import os import requests from dotenv import load_dotenv load_dotenv() POCKETBASE_URL = os.getenv("POCKETBASE_URL", "http://127.0.0.1:8090") POCKETBASE_TOKEN = os.getenv("POCKETBASE_TOKEN") def add_steam_game(app_id: int): steam_resp = requests.get( f"https://store.steampowered.com/api/appdetails?appids={app_id}", timeout=30, ) steam_resp.raise_for_status() steam_data = steam_resp.json().get(str(app_id)) if not steam_data or not steam_data["success"]: raise ValueError(f"Steam app {app_id} not found") data = steam_data["data"] record = { "name": data["name"], "description": data.get("short_description", ""), "image": data.get("header_image", ""), "url": f"https://store.steampowered.com/app/{app_id}", "type": "Game", "played": False, "notes": "", } resp = requests.post( f"{POCKETBASE_URL}/api/collections/list/records", headers={ "Authorization": f"Bearer {POCKETBASE_TOKEN}", "Content-Type": "application/json", }, json=record, timeout=30, ) if not resp.ok: print(resp.status_code) print(resp.text) resp.raise_for_status() return resp.json()