Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import random
- #Using the user agent from the example, because I'm lazy
- r = praw.Reddit('Comment Scraper 1.0 by u/_Daimon_ see'
- 'https://praw.readthedocs.org/en/latest/'
- 'pages/comment_parsing.html')
- #Pick the submission to choose a comment from, using the post's UUID (/r/subreddit/comments/[Submission ID]
- submission = r.get_submission(submission_id='3jfwb1')
- #Put all the comments in the submission in the list, "allComments"
- submission.replace_more_comments(limit=None, threshold=0)
- submissionComments = submission.comments
- allComments = praw.helpers.flatten_tree(submissionComments)
- #If the user's name is not already in the set "usernames", add it
- usernames = set()
- for comment in allComments:
- if comment.author is not None and comment.author.name not in usernames:
- usernames.add(comment.author.name)
- #Print the number of unique usernames that commented
- print(len(usernames))
- #Get one random username from the usernames
- print( random.sample(usernames, 1) )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement