Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #this file was used to get and save the name of users who commented on the posts of users in level 1 and were not present in level 1
- import pprint
- import pymongo
- client = pymongo.MongoClient('130.212.214.188', 27017)
- db = client.bioinformatics_857
- collection2 = db.user_post_history_level_2
- cursor = collection2.find(no_cursor_timeout=True)
- cursor.sort("_id", pymongo.ASCENDING)
- collection3 = db.user_post_history_level_3
- collection4 = db.done_users
- 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
- redditor = i["redditor"]
- if redditor == '[deleted]':
- continue
- # print redditor
- posts = i["posts"]
- for p in posts:
- if p["subreddit"]=="opiates" or p["subreddit"]=="OpiatesRecovery":
- # print p["id"]
- # print p["post"]
- comments= p["comments"]
- for c in comments:
- comment_redditor = c["author"]
- if comment_redditor == "None":
- continue
- collection = db.done_users
- done_users = collection.distinct("redditor")
- if comment_redditor in done_users:
- print "old stuff"
- continue
- print "new user"
- user_dic={}
- user_dic["redditor"]=comment_redditor
- print "comment author ",comment_redditor
- user = reddit.redditor(comment_redditor)
- submissions = user.submissions
- posts =[]
- try:
- for c,s in enumerate(submissions.new(limit=None)):
- post_dic={}
- post_dic['subreddit']= str(s.subreddit)
- post_dic['title'] = s.title
- post_dic['post'] = s.selftext
- post_dic['created_at'] = s.created_utc
- post_dic['num_comments'] = s.num_comments
- post_dic['score'] = s.score
- post_dic['ups'] = s.ups
- post_dic['downs'] = s.downs
- post_dic['id'] = s.id
- posts.append(post_dic)
- user_dic['posts']=posts
- collection3.insert(user_dic)
- collection4.insert({"redditor":comment_redditor})
- except Exception as exc:
- pprint.pprint(vars(exc))
- collection4.insert({"redditor":comment_redditor})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement