from __future__ import annotations from typing import Any import requests SAVANT_GF_URL = "https://baseballsavant.mlb.com/gf" def fetch_live_statcast_feed(game_pk: str) -> dict[str, Any]: """ Fetch Baseball Savant live gamefeed payload for a game_pk. This is an unofficial endpoint and should fail gracefully. """ game_pk = str(game_pk or "").strip() if not game_pk: return {} try: response = requests.get( SAVANT_GF_URL, params={"game_pk": game_pk}, timeout=20, headers={ "User-Agent": "Mozilla/5.0", "Accept": "application/json,text/plain,*/*", "Referer": "https://baseballsavant.mlb.com/", }, ) response.raise_for_status() data = response.json() return data if isinstance(data, dict) else {} except Exception: return {}