Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pymongo
- import praw
- import pprint
- import pickle
- my_user_agent = "orecovery"
- my_client_id = "_El8RNVxmx59Mg"
- my_client_secret = "0FEASY-6G8KBaMaS0bCx1nKxooA"
- my_username = "singhlab"
- my_password = "RahulSingh!@#$"
- 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)
- client = pymongo.MongoClient('130.212.214.188', 27017)
- db = client.ieee_big_data
- collection = db.user_post_history_opiatesrecovery_copy
- cursor = collection.find(no_cursor_timeout=True)
- cursor=cursor.sort("_id",-1)
- collection2 = db.user_comment_history
- # comments=[]
- missed_users=[]
- done_users =[]
- cursor2 = collection2.find()
- users_done=0
- # for c,j in enumerate(cursor2):
- # print c
- # done_users.append(j["redditor"])
- for i in cursor:
- # if i["redditor"]=="santiaguina":
- # continue
- print i["redditor"]
- if "got_comments" in i:
- continue
- user_redditor= i["redditor"]
- comments=[]
- try:
- user = reddit.redditor(user_redditor)
- comments_new = user.comments.new(limit=None)
- count=0
- for c in comments_new:
- comment_dic={}
- # comment_dic["body"]= c.body
- # print c.body
- # print c.subreddit.display_name
- comment_dic["subreddit"]= c.subreddit.display_name
- comment_dic["created_at"]= c.created_utc
- comments.append(comment_dic)
- count +=1
- print count
- except Exception as exc:
- pprint.pprint(vars(exc))
- try:
- dic={}
- dic["redditor"]= i["redditor"]
- dic["comments"]=comments
- collection2.insert(dic)
- users_done +=1
- i["got_comments"]=1
- collection.save(i)
- except Exception as exc:
- missed_users.append(i["redditor"])
- pprint.pprint(vars(exc))
- users_done +=1
- print "users_done ",users_done
- with open("test.txt", "wb") as fp: #Pickling
- pickle.dump(missed_users, fp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement