Skip to content

Instantly share code, notes, and snippets.

@syxolk
Created January 12, 2017 02:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syxolk/31649f45f6c805967d8ba09180df82aa to your computer and use it in GitHub Desktop.
Save syxolk/31649f45f6c805967d8ba09180df82aa to your computer and use it in GitHub Desktop.
import requests
import json
import sys
def get_game_hours(profile_id):
r = requests.get("https://steamcommunity.com/profiles/" + str(profile_id) + "/games/?tab=all")
hours = []
for line in r.text.splitlines():
if line.lstrip().startswith("var rgGames"):
line = line[line.index("=")+1:line.rindex(";")]
data = json.loads(line)
for game in data:
if "hours_forever" in game:
hours.append(float(game["hours_forever"].replace(",", "")))
return hours
def h_index(values):
h = 0
for x in values:
if x > h:
h += 1
else:
break
return h
if __name__ == "__main__":
print(h_index(get_game_hours(sys.argv[1])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment