Skip to content

Instantly share code, notes, and snippets.

@benrules2
Created November 6, 2016 17:54
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 benrules2/fbc25b7a42449b8f774c99729b55ecad to your computer and use it in GitHub Desktop.
Save benrules2/fbc25b7a42449b8f774c99729b55ecad to your computer and use it in GitHub Desktop.
Reddit Sorry Counter
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