Separated function to retrieve boardgames from collection url, eg. for wishlist retrieval

This commit is contained in:
Yarne Coppens 2024-08-01 10:11:08 +02:00
parent 5b8bd40970
commit e0c8a6c7dd

View file

@ -107,18 +107,17 @@ def convert_collection_xml_to_boardgame(boardgame_extra_info: BoardGame, collect
return boardgame return boardgame
def get_user_owned_collection() -> list[BoardGame]: def get_boardgames_from_collection_url(collection_url: str) -> 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(collection_url)
collection_xml = url_to_xml_object(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: 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) assert len(boardgame_extras) == len(collection_xml)
@ -127,10 +126,17 @@ def get_user_owned_collection() -> list[BoardGame]:
for boardgame_item in collection_xml: for boardgame_item in collection_xml:
boardgame_extra = boardgame_extras[current_index] boardgame_extra = boardgame_extras[current_index]
boardgame = convert_collection_xml_to_boardgame(boardgame_extra, boardgame_item) boardgame = convert_collection_xml_to_boardgame(boardgame_extra, boardgame_item)
owned_collection_list.append(boardgame) collection_list.append(boardgame)
current_index += 1 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: def load_authenticated_bgg_session(username: str, password: str) -> requests.Session: