Created
November 6, 2016 17:54
-
-
Save benrules2/fbc25b7a42449b8f774c99729b55ecad to your computer and use it in GitHub Desktop.
Reddit Sorry Counter
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
def get_subreddit_comments(reddit_agent, subreddit, comments_out = [], count = 100): | |
#surrounded by try catch in case API calls get exceed | |
try: | |
sub = reddit_agent.get_subreddit(subreddit) | |
comments_raw = sub.get_comments(sub, limit=count) | |
comments_flat = praw.helpers.flatten_tree(comments_raw) | |
for comment in comments_flat: | |
#try catch handles end of reply tree containing a null comment | |
try: | |
if hasattr(comment, 'comments'): | |
for reply in comment.comments: | |
comments_out.append(reply.body) | |
else: | |
comments_out.append(comment.body) | |
except: | |
pass | |
except: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment