start implementation of fetching game details

This commit is contained in:
Maximilian Keßler 2023-11-23 09:28:13 +01:00
parent a15059318c
commit 059521ea47
Signed by: max
GPG key ID: BCC5A619923C0BA5

View file

@ -178,3 +178,20 @@ def store_new_games(games: Dict[int, GameInfo]):
# We only commit after performing all insertions. This guarantees that the download table is always in sync
# with the actual games stored in the database.
conn.commit()
def detailed_fetch_game(game_id: int):
url = "https://hanab.live/export/{}".format(game_id)
response = session.get(url)
if not response.status_code == 200:
err_msg = "Failed to fetch game {}, requested URL {}".format(game_id, url)
logger.error(err_msg)
raise ConnectionError(err_msg)
game_json = json.loads(response.text)
cur = conn_manager.get_new_cursor()
cur.execute("SELECT user_accounts.normalized_username, user_accounts.user_id FROM user_accounts")
user_name_dict: Dict[str, int] = {}
for username, user_id in cur.fetchall():
user_name_dict[username] = user_id
info = process_game_entry(game_json, user_name_dict, database.get_variant_ids())
print(info)