Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. import pymongo
  2. client = pymongo.MongoClient('130.212.214.188', 27017)
  3. db = client.bioinformatics_857
  4. collection = db.user_post_history_level_2
  5. cursor = collection.find(no_cursor_timeout=True)
  6. cursor.sort("_id", pymongo.ASCENDING)
  7.  
  8. import praw
  9.  
  10. my_user_agent = "RandomForest"
  11. my_client_id = "zyyC4k0WkK_glw"
  12. my_client_secret = "Y5NsNv39WgVifcgSz_gqJBpoDxM"
  13. my_username = "RandomForest07"
  14. my_password = "Thesisspring2017"
  15.  
  16. reddit = praw.Reddit(user_agent=my_user_agent,
  17. client_id=my_client_id,
  18. client_secret=my_client_secret)
  19.  
  20. reddit = praw.Reddit(user_agent=my_user_agent,
  21. client_id=my_client_id,client_secret=my_client_secret,
  22. username=my_username,
  23. password=my_password)
  24.  
  25. for c,i in enumerate(cursor):
  26. print c
  27. if "comments_done" in i:
  28. continue
  29. redditor = i["redditor"]
  30. if redditor == '[deleted]':
  31. continue
  32. print redditor
  33. posts = i["posts"]
  34. for p in posts:
  35. # print "*********"
  36. if p["subreddit"]=="opiates" or p["subreddit"]=="OpiatesRecovery":
  37. # print p["id"]
  38. # print p["post"]
  39. submission = reddit.submission(id = p["id"])
  40. submission.comments.replace_more(limit=0)
  41. all_comments = submission.comments.list()
  42.  
  43. post_comments=[]
  44. for top_level_comment in all_comments:
  45. comments={}
  46. # print top_level_comment.body
  47. # print str(top_level_comment.author)
  48. # print "*******"
  49. comments["body"] = top_level_comment.body
  50. comments["author"] = str(top_level_comment.author)
  51. comments["score"] = top_level_comment.score
  52. comments["created_at"] = top_level_comment.created_utc
  53. post_comments.append(comments)
  54. # print len(post_comments)
  55. # print "**********"
  56. # print len(post_comments)
  57. p["comments"]=post_comments
  58. collection.save(i)
  59. i["comments_done"]=1
  60. collection.save(i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement