can now get information about a single boardgame
This commit is contained in:
parent
7b94d0074d
commit
719eb363a9
2 changed files with 22 additions and 2 deletions
|
|
@ -12,4 +12,23 @@ def url_to_xml_object(url: HttpUrl) -> ET.Element:
|
||||||
|
|
||||||
def get_boardgame(boardgame_id: int) -> BoardGame:
|
def get_boardgame(boardgame_id: int) -> BoardGame:
|
||||||
url : str = "https://boardgamegeek.com/xmlapi2/thing?id={}&stats=true".format(boardgame_id)
|
url : str = "https://boardgamegeek.com/xmlapi2/thing?id={}&stats=true".format(boardgame_id)
|
||||||
boardgame_xml_object : ET.Element = url_to_xml_object(url)
|
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
|
||||||
3
main.py
3
main.py
|
|
@ -2,6 +2,7 @@ from typing import Union
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
|
||||||
from classes.boardgame import BoardGame, BoardGameExpansion
|
from classes.boardgame import BoardGame, BoardGameExpansion
|
||||||
|
from bgg_connection import get_boardgame
|
||||||
|
|
||||||
app = FastAPI()
|
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)
|
@app.get("/boardgame/{boardgame_id}", response_model=BoardGame)
|
||||||
def get_boardgame_by_id(boardgame_id: int):
|
def get_boardgame_by_id(boardgame_id: int):
|
||||||
pass
|
return get_boardgame(boardgame_id)
|
||||||
Loading…
Reference in a new issue