From fd3e38f818d1cf29fb71820afa0a65e61a875a20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Gl=C3=BCpker?= Date: Sat, 6 Jan 2018 21:18:09 +0100 Subject: Remove gameextrainfo Steam API does not provide this anymore. We now fetch the gamelist ourself and use gameid. --- SteamAPI.py | 32 +++++++++++++++++++++++++++++++- main.py | 4 +++- templates/lobby_html.jinja | 8 ++++---- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/SteamAPI.py b/SteamAPI.py index 580b375..cc67f20 100644 --- a/SteamAPI.py +++ b/SteamAPI.py @@ -19,6 +19,36 @@ class SteamAPI(): def __init__(self, token): self.token = token + def getGames(self): + """Get list of steam games by app id. + + Returns: + dict() with str(appid) as keys, str gamename as value + """ + if CACHE: + cache = Caching.readCache('general', 'gamelist', 7*24*60*60) + if cache: + return json.loads(cache) + + url = 'https://api.steampowered.com/ISteamApps/GetAppList/v2' + try: + response = urlopen(url) + data = response.read().decode('utf-8') + jsondata = json.loads(data) + applist = jsondata['applist']['apps'] + except KeyError: + return None + except HTTPError: + return None + + gamelist = dict() + for app in applist: + gamelist[int(app['appid'])] = app['name'] + + if CACHE: + cache = Caching.writeCache('general', 'gamelist', json.dumps(gamelist)) + return gamelist + def getProfiles(self, steamids): """Get steam profiles. @@ -140,7 +170,7 @@ class SteamAPI(): print('No game in json:', jsondata) return None - def getGames(self, steamid): + def getPlayerGames(self, steamid): """Fetch a list of games a person possesses. Args: diff --git a/main.py b/main.py index ca1282e..4071be0 100755 --- a/main.py +++ b/main.py @@ -90,6 +90,7 @@ def lobby(): with open(os.path.join(CONFIG, 'lobby.json'), 'rt') as config: steamids = json.load(config) + gamelist = steam.getGames() profiledata = steam.getProfiles(steamids.keys()) # Merge new data in loaded config @@ -121,11 +122,12 @@ def lobby(): steamids = OrderedDict(sorted(steamids.items(), key = lambda player: player[1]['personaname'].lower())) steamids = OrderedDict(sorted(steamids.items(), reverse=True, key = lambda player: int(player[1]['lastlogoff']))) steamids = OrderedDict(sorted(steamids.items(), key = lambda player: (player[1]['personastate'] > 0) and player[1]['personastate'] or 10)) - steamids = OrderedDict(sorted(steamids.items(), key = lambda player: ('gameextrainfo' in player[1] and player[1]['gameextrainfo'].lower() or "zzz"))) + steamids = OrderedDict(sorted(steamids.items(), key = lambda player: ('gameid' in player[1] and player[1]['gameid'] or "zzz"))) return render_template('lobby_html.jinja', steamids = steamids, serverinfo = serverinfo, + gamelist = gamelist, states = ['Offline', 'Online', 'Busy', 'Away', 'Snooze', 'Looking to trade', 'Looking to play'], display_time = display_time, current_time = time.time()) diff --git a/templates/lobby_html.jinja b/templates/lobby_html.jinja index 54d5037..a9598bc 100644 --- a/templates/lobby_html.jinja +++ b/templates/lobby_html.jinja @@ -40,7 +40,7 @@
{# Ingame (Steam), Ingame (Nonsteam), Offline/Other #} {% if profile['gameid'] %} - {{ profile['gameextrainfo'] or 'N/A' }} + {{ gamelist[profile['gameid']] or 'N/A' }} {% if profile['gameserverip'] not in serverinfo %} {# No serverinfo -> Display game logo #} @@ -60,7 +60,7 @@ {% set mapname = serverinfo[profile['gameserverip']]['map'] %} {% set players = serverinfo[profile['gameserverip']]['players'] %} {% set playersmax = serverinfo[profile['gameserverip']]['playersmax'] %} - {% if game != profile['gameextrainfo'] %} + {% if game != gamelist[profile['gameid']] %} {{ game }}
{% endif %} {{ servername }}
@@ -72,8 +72,8 @@
Copy link
{% endif %} - {% elif profile['gameextrainfo'] %} - {{ profile['gameextrainfo'] }}
+ {% elif gamelist[profile['gameid']] %} + {{ gamelist[profile['gameid']] }}
(non-steam) {% else %} {% if profile['personastate'] == 0 %} -- cgit v1.2.3