diff options
Diffstat (limited to 'SteamAPI.py')
-rw-r--r-- | SteamAPI.py | 32 |
1 files changed, 31 insertions, 1 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: |