Advertisement
Guest User

Untitled

a guest
Oct 5th, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import praw
  2. import random
  3.  
  4. #Using the user agent from the example, because I'm lazy
  5. r = praw.Reddit('Comment Scraper 1.0 by u/_Daimon_ see'
  6. 'https://praw.readthedocs.org/en/latest/'
  7. 'pages/comment_parsing.html')
  8.  
  9. #Pick the submission to choose a comment from, using the post's UUID (/r/subreddit/comments/[Submission ID]
  10. submission = r.get_submission(submission_id='3jfwb1')
  11.  
  12. #Put all the comments in the submission in the list, "allComments"
  13. submission.replace_more_comments(limit=None, threshold=0)
  14. submissionComments = submission.comments
  15. allComments = praw.helpers.flatten_tree(submissionComments)
  16.  
  17. #If the user's name is not already in the set "usernames", add it
  18. usernames = set()
  19. for comment in allComments:
  20. if comment.author is not None and comment.author.name not in usernames:
  21. usernames.add(comment.author.name)
  22.  
  23. #Print the number of unique usernames that commented
  24. print(len(usernames))
  25.  
  26. #Get one random username from the usernames
  27. print( random.sample(usernames, 1) )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement