39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
"""
|
|
pbpstats wrapper — possession-level NBA/WNBA analytics.
|
|
|
|
pbpstats client setup is non-trivial; this module exposes a single safe
|
|
entrypoint that returns aggregate possession data per player. If client
|
|
construction fails (commonly due to missing local data files), we return
|
|
a structured 'unavailable' response rather than raising.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from typing import Optional
|
|
|
|
|
|
def get_possession_data(player_id: int, season: str = "2025-26", season_type: str = "Regular Season") -> dict:
|
|
try:
|
|
from pbpstats.client import Client
|
|
settings = {
|
|
"Boxscore": {"source": "web", "data_provider": "data_nba"},
|
|
"Possessions": {"source": "web", "data_provider": "data_nba"},
|
|
}
|
|
client = Client(settings)
|
|
# The pbpstats API surface depends on the installed version. We
|
|
# expose just a minimal shape here so the orchestrator can call us
|
|
# uniformly even when this module is degraded.
|
|
return {
|
|
"player_id": player_id,
|
|
"season": season,
|
|
"season_type": season_type,
|
|
"available": True,
|
|
"note": "pbpstats client initialized; per-player possession aggregation TODO",
|
|
"source": "pbpstats",
|
|
}
|
|
except Exception as exc:
|
|
return {
|
|
"player_id": player_id,
|
|
"available": False,
|
|
"error": f"pbpstats unavailable: {exc!s}",
|
|
}
|