Skip to content

Instantly share code, notes, and snippets.

@manmohan24nov
Last active November 10, 2020 18:40
Show Gist options
  • Save manmohan24nov/cc1e59600df92f3b7ddda3d27fbca15c to your computer and use it in GitHub Desktop.
Save manmohan24nov/cc1e59600df92f3b7ddda3d27fbca15c to your computer and use it in GitHub Desktop.
In [1]: import praw
In [2]: import re
In [3]: reddit = praw.Reddit(client_id='client id',
...: client_secret='client secret',
...: user_agent='user agent')
In [4]: top_posts = reddit.subreddit('showerthoughts').top('week', limit=1)
In [5]: comment_section = []
In [6]: TEXT_CLEANING_RE = "@\S+|https?:\S+|http?:\S|[^A-Za-z0-9]+"
In [7]: def replies_of(top_level_comment, count_comment):
...: if len(top_level_comment.replies) == 0:
...: count_comment = 0
...: return
...: else:
...: for num, comment in enumerate(top_level_comment.replies):
...: try:
...: count_comment += 1
...: print('-' * count_comment, comment.body)
...: text = re.sub(TEXT_CLEANING_RE, ' ', str(comment.body).lower()).strip()
...: print(text)
...: text = text.replace('\n', " ").replace("\\", "")
...: print(text)
...: print('*'*50)
...: comment_section.append(text)
...: except:
...: continue
...: replies_of(comment, count_comment)
...:
In [8]: for submission in top_posts:
...: submission_comm = reddit.submission(id=submission.id)
...: for count, top_level_comment in enumerate(submission_comm.comments):
...: print(f"-------------{count} top level comment start--------------")
...: count_comm = 0
...: try :
...: print(top_level_comment.body)
...: replies_of(top_level_comment,
...: count_comm)
...: except:
...: continue
In [9]: comment_section
Out[9]:
['you just know someone has made that joke with her',
'was literally discussing this with my wife yesterday i am british she is not for some reason she thought i would know the answer to whether that would be a thing or not i did not so i guess it s a pretty common shower thought tbh',
'pardon',
'this chap s missus thought he might have a clue whether her maj will get a telegram from herself courtesy of herself when she tops a ton what with him being an englishman that help squire',
'ha ha thanks for clarifying my apparently rambling train of thought',
'my pleasure mate have a good un',
'ah yes old bean much indebted',
'i read that in a british accent well done cheers',
'ikr i m british and i still read that in a noticeably british accent',
'i read it in the most aussie accent ever',
'aussie needs more oi and cunt',
'that is the most british sentence i ve ever seen',
'hmmm yes well played my good man',
'i am chuffed by this whole exchange',
'why does this sound like captain jack sparrow',
'i ve pirated his accent',
'when she tops a ton she ll have to start packing it on then i m not sure she s even ten stone',
'english reddit intensifies',
'honestly every brit should send the queen a card to her when she turns 100s she s nice enough to do it for everyone else',
'imagine the other people she has sent cards to congratulating her back that would be perfect',
'do we have the same wife im not british but for some reason my wife always asks me the most random shit as if i just have the answer waiting in my pocket u rexfordays',
'contact the office of your member of parliament in canada if you turn 90 you can get a signed portrait of the prime minister trudeau in england boris johnson and when you turn 100 your mp can get you signed photo of queen elizabeth',
'well i m over halfway to 90 now so will have to start getting that sorted',
'we should all write letters to ourselves like that at some point stick it to our mirrors or something',
'my gf leaves a note on the inside of our front door so i see it every morning when i leave for work since she s still asleep at that time it s supposed to be a reminder to take the trash with me but it just says trash so it s really a reminder of me as a man',
'this made me laugh if i had awards i d give one i dont so i m just gonna start doing this for my boyfriend',
'just a heads up to anyone who doesn t know which included me recently reddit will give you a free award to give out every so often can be redeemed when you click on the golden coin where they want you to buy their shit',
'that s awesome thanks for the info so excited to spread the reddit love',
'i m giving you mine as a thank you for telling us this']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment