From cfff61853a6cd537c6cd5cdba9bd6f2c9d04c30a Mon Sep 17 00:00:00 2001 From: Yarne Coppens Date: Thu, 1 Aug 2024 10:35:51 +0200 Subject: [PATCH] Added endpoint to retrieve wishlist --- bgg_connection.py | 7 ++++++- main.py | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/bgg_connection.py b/bgg_connection.py index 9b98cf7..994628a 100644 --- a/bgg_connection.py +++ b/bgg_connection.py @@ -10,7 +10,7 @@ authenticated_session: requests.Session = requests.Session() def url_to_xml_object(url: HttpUrl) -> ET.Element: r = authenticated_session.get(url) - assert r.status_code == 200 + assert r.status_code == 200, "Got {} status code".format(r.status_code) root = ET.fromstring(r.content) return root @@ -144,6 +144,11 @@ def get_user_owned_collection() -> list[BoardGame]: return owned_boardgames +def get_user_wishlist_collection() -> list[BoardGame]: + url = 'https://boardgamegeek.com/xmlapi2/collection?username={}&wishlist=1&stats=1&showprivate=1&version=1'.format(auth_manager.username) + wishlisted_boardgames = get_boardgames_from_collection_url(url) + + return wishlisted_boardgames def load_authenticated_bgg_session(username: str, password: str) -> requests.Session: diff --git a/main.py b/main.py index 2675452..7bf4310 100644 --- a/main.py +++ b/main.py @@ -2,7 +2,7 @@ from typing import Union from fastapi import FastAPI from classes.boardgame import BoardGame, BoardGameExpansion -from bgg_connection import get_boardgame, get_user_owned_collection +from bgg_connection import get_boardgame, get_user_owned_collection, get_user_wishlist_collection app = FastAPI() @@ -24,4 +24,10 @@ def get_boardgame_by_id(boardgame_id: int): @app.get("/collection", response_model=list[BoardGame]) def get_owned_collection(): requested_collection: list[BoardGame] = get_user_owned_collection() + return requested_collection + + +@app.get("/wishlist", response_model=list[BoardGame]) +def get_wishlist_collection(): + requested_collection: list[BoardGame] = get_user_wishlist_collection() return requested_collection \ No newline at end of file