diff options
| author | Pinapelz <yukais@pinapelz.com> | 2026-06-05 11:23:34 -0700 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2026-06-05 11:23:34 -0700 |
| commit | 95d56dd94153cf464ada2c9bbbe840a3da14f98a (patch) | |
| tree | 9967f18d5f0a6f0f189078f0fa05929bd234980f /steam.py | |
init commit
Diffstat (limited to 'steam.py')
| -rw-r--r-- | steam.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/steam.py b/steam.py new file mode 100644 index 0000000..3903f76 --- /dev/null +++ b/steam.py @@ -0,0 +1,50 @@ +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() |
