Move CLI to own package
This commit is contained in:
parent
d23f364f71
commit
7a1226b232
12 changed files with 273 additions and 179 deletions
32
cli/download_steam_ids.py
Normal file
32
cli/download_steam_ids.py
Normal 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}.")
|
||||
Loading…
Add table
Add a link
Reference in a new issue