Last active
August 29, 2015 14:07
-
-
Save montycheese/b697130be71191931ca9 to your computer and use it in GitHub Desktop.
Reddit Comment and Karma checker
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 requests, webbrowser | |
def get_reddit_user_info(username): | |
url = "https://www.reddit.com/user/%s.json" % username | |
r = requests.get(url) | |
json_data = r.json() | |
#op = json_data['data']['children'][0]['data']['link_author'] | |
#individualpost = json_data['data']['children'][0]['data'] | |
try: | |
if json_data['error'] == 404: | |
print "404 error, user has been banned or does not exist" | |
exit() | |
except KeyError: | |
pass | |
try: | |
all_posts = json_data["data"]['children'] | |
except KeyError: | |
all_posts = json_data['data']['children'] | |
# max post index = 24 as of 10/19/14 | |
#print all_posts[3]['data']['score'] | |
# Prints out all titles of posts I've commented on | |
# title - if self post, #link_title - if another user post | |
for post in all_posts: | |
try: | |
print "Title: %s \nComment: %s \nKarma: %s\n" % (post['data']['link_title'], post['data']['body'], post['data']['score']) | |
except KeyError: #if selfpost skip it. | |
continue | |
if __name__ == "__main__": | |
x = raw_input("Enter Username >>") | |
get_reddit_user_info(x) | |
# webbrowser.open("https://www.reddit.com/user/%s" % x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment