From 6f5436e653a77950172131f563083ad4392b7687 Mon Sep 17 00:00:00 2001 From: Yarne Coppens Date: Thu, 22 Aug 2024 21:24:01 +0200 Subject: [PATCH] Use version info for owned & wishlisted board games --- src/modules/bgg_connection.py | 36 +++++++++++++++-------------------- tests/test_main.py | 2 +- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/modules/bgg_connection.py b/src/modules/bgg_connection.py index fad6852..2285bc1 100644 --- a/src/modules/bgg_connection.py +++ b/src/modules/bgg_connection.py @@ -123,8 +123,6 @@ def convert_xml_to_boardgame(boardgame_xml: ET.Element) -> boardgame_classes.Boa def convert_collection_xml_to_owned_boardgame(boardgame_extra_info: boardgame_classes.BoardGame, collection_boardgame_xml: ET.Element) -> boardgame_classes.BoardGame: - boardgame_type = collection_boardgame_xml.get('subtype') - price_paid = collection_boardgame_xml.find('privateinfo').get('pricepaid') if price_paid == '': price_paid = 0.0 @@ -152,13 +150,14 @@ def convert_collection_xml_to_owned_boardgame(boardgame_extra_info: boardgame_cl boardgame_extra_info.owned_info = owned_info - # if boardgame_type == "boardgameexpansion": - # expansion_boardgame_dict = { - # "boardgame_id" : boardgame_extra_info.id, - # "expansion_for" : boardgame_extra_info.expansion_for - # } - # expansion_info = boardgame_classes.ExpansionInfo.model_validate(expansion_boardgame_dict) - # boardgame_extra_info.expansion_info = expansion_info + boardgame_version_info = collection_boardgame_xml.find('version') + + if boardgame_version_info != None: + boardgame_extra_info_item = boardgame_version_info.find('item') + boardgame_extra_info.name = collection_boardgame_xml.find('name').text if boardgame_extra_info_item.find('name') != None else boardgame_extra_info.name + boardgame_extra_info.image_url = boardgame_extra_info_item.find('image').text if boardgame_extra_info_item.find('image') != None else boardgame_extra_info.image_url + boardgame_extra_info.thumbnail_url = boardgame_extra_info_item.find('thumbnail').text if boardgame_extra_info_item.find('thumbnail') != None else boardgame_extra_info.thumbnail_url + boardgame_extra_info.year_published = boardgame_extra_info_item.find('yearpublished').get('value') if boardgame_extra_info_item.find('yearpublished') != None else boardgame_extra_info.year_published boardgame = boardgame_extra_info @@ -166,8 +165,6 @@ def convert_collection_xml_to_owned_boardgame(boardgame_extra_info: boardgame_cl def convert_collection_xml_to_wishlist_boardgame(boardgame_extra_info: boardgame_classes.BoardGame, collection_boardgame_xml: ET.Element) -> boardgame_classes.BoardGame: - boardgame_type = collection_boardgame_xml.get('subtype') - wishlist_priority = collection_boardgame_xml.find('status').get('wishlistpriority') wishlist_boardgame_dict = { @@ -178,17 +175,14 @@ def convert_collection_xml_to_wishlist_boardgame(boardgame_extra_info: boardgame boardgame_extra_info.wishlist_info = wishlist_info - # boardgame_dict = { - # **boardgame_extra_info.__dict__, - # **wishlist_boardgame_dict - # } + boardgame_version_info = collection_boardgame_xml.find('version') - # match boardgame_type: - # case "boardgame": - # boardgame = boardgame_classes.WishlistBoardGame(**boardgame_dict) - # case "boardgameexpansion": - # boardgame_dict['expansion_for'] = boardgame_extra_info.expansion_for - # boardgame = boardgame_classes.WishlistBoardGameExpansion(**boardgame_dict) + if boardgame_version_info != None: + boardgame_extra_info_item = boardgame_version_info.find('item') + boardgame_extra_info.name = collection_boardgame_xml.find('name').text if boardgame_extra_info_item.find('name') != None else boardgame_extra_info.name + boardgame_extra_info.image_url = boardgame_extra_info_item.find('image').text if boardgame_extra_info_item.find('image') != None else boardgame_extra_info.image_url + boardgame_extra_info.thumbnail_url = boardgame_extra_info_item.find('thumbnail').text if boardgame_extra_info_item.find('thumbnail') != None else boardgame_extra_info.thumbnail_url + boardgame_extra_info.year_published = boardgame_extra_info_item.find('yearpublished').get('value') if boardgame_extra_info_item.find('yearpublished') != None else boardgame_extra_info.year_published boardgame = boardgame_extra_info diff --git a/tests/test_main.py b/tests/test_main.py index d5ae1b7..9e0cc44 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -125,4 +125,4 @@ def test_retrieve_game_order_statistic(): default_statistic_test(returned_statistic) assert type(returned_statistic.result) == list - assert type(returned_statistic.result[0]) == boardgame_classes.BoardGame \ No newline at end of file + assert type(returned_statistic.result[0]) == boardgame_classes.BoardGamePublic \ No newline at end of file