From 70cfef54ad4cf796b7c24bda06eb30822b525144 Mon Sep 17 00:00:00 2001 From: Yarne Coppens Date: Wed, 31 Jul 2024 14:54:31 +0200 Subject: [PATCH] Created method to produce an authenticated session --- bgg_connection.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/bgg_connection.py b/bgg_connection.py index 0956261..02a02be 100644 --- a/bgg_connection.py +++ b/bgg_connection.py @@ -1,6 +1,7 @@ import requests import xml.etree.ElementTree as ET from pydantic import HttpUrl +import requests from classes.boardgame import BoardGame, BoardGameExpansion @@ -56,4 +57,21 @@ def get_boardgame(boardgame_id: int) -> BoardGame: requested_boardgame = convert_xml_to_boardgame(boardgame_xml_object.find('item')) - return requested_boardgame \ No newline at end of file + return requested_boardgame + +def get_authenticated_bgg_session(username: str, password: str) -> requests.Session: + login_url = "https://boardgamegeek.com/login/api/v1" + + post_data = { + "credentials":{ + "username": username, + "password": password + } + } + + authenticated_session = requests.Session() + login_response = authenticated_session.post(login_url, json=post_data) + + print(login_response.status_code) + + return authenticated_session \ No newline at end of file