Last active
January 3, 2016 01:59
-
-
Save schrobby/8392405 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 re | |
import praw | |
from HTMLParser import HTMLParser | |
def get_awards(user, passwd, subreddit, num=3): | |
awards = {} | |
r = praw.Reddit(user_agent="super_quick_awards_script.py 0.1a by /u/schrobby") | |
r.login(user, passwd) | |
print("Logged in as " + user) | |
for submission in r.get_subreddit(subreddit).get_new(limit=None): | |
awards[submission.title] = [] | |
submission.replace_more_comments(limit=None) | |
print("Fetching comments for submission '%s'" % HTMLParser().unescape(submission.title)) | |
for comment in submission.comments: | |
match = re.match(r".*\[(.*)\]\(.*\).*", comment.body) | |
song_name = match.group(1) if match is not None else comment.body | |
awards[submission.title].append((HTMLParser().unescape(song_name), comment.ups)) | |
print("Sorting comments by upvotes") | |
print("\n\n\n") | |
for title, song_list in awards.iteritems(): | |
song_list.sort(key=lambda song: song[1], reverse=True) | |
print("__%s__\n" % HTMLParser().unescape(title)) | |
print("%s | %s" % song_list[0]) | |
print(":|:") | |
for s in song_list[1:num]: | |
print("%s | %s" % s) | |
print("\n") | |
if __name__ == "__main__": | |
import sys | |
leng = len(sys.argv) | |
if leng < 4: | |
print("Usage: ./awards-stats.py <user> <password> <subreddit> [number of comments]") | |
elif leng == 5: | |
get_awards(sys.argv[1], sys.argv[2], sys.argv[3], num=int(sys.argv[4])), | |
else: | |
get_awards(sys.argv[1], sys.argv[2], sys.argv[3]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment