Skip to content

Commit

Permalink
check_gamefixes: use single quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
R1kaB3rN committed Aug 4, 2024
1 parent 0783c43 commit 0c2ec01
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions tools/check_gamefixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@


headers = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:127.0) Gecko/20100101 Firefox/127.0",
"Accept": "application/font-woff2;q=1.0,application/font-woff;q=0.9,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.5",
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:127.0) Gecko/20100101 Firefox/127.0',
'Accept': 'application/font-woff2;q=1.0,application/font-woff;q=0.9,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.5',
}

# Steam games that are no longer on sale, but are valid IDs
Expand All @@ -31,17 +31,17 @@ def check_steamfixes(project: Path, url: str, api: ApiEndpoint) -> None:
appids = set()

# Get all IDs
for file in project.joinpath("gamefixes-steam").glob("*"):
appid = file.name.removesuffix(".py")
for file in project.joinpath('gamefixes-steam').glob('*'):
appid = file.name.removesuffix('.py')
if not appid.isnumeric():
continue
appids.add(int(appid))

# Check the IDs against ours
with urlopen(Request(url, headers=headers), timeout=500) as r:
for obj in ijson.items(r, "applist.apps.item"):
if obj["appid"] in appids:
appids.remove(obj["appid"])
for obj in ijson.items(r, 'applist.apps.item'):
if obj['appid'] in appids:
appids.remove(obj['appid'])
if not appids:
break

Expand All @@ -52,12 +52,12 @@ def check_steamfixes(project: Path, url: str, api: ApiEndpoint) -> None:
conn = HTTPSConnection(host)

for appid in appids.copy():
conn.request("GET", f"{endpoint}{appid}")
conn.request('GET', f'{endpoint}{appid}')
r = conn.getresponse()
parser: Iterator[tuple[str, str, Any]] = ijson.parse(r)

for prefix, _, value in parser:
if prefix == f"{appid}.success" and isinstance(value, bool) and value:
if prefix == f'{appid}.success' and isinstance(value, bool) and value:
appids.remove(appid)
break
if not appids:
Expand All @@ -69,7 +69,7 @@ def check_steamfixes(project: Path, url: str, api: ApiEndpoint) -> None:

for appid in appids:
if appid not in whitelist_steam:
err = f"Steam app id is invalid: {appid}"
err = f'Steam app id is invalid: {appid}'
raise ValueError(err)


Expand All @@ -83,24 +83,24 @@ def check_gogfixes(project: Path, url: str, api: ApiEndpoint) -> None:

# Find all IDs in batches of 50. The gog api enforces 50 ids per request
# See https://gogapidocs.readthedocs.io/en/latest/galaxy.html#get--products
for gogids in _batch_generator(project.joinpath("gamefixes-gog")):
sep = "%2C" # Required comma separator character. See the docs.
for gogids in _batch_generator(project.joinpath('gamefixes-gog')):
sep = '%2C' # Required comma separator character. See the docs.
appids = gogids.copy()

with urlopen(
Request(f"{url}{sep.join(appids)}", headers=headers), timeout=500
Request(f'{url}{sep.join(appids)}', headers=headers), timeout=500
) as r:
for obj in ijson.items(r, "item"):
for obj in ijson.items(r, 'item'):
# Like Steam's, app ids are integers
if (appid := str(obj["id"])) in appids:
if (appid := str(obj['id'])) in appids:
appids.remove(appid)
if not appids:
break

# IDs may be links to Steam fixes.
if appids:
for file in project.joinpath("gamefixes-steam").glob("*"):
if (appid := file.name.removesuffix(".py")) in appids:
for file in project.joinpath('gamefixes-steam').glob('*'):
if (appid := file.name.removesuffix('.py')) in appids:
appids.remove(appid)
if not appids:
break
Expand All @@ -109,7 +109,7 @@ def check_gogfixes(project: Path, url: str, api: ApiEndpoint) -> None:
if appids:
host, endpoint = api
conn = HTTPSConnection(host)
conn.request("GET", endpoint)
conn.request('GET', endpoint)
r = conn.getresponse()

for obj in ijson.items(r, 'item'):
Expand All @@ -122,8 +122,8 @@ def check_gogfixes(project: Path, url: str, api: ApiEndpoint) -> None:

if appids:
err = (
"The following GOG app ids are invalid or are missing entries"
f" in the umu database: {appids}"
'The following GOG app ids are invalid or are missing entries'
f' in the umu database: {appids}'
)
raise ValueError(err)

Expand All @@ -134,8 +134,8 @@ def _batch_generator(gamefix: Path, size=50) -> Generator[set[str], Any, Any]:
count = 0

# Process only umu-* app ids
for file in gamefix.glob("*"):
appid = file.name.removeprefix("umu-").removesuffix(".py")
for file in gamefix.glob('*'):
appid = file.name.removeprefix('umu-').removesuffix('.py')
appids.add(appid)
if count == size:
yield appids
Expand All @@ -158,27 +158,27 @@ def main() -> None:
# making a request to `api.steampowered.com`.
# NOTE: There's neither official nor unofficial documentation. Only forum posts
# See https://stackoverflow.com/questions/46330864/steam-api-all-games
steamapi: ApiEndpoint = ("store.steampowered.com", "/api/appdetails?appids=")
steamapi: ApiEndpoint = ('store.steampowered.com', '/api/appdetails?appids=')

# UMU Database, that will be used to validate umu gamefixes ids against
# See https://github.com/Open-Wine-Components/umu-database/blob/main/README.md
umudb_gog: ApiEndpoint = ("umu.openwinecomponents.org", "/umu_api.php?store=gog")
umudb_gog: ApiEndpoint = ('umu.openwinecomponents.org', '/umu_api.php?store=gog')

# Steam API
# Main API used to validate steam gamefixes
# NOTE: There's neither official nor unofficial documentation. Only forum posts
# See https://stackoverflow.com/questions/46330864/steam-api-all-games
steampowered = (
"https://api.steampowered.com/ISteamApps/GetAppList/v0002/?format=json"
'https://api.steampowered.com/ISteamApps/GetAppList/v0002/?format=json'
)

# GOG API
# See https://gogapidocs.readthedocs.io/en/latest/galaxy.html#get--products
gogapi = "https://api.gog.com/products?ids="
gogapi = 'https://api.gog.com/products?ids='

check_steamfixes(project, steampowered, steamapi)
check_gogfixes(project, gogapi, umudb_gog)


if __name__ == "__main__":
if __name__ == '__main__':
main()

0 comments on commit 0c2ec01

Please sign in to comment.