2024-07-25 19:58:28 +02:00
|
|
|
import requests
|
|
|
|
|
import xml.etree.ElementTree as ET
|
|
|
|
|
from pydantic import HttpUrl
|
|
|
|
|
|
2024-07-25 21:52:49 +02:00
|
|
|
from classes.boardgame import BoardGame, BoardGameExpansion
|
|
|
|
|
|
2024-07-25 19:58:28 +02:00
|
|
|
def url_to_xml_object(url: HttpUrl) -> ET.Element:
|
|
|
|
|
r = requests.get(url)
|
|
|
|
|
root = ET.fromstring(r.content)
|
|
|
|
|
return root
|
2024-07-25 21:52:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_boardgame(boardgame_id: int) -> BoardGame:
|
|
|
|
|
url : str = "https://boardgamegeek.com/xmlapi2/thing?id={}&stats=true".format(boardgame_id)
|
2024-07-26 10:46:46 +02:00
|
|
|
boardgame_xml_object : ET.Element = url_to_xml_object(url)
|
|
|
|
|
|
|
|
|
|
boardgame_name = boardgame_xml_object.find('item').find('name').get('value')
|
|
|
|
|
|
|
|
|
|
requested_boardgame = BoardGame(
|
|
|
|
|
id = boardgame_id,
|
|
|
|
|
name = boardgame_name,
|
|
|
|
|
description = 'Some description',
|
|
|
|
|
image_url = 'https://bordspellen.yarnecoppens.com/static/favicon.ico',
|
|
|
|
|
thumbnail_url = 'https://bordspellen.yarnecoppens.com/static/favicon.ico',
|
|
|
|
|
year_published = 9999,
|
|
|
|
|
min_players = 0,
|
|
|
|
|
max_players = 99,
|
|
|
|
|
min_playing_time = 0,
|
|
|
|
|
max_playing_time = 99,
|
|
|
|
|
min_age = 0,
|
|
|
|
|
all_expansion_ids = [0,1,2,3]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return requested_boardgame
|