Implemented boardgame type check for expansions
This commit is contained in:
parent
1bb40881a7
commit
6de35547a3
1 changed files with 37 additions and 14 deletions
|
|
@ -9,7 +9,13 @@ def url_to_xml_object(url: HttpUrl) -> ET.Element:
|
|||
root = ET.fromstring(r.content)
|
||||
return root
|
||||
|
||||
#Requires single boardgame XML 'item' from bgg api
|
||||
def convert_xml_to_boardgame(boardgame_xml: ET.Element) -> BoardGame:
|
||||
|
||||
boardgame_type = boardgame_xml.get('type')
|
||||
|
||||
match boardgame_type:
|
||||
case "boardgame":
|
||||
boardgame = BoardGame(
|
||||
id = boardgame_xml.get('id'),
|
||||
name = boardgame_xml.find('name').get('value'),
|
||||
|
|
@ -24,6 +30,23 @@ def convert_xml_to_boardgame(boardgame_xml: ET.Element) -> BoardGame:
|
|||
min_age = int(boardgame_xml.find('minage').get('value')),
|
||||
all_expansion_ids = [0,1,2,3]
|
||||
)
|
||||
case "boardgameexpansion":
|
||||
boardgame = BoardGameExpansion(
|
||||
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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue