Skip to content

Instantly share code, notes, and snippets.

@ET-CS
Created June 26, 2015 04:43
Show Gist options
  • Save ET-CS/3ad39b5f86f93121b1a4 to your computer and use it in GitHub Desktop.
Save ET-CS/3ad39b5f86f93121b1a4 to your computer and use it in GitHub Desktop.
python stackoverflow get reputation and badge count
#!/usr/bin/env python
import requests
import simplejson as json
# this function fetch your user data from the so api
def get_data():
# replace '3879958' with your userid
url = "https://api.stackexchange.com/2.2/users/3879958?order=desc&sort=reputation&site=stackoverflow"
j=json.loads((requests.get(url, timeout=5)).text)
return j
# get only badge counts
def get_badge_counts():
return get_data()['items'][0]['badge_counts']
# get only reputation
def get_reputation():
return get_data()['items'][0]['reputation']
# get my data - include badge counts & reputation
def get_my_data():
j = get_data()['items'][0]
return { 'reputation' : j['reputation'], 'badge_counts': j['badge_counts'] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment