Skip to content

Instantly share code, notes, and snippets.

@jrabbit
Created July 2, 2010 19:09
Show Gist options
  • Save jrabbit/461769 to your computer and use it in GitHub Desktop.
Save jrabbit/461769 to your computer and use it in GitHub Desktop.
from urllib2 import urlopen
import simplejson as json
class Reddit:
def __init__(self):
self.url = 'http://www.reddit.com/user/%s/about.json'
def karma(self, phrase):
user = sys.argv[1]
raw = urlopen(self.url % phrase).read()
data = json.loads(raw)['data']
karma = data['link_karma']
comment = data['comment_karma']
return [user, karma, comment, user]
if __name__ == '__main__':
import sys
if len(sys.argv) > 1:
phrase = sys.argv[1]
reddit = Reddit()
values = reddit.karma(phrase)
print "%s has %s link karma and %s comment karma: http://www.reddit.com/user/%s" % (values)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment