diff --git a/app.py b/app.py index 667941e..311f29b 100644 --- a/app.py +++ b/app.py @@ -126,9 +126,8 @@ def main(): platform="GOG", # TODO update this if necessary thumb_url=( - #"https://github.com/kurokobo/game-update-notifier/raw/main/" - #"assets/gog.png" - + # "https://github.com/kurokobo/game-update-notifier/raw/main/" + # "assets/gog.png" "https://github.com/BFrizzleFoShizzle/game-update-notifier/raw/main/" "assets/gog.png" ), diff --git a/helper/app_finder.py b/helper/app_finder.py index bf01310..fea74e5 100644 --- a/helper/app_finder.py +++ b/helper/app_finder.py @@ -27,7 +27,9 @@ def gather_steam(id): _name = _product_info["apps"][_id]["common"]["name"] _updated_time = -1 if "timeupdated" in _product_info["apps"][_id]["depots"]["branches"][_branch]: - _updated_time = _product_info["apps"][_id]["depots"]["branches"][_branch]["timeupdated"] + _updated_time = _product_info["apps"][_id]["depots"]["branches"][_branch][ + "timeupdated" + ] _row = [ "{}:{}".format(_id, _branch), _id, @@ -93,6 +95,7 @@ def gather_epicgames(): print(tabulate(_table, _header)) + def gather_gog_id(id): # get name _response = requests.get("https://api.gog.com/products/" + str(id)) @@ -100,9 +103,11 @@ def gather_gog_id(id): _name = _response.json()["title"] # get branch info - _response = requests.get("https://content-system.gog.com/products/" + _response = requests.get( + "https://content-system.gog.com/products/" + str(id) - + "/os/windows/builds?generation=2") + + "/os/windows/builds?generation=2" + ) _response.close() _product_info = _response.json() @@ -111,7 +116,7 @@ def gather_gog_id(id): _branches = [] for _product in _product_info["items"]: _branch = _product["branch"] - _branch_str = ("null" if _branch is None else "\"" + _branch + "\"") + _branch_str = "null" if _branch is None else '"' + _branch + '"' if not _product["branch"] in _branches: _key = str(id) + ":" + _branch_str _table.append([_key, id, _name, _branch_str]) @@ -119,11 +124,10 @@ def gather_gog_id(id): return (_table, _header) + def gather_gog_name(name): _endpoint = "https://embed.gog.com/games/ajax/filtered" - _params = { - "search": name - } + _params = {"search": name} _response = requests.get(url=_endpoint, params=_params) _response.close() _search_matches = _response.json() @@ -136,7 +140,6 @@ def gather_gog_name(name): print(tabulate(_table, _keys)) - def main(): parser = argparse.ArgumentParser() parser.add_argument( @@ -184,5 +187,6 @@ def main(): elif args.platform == "gog" and args.name is not None: gather_gog_name(args.name) + if __name__ == "__main__": main() diff --git a/modules/epicgames.py b/modules/epicgames.py index e1fb16f..818f3e9 100644 --- a/modules/epicgames.py +++ b/modules/epicgames.py @@ -54,7 +54,9 @@ def gather_app_info(self): id=_app, name=_product_info["apps"][_app]["app_title"], ), - data=_product_info["apps"][_app]["asset_infos"]["Windows"]["build_version"], + data=_product_info["apps"][_app]["asset_infos"]["Windows"][ + "build_version" + ], last_checked=self.timestamp, last_updated=_last_updated, ) diff --git a/modules/gog.py b/modules/gog.py index 1bb9623..54a5efa 100644 --- a/modules/gog.py +++ b/modules/gog.py @@ -1,18 +1,19 @@ import copy import logging -from datetime import datetime import time +from datetime import datetime from gevent import monkey monkey.patch_all() -import requests +import json # noqa: E402 + +import requests # noqa: E402 from modules import utils # noqa: E402 from modules.models import App, Cache, Result # noqa: E402 -import json class GOGAppFilter: # None = null (default release branch) @@ -23,7 +24,9 @@ def __init__(self, id, filter=None): def __str__(self): # GOG uses null for main branch # null != "null" so we add quotes around strings to avoid confusion - return self.id + ":" + ("null" if self.filter is None else "\"" + self.filter + "\"") + return ( + self.id + ":" + ("null" if self.filter is None else '"' + self.filter + '"') + ) class GOG: @@ -58,14 +61,14 @@ def __init__(self, app_ids, notifier, ignore_first): if _app_id in self.new_result: # de-JSON self.new_result[_app_id] = Result( - app=App( - id=_app_id, - name=self.new_result[_app_id]["app"]["name"], - ), - data=self.new_result[_app_id]["data"], - last_checked=self.new_result[_app_id]["last_checked"], - last_updated=self.new_result[_app_id]["last_updated"], - ) + app=App( + id=_app_id, + name=self.new_result[_app_id]["app"]["name"], + ), + data=self.new_result[_app_id]["data"], + last_checked=self.new_result[_app_id]["last_checked"], + last_updated=self.new_result[_app_id]["last_updated"], + ) # disable ignore_first because we're loading from a cached state self.ignore_first = False @@ -78,24 +81,40 @@ def gather_app_info(self): ) _product_info = {} for a in self.apps: - if not a.id in _product_info: + if a.id not in _product_info: try: # get game name - _response = requests.get("https://api.gog.com/products/" + str(a.id)) + _response = requests.get( + "https://api.gog.com/products/" + str(a.id) + ) if _response.status_code != 200: - self.logger.error("GOG api request for " + str(a.id) - + " returned status code " + str(_response.status_code) + " " + _response.url) + self.logger.error( + "GOG api request for " + + str(a.id) + + " returned status code " + + str(_response.status_code) + + " " + + _response.url + ) continue _response.close() _game_name = _response.json()["title"] # get branch info - _response = requests.get("https://content-system.gog.com/products/" + _response = requests.get( + "https://content-system.gog.com/products/" + str(a.id) - + "/os/windows/builds?generation=2") + + "/os/windows/builds?generation=2" + ) if _response.status_code != 200: - self.logger.error("GOG content-system request for " + str(a.id) - + " returned status code " + str(_response.status_code) + " " + _response.url) + self.logger.error( + "GOG content-system request for " + + str(a.id) + + " returned status code " + + str(_response.status_code) + + " " + + _response.url + ) continue _product_info[a.id] = _response.json() _product_info[a.id]["name"] = _game_name @@ -112,15 +131,22 @@ def gather_app_info(self): _latest_info = {} for _product in _product_info: - # GOG can contain multiple entries for each branch, use the one with the latest timestamp + # GOG can contain multiple entries for each branch, + # use the one with the latest timestamp for _release in _product_info[_product]["items"]: # null != "null" so we add quotes around strings to avoid confusion - _branch_key = str(GOGAppFilter(_release["product_id"], _release["branch"])) + _branch_key = str( + GOGAppFilter(_release["product_id"], _release["branch"]) + ) # extract timestamp - _release["timestamp"] = time.mktime(datetime.strptime(_release["date_published"], "%Y-%m-%dT%H:%M:%S%z").timetuple()) + _release["timestamp"] = time.mktime( + datetime.strptime( + _release["date_published"], "%Y-%m-%dT%H:%M:%S%z" + ).timetuple() + ) _release["name"] = _product_info[_product]["name"] - if not _branch_key in _latest_info: - _latest_info[_branch_key] = {'timestamp' : -1} + if _branch_key not in _latest_info: + _latest_info[_branch_key] = {"timestamp": -1} if _latest_info[_branch_key]["timestamp"] < _release["timestamp"]: _latest_info[_branch_key] = _release @@ -162,7 +188,9 @@ def is_updated(self): or self.old_result[key].data != self.new_result[key].data ): self.logger.info( - "Update detected for: {} ({})".format(self.new_result[key].app.name, _app.filter) + "Update detected for: {} ({})".format( + self.new_result[key].app.name, _app.filter + ) ) self.logger.info("New data: {}".format(self.new_result[key].data)) diff --git a/modules/steam.py b/modules/steam.py index d263a7f..d3e7d3a 100644 --- a/modules/steam.py +++ b/modules/steam.py @@ -50,14 +50,14 @@ def __init__(self, app_ids, notifier, ignore_first): if _app_id in self.new_result: # de-JSON self.new_result[_app_id] = Result( - app=App( - id=_app_id, - name=self.new_result[_app_id]["app"]["name"], - ), - data=self.new_result[_app_id]["data"], - last_checked=self.new_result[_app_id]["last_checked"], - last_updated=self.new_result[_app_id]["last_updated"], - ) + app=App( + id=_app_id, + name=self.new_result[_app_id]["app"]["name"], + ), + data=self.new_result[_app_id]["data"], + last_checked=self.new_result[_app_id]["last_checked"], + last_updated=self.new_result[_app_id]["last_updated"], + ) # disable ignore_first because we're loading from a cached state self.ignore_first = False @@ -137,7 +137,9 @@ def is_updated(self): or self.old_result[key].data != self.new_result[key].data ): self.logger.info( - "Update detected for: {} ({})".format(self.new_result[key].app.name, _app.filter) + "Update detected for: {} ({})".format( + self.new_result[key].app.name, _app.filter + ) ) self.logger.info("New data: {}".format(self.new_result[key].data)) diff --git a/modules/utils.py b/modules/utils.py index e56a24f..783dbf8 100644 --- a/modules/utils.py +++ b/modules/utils.py @@ -8,13 +8,15 @@ def save_dict_as_json(dict, path): with open(path, mode="wt", encoding="utf-8") as file: json.dump(dict, file, ensure_ascii=False, indent=2, default=models.json_default) + def load_json_as_dict(path): try: with open(path, mode="r", encoding="utf-8") as file: return json.load(file) - except: + except: # noqa: E722 return {} + def create_directory(path): os.makedirs(path, exist_ok=True)