From e0c8a6c7dd253a8b8b1bbef4f68b9b009e8277a9 Mon Sep 17 00:00:00 2001 From: Yarne Coppens Date: Thu, 1 Aug 2024 10:11:08 +0200 Subject: [PATCH] Separated function to retrieve boardgames from collection url, eg. for wishlist retrieval --- bgg_connection.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/bgg_connection.py b/bgg_connection.py index bd74679..fc33e01 100644 --- a/bgg_connection.py +++ b/bgg_connection.py @@ -107,18 +107,17 @@ def convert_collection_xml_to_boardgame(boardgame_extra_info: BoardGame, collect return boardgame -def get_user_owned_collection() -> list[BoardGame]: - url = 'https://boardgamegeek.com/xmlapi2/collection?username={}&own=1&stats=1&excludesubtype=boardgameexpansion&showprivate=1&version=1'.format(auth_manager.username) - collection_xml = url_to_xml_object(url) +def get_boardgames_from_collection_url(collection_url: str) -> list[BoardGame]: + collection_xml = url_to_xml_object(collection_url) - owned_collection_list: list[BoardGame] = [] + collection_list: list[BoardGame] = [] - owned_collection_id_list: list[int] = [] + collection_id_list: list[int] = [] for boardgame_item in collection_xml: - owned_collection_id_list.append(boardgame_item.get('objectid')) + collection_id_list.append(boardgame_item.get('objectid')) - boardgame_extras = get_multiple_boardgames(owned_collection_id_list) + boardgame_extras = get_multiple_boardgames(collection_id_list) assert len(boardgame_extras) == len(collection_xml) @@ -127,10 +126,17 @@ def get_user_owned_collection() -> list[BoardGame]: 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) + collection_list.append(boardgame) current_index += 1 - return owned_collection_list + return collection_list + +def get_user_owned_collection() -> list[BoardGame]: + url = 'https://boardgamegeek.com/xmlapi2/collection?username={}&own=1&stats=1&excludesubtype=boardgameexpansion&showprivate=1&version=1'.format(auth_manager.username) + owned_boardgames = get_boardgames_from_collection_url(url) + + return owned_boardgames + def load_authenticated_bgg_session(username: str, password: str) -> requests.Session: