You're looking at a specific version of this model. Jump to the model overview.
nateraw /nous-hermes-llama2-awq:b3f3f012
Input
Output
```python
import praw
def get_top_posts(reddit, subreddit):
posts = reddit.subreddit(subreddit).top(limit=100)
top_posts = []
for post in posts:
if post.score >= 1000:
top_posts.append(post)
return top_posts
def save_image_attachments(posts, image_dir):
for post in posts:
for comment in post.comments:
if 'image' in comment.body.lower() or 'jpg' in comment.body.lower() or 'png' in comment.body.lower():
try:
comment.crop((0, 0, 1080, 1920))
comment.download(os.path.join(image_dir, f"{post.id}-{comment.name}"))
except Exception as e:
print(f"Failed to download image for post {post.id}: {e}")
if __name__ == "__main__":
# Create PRAW client
client_id, client_secret, user_agent = "your_client_id", "your_client_secret", "pic-downloader"
reddit = praw.Reddit(client_id=client_id, client_secret=client_secret, user_agent=user_agent)
# Get top 3 posts of all time from /r/pics and save the image attachments
image_dir = "images"
top_posts = get_top_posts(reddit, "pics")
save_image_attachments(top_posts, image_dir)
# Close PRAW client
reddit.close()
```
Replace "your_client_id", "your_client_secret", and "pic-downloader" with your own PRAW client ID, client secret, and user agent string. This script will download the top 3 posts of all time from /r/pics and save their image attachments to a folder named "images" in the same directory as the script.
Generated in
This example was created by a different version, nateraw/nous-hermes-llama2-awq:c71045fd.