From 059521ea47992d74e759e999c1e50f9a0ca3099e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Thu, 23 Nov 2023 09:28:13 +0100 Subject: [PATCH] start implementation of fetching game details --- fetch_games.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/fetch_games.py b/fetch_games.py index 6b61065..3e9f860 100644 --- a/fetch_games.py +++ b/fetch_games.py @@ -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)