try to match to steam game
This commit is contained in:
@@ -11,6 +11,7 @@ logger = logging.getLogger(__name__)
|
||||
# Public store endpoint, no API key needed. Rate limited to ~200 calls / 5 min,
|
||||
# which is plenty for a handful of games every few hours.
|
||||
APP_DETAILS_URL = "https://store.steampowered.com/api/appdetails"
|
||||
STORE_SEARCH_URL = "https://store.steampowered.com/api/storesearch/"
|
||||
|
||||
|
||||
class SteamStoreError(Exception):
|
||||
@@ -37,6 +38,17 @@ def fetch_app_details(steam_app_id: int) -> dict:
|
||||
return entry["data"]
|
||||
|
||||
|
||||
def search_store(term: str) -> list[dict]:
|
||||
"""Store search results for term, as [{"id": app id, "name": ...}, ...]."""
|
||||
response = httpx.get(
|
||||
STORE_SEARCH_URL,
|
||||
params={"term": term, "cc": settings.STEAM_STORE_COUNTRY, "l": "english"},
|
||||
timeout=10,
|
||||
)
|
||||
response.raise_for_status()
|
||||
return (response.json() or {}).get("items") or []
|
||||
|
||||
|
||||
def refresh_steam_game(game: Game) -> None:
|
||||
"""Pull the current store info for a Steam game into its steam_* fields."""
|
||||
data = fetch_app_details(game.steam_app_id)
|
||||
|
||||
Reference in New Issue
Block a user