Last active
March 6, 2021 16:21
-
-
Save manmohan24nov/c88d020708fb6342fcb075f4f4ebd7f1 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 | |
>>> 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