Advertisement
Guest User

recovery

a guest
Apr 23rd, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 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. import pymongo
  11. client = pymongo.MongoClient('130.212.215.135', 27017)
  12. db = client.new_reddit
  13. collection = db.user_post_history_level_1_users
  14. collection2 = db.subreddits_done
  15. done_subreddits = collection2.distinct("subreddit")
  16. import praw
  17.  
  18. my_user_agent = "sfsuthesis1"
  19. my_client_id = "719oiPs6Hm2YAA"
  20. my_client_secret = "dIwlDy7TYQlxJGkCHoyrVK2suqg"
  21. my_username = "sfsuthesis"
  22. my_password = "sfsuthesis"
  23.  
  24. reddit = praw.Reddit(user_agent=my_user_agent,
  25. client_id=my_client_id,
  26. client_secret=my_client_secret)
  27.  
  28. reddit = praw.Reddit(user_agent=my_user_agent,
  29. client_id=my_client_id,client_secret=my_client_secret,
  30. username=my_username,
  31. password=my_password)
  32.  
  33.  
  34. for c,subreddit in enumerate(recovery_subreddits):
  35. if subreddit in done_subreddits:
  36. continue
  37. collection2.insert({"subreddit":subreddit})
  38. print c, subreddit
  39. sub = reddit.subreddit(subreddit)
  40. posts = sub.new(limit=None)
  41. count=0
  42. for submission in posts:
  43. count = count +1
  44. print count
  45. # print submission.author
  46. post_author = str(submission.author)
  47. # print post_author
  48. # collection.insert({"redditor":post_author})
  49. # print submission.selftext
  50. # print submission.title
  51. # print submission.id
  52. submission.comments.replace_more(limit=0)
  53. for comment in submission.comments.list():
  54. # print comment.body
  55. # print comment.author
  56. comment_author = str(comment.author)
  57. # collection.insert({"redditor":comment_author})
  58. # print comment.id
  59. # print "******************"
  60. # print "**************"
  61. #do thing to each submission
  62.  
  63. # user = reddit.redditor("Jtgivesualadyboner")
  64. # submissions = user.submissions
  65. #
  66. # for p in submissions.new(limit=None):
  67. # print p.title
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement