Skip to content

Instantly share code, notes, and snippets.

@fprimex
Last active August 29, 2015 14:06
Show Gist options
  • Save fprimex/4df1c90fa57e1f55bb6a to your computer and use it in GitHub Desktop.
Save fprimex/4df1c90fa57e1f55bb6a to your computer and use it in GitHub Desktop.
Check a Steam username for Spelunky achievements
#!/usr/bin/env python
import sys
import os
import urllib2
import json
spelunky_app_id = '239350'
steam_id_url = 'http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/?key={}&vanityurl={}&format=json'
spelunky_url = 'http://api.steampowered.com/ISteamUserStats/GetPlayerAchievements/v0001/?appid=' + spelunky_app_id + '&key={}&steamid={}'
if len(sys.argv) != 2:
print 'Need one argument: the steam username to check'
sys.exit(1)
steam_user=sys.argv[1]
# You need a Steam API Key. Put that in the file ~/.steam_api_key on one single line.
# Get it from here:
# http://steamcommunity.com/dev/apikey
with open(os.path.join(os.path.expanduser('~'), '.steam_api_key')) as f:
steam_key = f.read().strip()
try:
response = urllib2.urlopen(steam_id_url.format(steam_key, steam_user))
result = response.read()
steam_id = json.loads(result)['response']['steamid']
except:
print "Couldn't get steamid for given user"
print result
sys.exit(1)
try:
response = urllib2.urlopen(spelunky_url.format(steam_key, steam_id))
result = response.read()
spelunky = json.loads(result)['playerstats']['achievements']
except:
print "Couldn't get spelunky achievements for given user"
print result
sys.exit(1)
ach_total = 0
for ach in spelunky:
if ach[u'apiname'] == u'ACH_IRONMAN' and ach[u'achieved'] == 1:
print u'Olmec: Yes'
elif ach[u'apiname'] == u'ACH_TO_HELL_AND_BACK' and ach[u'achieved'] == 1:
print u'Hell: Yes'
if ach[u'achieved'] == 1:
ach_total += 1
if ach_total == 20:
print u'Complete: Yes'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment