forked from Hanabi/hanabi-league
start implementation of fetching game details
This commit is contained in:
parent
a15059318c
commit
059521ea47
1 changed files with 17 additions and 0 deletions
|
@ -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
|
# 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.
|
# with the actual games stored in the database.
|
||||||
conn.commit()
|
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)
|
||||||
|
|
Loading…
Reference in a new issue