1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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()
|