expansion_ids are now correctly filled

This commit is contained in:
Yarne Coppens 2024-08-01 10:26:40 +02:00
parent e0c8a6c7dd
commit 04906e67c7

View file

@ -37,7 +37,6 @@ def get_multiple_boardgames(boardgame_ids: list[int]) -> list[BoardGame]:
for boardgame_id_list_size_20 in boardgame_ids_divided: for boardgame_id_list_size_20 in boardgame_ids_divided:
boardgame_id_list_commas: str = ','.join(boardgame_id_list_size_20) boardgame_id_list_commas: str = ','.join(boardgame_id_list_size_20)
url : str = "https://boardgamegeek.com/xmlapi2/thing?id={}&stats=true".format(boardgame_id_list_commas) url : str = "https://boardgamegeek.com/xmlapi2/thing?id={}&stats=true".format(boardgame_id_list_commas)
print(url)
boardgames_xml_object : ET.Element = url_to_xml_object(url) boardgames_xml_object : ET.Element = url_to_xml_object(url)
for boardgame_xml_object in boardgames_xml_object: for boardgame_xml_object in boardgames_xml_object:
@ -53,6 +52,14 @@ def convert_xml_to_boardgame(boardgame_xml: ET.Element) -> BoardGame:
boardgame_type = boardgame_xml.get('type') boardgame_type = boardgame_xml.get('type')
expansion_ids: list[int] = []
all_links = boardgame_xml.findall('link')
for link in all_links:
if link.get('type') == 'boardgameexpansion':
expansion_ids.append(int(link.get('id')))
boardgame_dict = { boardgame_dict = {
"id" : int(boardgame_xml.get('id')), "id" : int(boardgame_xml.get('id')),
"name" : boardgame_xml.find('name').get('value'), "name" : boardgame_xml.find('name').get('value'),
@ -65,7 +72,7 @@ def convert_xml_to_boardgame(boardgame_xml: ET.Element) -> BoardGame:
"min_playing_time" : int(boardgame_xml.find('minplaytime').get('value')), "min_playing_time" : int(boardgame_xml.find('minplaytime').get('value')),
"max_playing_time" : int(boardgame_xml.find('maxplaytime').get('value')), "max_playing_time" : int(boardgame_xml.find('maxplaytime').get('value')),
"min_age" : int(boardgame_xml.find('minage').get('value')), "min_age" : int(boardgame_xml.find('minage').get('value')),
"all_expansion_ids" : [0,1,2,3] "all_expansion_ids" : expansion_ids
} }
match boardgame_type: match boardgame_type:
@ -94,7 +101,7 @@ def convert_collection_xml_to_boardgame(boardgame_extra_info: BoardGame, collect
"min_playing_time" : boardgame_extra_info.min_playing_time, "min_playing_time" : boardgame_extra_info.min_playing_time,
"max_playing_time" : boardgame_extra_info.max_playing_time, "max_playing_time" : boardgame_extra_info.max_playing_time,
"min_age" : boardgame_extra_info.min_age, "min_age" : boardgame_extra_info.min_age,
"all_expansion_ids" : [0,1,2,3] "all_expansion_ids" : boardgame_extra_info.all_expansion_ids
} }
match boardgame_type: match boardgame_type: