Spaces:
Sleeping
Sleeping
File size: 1,058 Bytes
60f5126 | 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 | from __future__ import annotations
from typing import Any
import pandas as pd
import requests
from config.settings import MLB_TEAMS_URL
def fetch_mlb_teams() -> pd.DataFrame:
response = requests.get(MLB_TEAMS_URL, params={"sportId": 1}, timeout=30)
response.raise_for_status()
payload = response.json()
rows: list[dict[str, Any]] = []
for team in payload.get("teams", []):
rows.append(
{
"team_id": team.get("id"),
"name": team.get("name"),
"team_code": team.get("teamCode"),
"file_code": team.get("fileCode"),
"abbreviation": team.get("abbreviation"),
"location_name": team.get("locationName"),
"club_name": team.get("clubName"),
"league_name": (team.get("league") or {}).get("name"),
"division_name": (team.get("division") or {}).get("name"),
"venue_name": (team.get("venue") or {}).get("name"),
}
)
return pd.DataFrame(rows) |