Created
January 12, 2017 02:07
-
-
Save syxolk/31649f45f6c805967d8ba09180df82aa to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
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