Move CLI to own package

This commit is contained in:
Joakim Hellsén 2024-06-27 11:53:39 +02:00
commit 7a1226b232
No known key found for this signature in database
GPG key ID: D196AE66FEBE1DC9
12 changed files with 273 additions and 179 deletions

32
cli/download_steam_ids.py Normal file
View file

@ -0,0 +1,32 @@
from pathlib import Path
import requests
from rich import print
from app.settings import DATA_DIR
from cli.cli import app
@app.command(
name="download_steam_ids",
help="Download Steam IDs from the Steam API.",
)
def download_steam_ids() -> None:
"""Download Steam IDs from "https://api.steampowered.com/ISteamApps/GetAppList/v2/"."""
print("Downloading Steam IDs...")
r: requests.Response = requests.get(
"https://api.steampowered.com/ISteamApps/GetAppList/v2/",
timeout=10,
)
r.raise_for_status()
data: dict[str, dict[str, list[dict[str, str]]]] = r.json()
app_ids: list[dict[str, str]] = data["applist"]["apps"]
file_path: Path = Path(DATA_DIR) / "steam_ids.txt"
with file_path.open("w", encoding="utf-8") as f:
for app_id in app_ids:
f.write(f"{app_id["appid"]}\n")
print(f"Steam IDs downloaded. {len(app_ids)} IDs saved to {file_path}.")