Created
September 3, 2012 01:19
-
-
Save aperson/3606054 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import urllib.request | |
import time | |
from urllib.parse import urlencode | |
import http.cookiejar | |
def _isVideo(submission): | |
'''Returns video author name if this is a video''' | |
if 'media' in submission: | |
if submission['media'] is not None: | |
if 'oembed' in submission['media']: | |
if 'author_name' in submission['media']['oembed'] is not None: | |
return submission['media']['oembed']['author_name'] | |
def _checkProfile(user): | |
opener = urllib.request.build_opener() | |
opener.addheaders = [('User-agent', 'moderator-bot.py v2')] | |
with opener.open( | |
'http://www.reddit.com/user/{}/comments/.json?limit=100&sort=new'.format(user)) as w: | |
comments = json.loads(w.read().decode('utf-8'))['data']['children'] | |
time.sleep(2) | |
with opener.open( | |
'http://www.reddit.com/user/{}/submitted/.json?limit=100&sort=new'.format(user)) as w: | |
submitted = json.loads(w.read().decode('utf-8'))['data']['children'] | |
video_count = 0 | |
video_authors = set() | |
video_submissions = set() | |
comments_on_self = 0 | |
for item in submitted: | |
item = item['data'] | |
video_author = _isVideo(item) | |
if video_author: | |
video_count += 1 | |
video_authors.add(video_author) | |
video_submissions.add(item['name']) | |
for item in comments: | |
item = item['data'] | |
if item['link_id'] in video_submissions: | |
comments_on_self +=1 | |
# debug print | |
print({'vc': video_count, 'va': len(video_authors), 'vs': len(video_submissions), 'cos': comments_on_self, | |
'total': (((video_count + comments_on_self) / (len(comments) + len(submitted))) * 100)}) | |
if len(video_authors) == 1 and video_count >= 3: | |
print(video_count, comments_on_self) | |
return ((video_count + comments_on_self) / (len(comments) + len(submitted))) * 100 | |
_checkProfile('SethBling') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment