Created
October 3, 2016 20:30
-
-
Save monajalal/e3eb0590bc0a4f757500ec423f2b6dd3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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