From 2c07560dab55c4c8e6f9885451488f96c7fc2338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Gl=C3=BCpker?= Date: Fri, 30 Mar 2018 12:58:44 +0200 Subject: Support game update check in SteamAPI --- SteamAPI.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/SteamAPI.py b/SteamAPI.py index 1790989..e6548fc 100644 --- a/SteamAPI.py +++ b/SteamAPI.py @@ -269,6 +269,43 @@ class SteamAPI(): return jsondata return None + def getGameUpdateState(self, gameid, gameversion): + """Fetch the current game update state. + + Args: + gameid: Steam game id + gameversion: Current version of the game + Returns: + dict() with the following keys: + - success Boolean Was able to check version + - up_to_date Boolean If the game is up to date + - version_is_listable Boolean If the game version is listed + - required_version (int) ? New version ? + - message (String) Message to display + """ + + if CACHE: + cache = Caching.readCache('serverupdate', '%s-%s' % (str(gameid), str(gameversion)), 60*60) + if cache: + cachedata = json.loads(cache) + return cachedata + + url = 'http://api.steampowered.com/ISteamApps/UpToDateCheck/v1?appId={0}&version={1}'.format(gameid, gameversion) + try: + response = urlopen(url) + data = response.read().decode('utf-8') + jsondata = json.loads(data) + if 'response' in jsondata: + jsondata = jsondata['response'] + except HTTPError: + jsondata = None + + if jsondata: + if CACHE: + cache = Caching.writeCache('serverupdate', '%s-%s' % (str(gameid), str(gameversion)), json.dumps(jsondata)) + return jsondata + return None + def getMultipleUserOwnedGames(self, steamids): executor = ThreadPoolExecutor(max_workers=10) futures = dict() -- cgit v1.2.3