Enabled working collection endpoint to retrieve all boardgames from owned collection
This commit is contained in:
parent
5f05e6bf82
commit
5b8bd40970
1 changed files with 30 additions and 19 deletions
|
|
@ -34,14 +34,14 @@ def get_multiple_boardgames(boardgame_ids: list[int]) -> list[BoardGame]:
|
|||
#Boardgamegeek only allows chunks of 20 boardgames at a time
|
||||
boardgame_ids_divided = list(divide_list_in_chunks(boardgame_ids))
|
||||
|
||||
for boardgame_id_list_20 in boardgame_ids_divided:
|
||||
boardgame_id_list_commas: str = ','.join(boardgame_id_list_20)
|
||||
for boardgame_id_list_size_20 in boardgame_ids_divided:
|
||||
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)
|
||||
print(url)
|
||||
boardgames_xml_object : ET.Element = url_to_xml_object(url)
|
||||
|
||||
for boardgame_xml_object in boardgames_xml_object:
|
||||
requested_boardgame = convert_xml_to_boardgame(boardgame_xml_object.find('item'))
|
||||
requested_boardgame = convert_xml_to_boardgame(boardgame_xml_object)
|
||||
boardgame_list_to_return.append(requested_boardgame)
|
||||
|
||||
return boardgame_list_to_return
|
||||
|
|
@ -78,24 +78,22 @@ def convert_xml_to_boardgame(boardgame_xml: ET.Element) -> BoardGame:
|
|||
|
||||
return boardgame
|
||||
|
||||
def convert_collection_xml_to_boardgame(boardgame_xml: ET.Element) -> BoardGame:
|
||||
def convert_collection_xml_to_boardgame(boardgame_extra_info: BoardGame, collection_boardgame_xml: ET.Element) -> BoardGame:
|
||||
|
||||
boardgame_extra: BoardGame = get_boardgame(boardgame_xml.get('objectid'))
|
||||
|
||||
boardgame_type = boardgame_xml.get('subtype')
|
||||
boardgame_type = collection_boardgame_xml.get('subtype')
|
||||
|
||||
boardgame_dict = {
|
||||
"id" : boardgame_extra.id,
|
||||
"name" : boardgame_extra.name,
|
||||
"description" : boardgame_extra.description,
|
||||
"image_url" : boardgame_extra.image_url,
|
||||
"thumbnail_url" : boardgame_extra.thumbnail_url,
|
||||
"year_published" : boardgame_extra.year_published,
|
||||
"min_players" : boardgame_extra.min_players,
|
||||
"max_players" : boardgame_extra.max_players,
|
||||
"min_playing_time" : boardgame_extra.min_playing_time,
|
||||
"max_playing_time" : boardgame_extra.max_playing_time,
|
||||
"min_age" : boardgame_extra.min_age,
|
||||
"id" : boardgame_extra_info.id,
|
||||
"name" : boardgame_extra_info.name,
|
||||
"description" : boardgame_extra_info.description,
|
||||
"image_url" : boardgame_extra_info.image_url,
|
||||
"thumbnail_url" : boardgame_extra_info.thumbnail_url,
|
||||
"year_published" : boardgame_extra_info.year_published,
|
||||
"min_players" : boardgame_extra_info.min_players,
|
||||
"max_players" : boardgame_extra_info.max_players,
|
||||
"min_playing_time" : boardgame_extra_info.min_playing_time,
|
||||
"max_playing_time" : boardgame_extra_info.max_playing_time,
|
||||
"min_age" : boardgame_extra_info.min_age,
|
||||
"all_expansion_ids" : [0,1,2,3]
|
||||
}
|
||||
|
||||
|
|
@ -115,9 +113,22 @@ def get_user_owned_collection() -> list[BoardGame]:
|
|||
|
||||
owned_collection_list: list[BoardGame] = []
|
||||
|
||||
owned_collection_id_list: list[int] = []
|
||||
|
||||
for boardgame_item in collection_xml:
|
||||
boardgame = convert_collection_xml_to_boardgame(boardgame_item)
|
||||
owned_collection_id_list.append(boardgame_item.get('objectid'))
|
||||
|
||||
boardgame_extras = get_multiple_boardgames(owned_collection_id_list)
|
||||
|
||||
assert len(boardgame_extras) == len(collection_xml)
|
||||
|
||||
current_index = 0
|
||||
|
||||
for boardgame_item in collection_xml:
|
||||
boardgame_extra = boardgame_extras[current_index]
|
||||
boardgame = convert_collection_xml_to_boardgame(boardgame_extra, boardgame_item)
|
||||
owned_collection_list.append(boardgame)
|
||||
current_index += 1
|
||||
|
||||
return owned_collection_list
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue