Skip to content

Instantly share code, notes, and snippets.

@monajalal
Created October 3, 2016 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monajalal/e3eb0590bc0a4f757500ec423f2b6dd3 to your computer and use it in GitHub Desktop.
Save monajalal/e3eb0590bc0a4f757500ec423f2b6dd3 to your computer and use it in GitHub Desktop.
import praw
r = praw.Reddit(user_agent="getting top posts from a subredit and its submissions", site_name='lamiastella')
subreddit = r.get_subreddit('iama')
top_year_subreddit = subreddit.get_top_from_year
submissions = top_year_subreddit(limit=50)
for submission in submissions:
submission.replace_more_comments(limit=None, threshold=0)
all_comments = praw.helpers.flatten_tree(submission.comments)
all_comments.sort(key = lambda comment : comment.score, reverse = True)
top_comments = all_comments[:30]
for comment in top_comments:
print(comment.body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment