Guest User

drug_subreddits

a guest
Apr 23rd, 2018
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. #this file was used to get the most recent 1000 posts and comments from drug and recovery subreddits in updated_reddit_forum_categories
  2. # this set of users were labelled as level 1
  3. #original posters and comment authors both were collected
  4.  
  5. import pprint
  6. import updated_reddit_forum_categories
  7. drug_subreddits = updated_reddit_forum_categories.drug_subreddits
  8. recovery_subreddits = updated_reddit_forum_categories.recovery_subreddits
  9.  
  10.  
  11.  
  12. import pymongo
  13. client = pymongo.MongoClient('130.212.215.135', 27017)
  14. db = client.new_reddit
  15. collection = db.user_post_history_level_1_users
  16. collection2 = db.subreddits_done
  17. done_subreddits = collection2.distinct("subreddit")
  18. print done_subreddits
  19. print len(done_subreddits)
  20. import praw
  21.  
  22. my_user_agent = "RandomForest"
  23. my_client_id = "zyyC4k0WkK_glw"
  24. my_client_secret = "Y5NsNv39WgVifcgSz_gqJBpoDxM"
  25. my_username = "RandomForest07"
  26. my_password = "Thesisspring2017"
  27.  
  28. reddit = praw.Reddit(user_agent=my_user_agent,
  29. client_id=my_client_id,
  30. client_secret=my_client_secret)
  31.  
  32. reddit = praw.Reddit(user_agent=my_user_agent,
  33. client_id=my_client_id,client_secret=my_client_secret,
  34. username=my_username,
  35. password=my_password)
  36.  
  37.  
  38. for c,subreddit in enumerate(drug_subreddits):
  39. print c, subreddit
  40. if subreddit in done_subreddits:
  41. continue
  42. collection2.insert({"subreddit":subreddit})
  43. print c, subreddit
  44. sub = reddit.subreddit(subreddit)
  45. posts = sub.new(limit=None)
  46. count =0
  47. for submission in posts:
  48. count = count + 1
  49. print count
  50. # print submission.author
  51. post_author = str(submission.author)
  52. # print post_author
  53. collection.insert({"redditor":post_author})
  54. # print submission.selftext
  55. # print submission.title
  56. # print submission.id
  57. submission.comments.replace_more(limit=0)
  58. for comment in submission.comments.list():
  59. # print comment.body
  60. # print comment.author
  61. comment_author = str(comment.author)
  62. collection.insert({"redditor":comment_author})
  63. # print comment.id
  64. # print "******************"
  65. # print "**************"
  66. #do thing to each submission
  67.  
  68. # user = reddit.redditor("Jtgivesualadyboner")
  69. # submissions = user.submissions
  70. #
  71. # for p in submissions.new(limit=None):
  72. # print p.title
Add Comment
Please, Sign In to add comment