Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pdb
- import pprint
- import praw
- import os
- from datetime import datetime
- # TODO
- # 1. People who posted demonetization related articles or participants - how many of them were new?
- # 2. Average age of an account that participated in these discussions
- # 3. Sentiment of posts - positive or negative - over a period of time
- # 4. Sentiment of posts/comments and the average age of authors
- # 5. Sentiment of authors towards BJP/Modi before demonetization
- # 6. Top influencers - authors whose comments/submissions were upvoted the most
- epoch = datetime(1970,1,1)
- def count_items(reddit_list):
- x = 0
- earliest_time = (datetime.utcnow()-epoch).total_seconds()
- for c in reddit_list:
- if c.created_utc < earliest_time:
- earliest_time = c.created_utc
- x += 1
- return x, earliest_time
- reddit = praw.Reddit(client_id='cZ5kksi-eSfL7A', client_secret='6pTEpAxxxZV_6_7XOUYTkh4LyOg',
- username='S1r1usBl4ck', password='spidyweb', user_agent='script')
- submission_details={}
- author_details={}
- india = reddit.subreddit('india')
- # Limits
- max_posts_to_download = 1000
- max_submissions_to_download = 1000
- max_comments_to_download = 1000
- def add_author_details(author):
- author_name = author.name
- if not author_details.has_key(author_name):
- print 'Getting details about', author_name
- try:
- author_details[author_name] = {}
- author_details[author_name]['link_karma'] = author.link_karma
- author_details[author_name]['comment_karma'] = author.comment_karma
- author_details[author_name]['upvotes'] = 0
- author_details[author_name]['downvotes'] = 0
- author_details[author_name]['score'] = 0
- author_details[author_name]['comment_upvotes'] = 0
- author_details[author_name]['comment_downvotes'] = 0
- author_details[author_name]['comment_score'] = 0
- user_since = datetime.utcfromtimestamp(author.created_utc)
- author_details[author_name]['user_since'] = user_since
- except:
- print '\tFailed to get information about author', author_name
- for submission in india.hot(limit=max_posts_to_download):
- try:
- if submission.link_flair_text=='Demonetization':
- print 'Found a demonetization related article'
- author_name = submission.author.name
- if not submission_details.has_key(author_name):
- print '\tFound new author', author_name
- submission_details[author_name] = []
- add_author_details(submission.author)
- submission_details[author_name].append({
- 'title': submission.title,
- 'score': submission.score,
- 'ups': submission.ups,
- 'downs': submission.downs,
- 'created': submission.created_utc
- })
- print '\tRetrieving all the comments from the submission'
- try:
- for comment in submission.comments.list():
- if hasattr(comment, 'author') and comment.author != None:
- add_author_details(comment.author)
- author_details[author_name]['comment_upvotes'] += comment.ups
- author_details[author_name]['comment_downvotes'] += comment.downs
- author_details[author_name]['comment_score'] += comment.score
- except:
- print '\tFailed to get comments for submission'
- author_details[author_name]['upvotes'] += submission.ups
- author_details[author_name]['downvotes'] += submission.downs
- author_details[author_name]['score'] += submission.score
- except:
- print 'Failed to get information about submission'
- for a in author_details:
- pprint.pprint(a)
- pprint.pprint(author_details[a], indent=4)
- #for s in submission_details[a]:
- # print '\t', s
- pdb.set_trace()
- # end-of-script
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement