Skip to content

Instantly share code, notes, and snippets.

@manmohan24nov
Last active March 6, 2021 16:21
Show Gist options
  • Save manmohan24nov/c88d020708fb6342fcb075f4f4ebd7f1 to your computer and use it in GitHub Desktop.
Save manmohan24nov/c88d020708fb6342fcb075f4f4ebd7f1 to your computer and use it in GitHub Desktop.
>>> import praw
>>> reddit = praw.Reddit(client_id='client id', #1
... client_secret='client secret',
... user_agent='user agent')
Version 7.1.0 of praw is outdated. Version 7.2.0 was released Wednesday February 24, 2021.
>>> def replies_of(top_level_comment, comment_list): #2
... if len(top_level_comment.replies) == 0:
... return
... else:
... for num, comment in enumerate(top_level_comment.replies):
... try:
... comment_list.append(str(comment.body))
... except:
... continue
... replies_of(comment, comment_list)
...
>>> list_of_subreddit = ['showerthoughts', 'wallstreetbets', 'askreddit', 'jokes', 'worldnews']
>>> comment_list = []
>>> for j in list_of_subreddit:
... top_posts = reddit.subreddit(j).top('day', limit=1) #3
... for submission in top_posts:
... submission_comm = reddit.submission(id=submission.id)
... for count, top_level_comment in enumerate(submission_comm.comments):
... try:
... replies_of(top_level_comment, comment_list)
... except:
... continue
...
>>> comment_list[0:5]
["It's all fun and games until sanitation commissioner Simpson blows the annual budget in the first month.",
'The garbage man can and he does it with a smile 😁', 'And never judges yoooouuuuu',
'He does. He thinks you should be eating more fruits and veggies. Also you should shred your mail, people can get a ton of information from it.',
'*FBI has entered the chat*\n\nlol']
>>> len(comment_list)
1556
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment