Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- from prettytable import PrettyTable
- with open("credentials.txt", "r") as f:
- DF = f.read().splitlines()
- REDDIT = praw.Reddit(client_id=DF[0],
- client_secret=DF[1],
- user_agent="python script",
- username=DF[2],
- password=DF[3]
- )
- # assumes DT is pinned post on the sub
- dt = [x.id for x in REDDIT.subreddit('neoliberal').hot(limit=1)][0]
- submission = REDDIT.submission(id=dt)
- com_count = dict()
- submission.comments.replace_more(limit=None)
- for comment in submission.comments.list():
- try:
- tmp = comment.author.name
- score = comment.score
- if tmp not in com_count:
- com_count[tmp] = [1, score]
- else:
- old_count, old_score = com_count[tmp]
- com_count[tmp] = [old_count + 1, old_score + score]
- except Exception:
- pass
- sorted_users = sorted(com_count.items(), key=lambda i: i[1][0], reverse=True)
- t = PrettyTable(['Name', 'Postcount', 'Karma', 'Karma/Post'])
- for key, value in sorted_users:
- kp = 0 if value[1] == 0 else float(value[1]/value[0])
- t.add_row([key, value[0], value[1], '{0:2.2f}'.format(kp)])
- print(t)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement