Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pymongo
- client = pymongo.MongoClient('130.212.214.188', 27017)
- db = client.bioinformatics_857
- collection = db.user_post_history_level_2
- cursor = collection.find(no_cursor_timeout=True)
- cursor.sort("_id", pymongo.ASCENDING)
- import praw
- my_user_agent = "RandomForest"
- my_client_id = "zyyC4k0WkK_glw"
- my_client_secret = "Y5NsNv39WgVifcgSz_gqJBpoDxM"
- my_username = "RandomForest07"
- my_password = "Thesisspring2017"
- reddit = praw.Reddit(user_agent=my_user_agent,
- client_id=my_client_id,
- client_secret=my_client_secret)
- reddit = praw.Reddit(user_agent=my_user_agent,
- client_id=my_client_id,client_secret=my_client_secret,
- username=my_username,
- password=my_password)
- for c,i in enumerate(cursor):
- print c
- if "comments_done" in i:
- continue
- redditor = i["redditor"]
- if redditor == '[deleted]':
- continue
- print redditor
- posts = i["posts"]
- for p in posts:
- # print "*********"
- if p["subreddit"]=="opiates" or p["subreddit"]=="OpiatesRecovery":
- # print p["id"]
- # print p["post"]
- submission = reddit.submission(id = p["id"])
- submission.comments.replace_more(limit=0)
- all_comments = submission.comments.list()
- post_comments=[]
- for top_level_comment in all_comments:
- comments={}
- # print top_level_comment.body
- # print str(top_level_comment.author)
- # print "*******"
- comments["body"] = top_level_comment.body
- comments["author"] = str(top_level_comment.author)
- comments["score"] = top_level_comment.score
- comments["created_at"] = top_level_comment.created_utc
- post_comments.append(comments)
- # print len(post_comments)
- # print "**********"
- # print len(post_comments)
- p["comments"]=post_comments
- collection.save(i)
- i["comments_done"]=1
- collection.save(i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement