Getting all boardgame attributes. All except expansion id's

This commit is contained in:
Yarne Coppens 2024-07-26 11:41:34 +02:00
parent 719eb363a9
commit 1bb40881a7

View file

@ -9,26 +9,28 @@ def url_to_xml_object(url: HttpUrl) -> ET.Element:
root = ET.fromstring(r.content) root = ET.fromstring(r.content)
return root return root
def convert_xml_to_boardgame(boardgame_xml: ET.Element) -> BoardGame:
boardgame = BoardGame(
id = boardgame_xml.get('id'),
name = boardgame_xml.find('name').get('value'),
description = boardgame_xml.find('description').text,
image_url = boardgame_xml.find('image').text,
thumbnail_url = boardgame_xml.find('thumbnail').text,
year_published = int(boardgame_xml.find('yearpublished').get('value')),
min_players = int(boardgame_xml.find('minplayers').get('value')),
max_players = int(boardgame_xml.find('maxplayers').get('value')),
min_playing_time = int(boardgame_xml.find('minplaytime').get('value')),
max_playing_time = int(boardgame_xml.find('maxplaytime').get('value')),
min_age = int(boardgame_xml.find('minage').get('value')),
all_expansion_ids = [0,1,2,3]
)
return boardgame
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 = convert_xml_to_boardgame(boardgame_xml_object.find('item'))
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 return requested_boardgame