Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #this file was used to get the most recent 1000 posts and comments from drug and recovery subreddits in updated_reddit_forum_categories
- # this set of users were labelled as level 1
- #original posters and comment authors both were collected
- import pprint
- import updated_reddit_forum_categories
- drug_subreddits = updated_reddit_forum_categories.drug_subreddits
- recovery_subreddits = updated_reddit_forum_categories.recovery_subreddits
- import pymongo
- client = pymongo.MongoClient('130.212.215.135', 27017)
- db = client.new_reddit
- collection = db.user_post_history_level_1_users
- collection2 = db.subreddits_done
- done_subreddits = collection2.distinct("subreddit")
- print done_subreddits
- print len(done_subreddits)
- 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,subreddit in enumerate(drug_subreddits):
- print c, subreddit
- if subreddit in done_subreddits:
- continue
- collection2.insert({"subreddit":subreddit})
- print c, subreddit
- sub = reddit.subreddit(subreddit)
- posts = sub.new(limit=None)
- count =0
- for submission in posts:
- count = count + 1
- print count
- # print submission.author
- post_author = str(submission.author)
- # print post_author
- collection.insert({"redditor":post_author})
- # print submission.selftext
- # print submission.title
- # print submission.id
- submission.comments.replace_more(limit=0)
- for comment in submission.comments.list():
- # print comment.body
- # print comment.author
- comment_author = str(comment.author)
- collection.insert({"redditor":comment_author})
- # print comment.id
- # print "******************"
- # print "**************"
- #do thing to each submission
- # user = reddit.redditor("Jtgivesualadyboner")
- # submissions = user.submissions
- #
- # for p in submissions.new(limit=None):
- # print p.title
Add Comment
Please, Sign In to add comment