From 719eb363a97f3b38cf2edb023ef7af8836201f79 Mon Sep 17 00:00:00 2001 From: Yarne Coppens Date: Fri, 26 Jul 2024 10:46:46 +0200 Subject: [PATCH] can now get information about a single boardgame --- bgg_connection.py | 21 ++++++++++++++++++++- main.py | 3 ++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/bgg_connection.py b/bgg_connection.py index 12e36d6..9727e83 100644 --- a/bgg_connection.py +++ b/bgg_connection.py @@ -12,4 +12,23 @@ def url_to_xml_object(url: HttpUrl) -> ET.Element: def get_boardgame(boardgame_id: int) -> BoardGame: url : str = "https://boardgamegeek.com/xmlapi2/thing?id={}&stats=true".format(boardgame_id) - boardgame_xml_object : ET.Element = url_to_xml_object(url) \ No newline at end of file + boardgame_xml_object : ET.Element = url_to_xml_object(url) + + boardgame_name = boardgame_xml_object.find('item').find('name').get('value') + + requested_boardgame = BoardGame( + id = boardgame_id, + name = boardgame_name, + description = 'Some description', + image_url = 'https://bordspellen.yarnecoppens.com/static/favicon.ico', + thumbnail_url = 'https://bordspellen.yarnecoppens.com/static/favicon.ico', + year_published = 9999, + min_players = 0, + max_players = 99, + min_playing_time = 0, + max_playing_time = 99, + min_age = 0, + all_expansion_ids = [0,1,2,3] + ) + + return requested_boardgame \ No newline at end of file diff --git a/main.py b/main.py index 661398b..3c6e97e 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,7 @@ from typing import Union from fastapi import FastAPI from classes.boardgame import BoardGame, BoardGameExpansion +from bgg_connection import get_boardgame app = FastAPI() @@ -17,4 +18,4 @@ def read_item(item_id: int, q: Union[str, None] = None): @app.get("/boardgame/{boardgame_id}", response_model=BoardGame) def get_boardgame_by_id(boardgame_id: int): - pass \ No newline at end of file + return get_boardgame(boardgame_id) \ No newline at end of file