Skip to content

Commit

Permalink
fix: apply lint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
kurokobo committed May 12, 2023
1 parent 73662a2 commit 98fe90c
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 48 deletions.
5 changes: 2 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
),
Expand Down
20 changes: 12 additions & 8 deletions helper/app_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -93,16 +95,19 @@ def gather_epicgames():

print(tabulate(_table, _header))


def gather_gog_id(id):
# get name
_response = requests.get("https://api.gog.com/products/" + str(id))
_response.close()
_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()

Expand All @@ -111,19 +116,18 @@ 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])
_branches.append(_product["branch"])

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()
Expand All @@ -136,7 +140,6 @@ def gather_gog_name(name):
print(tabulate(_table, _keys))



def main():
parser = argparse.ArgumentParser()
parser.add_argument(
Expand Down Expand Up @@ -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()
4 changes: 3 additions & 1 deletion modules/epicgames.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
80 changes: 54 additions & 26 deletions modules/gog.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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))
Expand Down
20 changes: 11 additions & 9 deletions modules/steam.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 3 additions & 1 deletion modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 98fe90c

Please sign in to comment.