diff --git a/api/api/business/daily_games.py b/api/api/business/daily_games.py index 60a7409..62dceed 100644 --- a/api/api/business/daily_games.py +++ b/api/api/business/daily_games.py @@ -1,4 +1,6 @@ from abc import ABC, abstractmethod +from datetime import datetime + import httpx from api.business.factory import AbstractFactory, FactoryItem from api.model.games.daily_game import NBALiveData, DailyGame, TeamData, PlayerLeader @@ -38,11 +40,15 @@ async def fetch(self) -> list[DailyGame]: return daily_games for game in games: + datetime_obj = datetime.strptime(game.gameTimeUTC, "%Y-%m-%dT%H:%M:%SZ") + unix_timestamp = datetime_obj.timestamp() + daily_games.append( DailyGame( game_id=game.gameId, game_date=game_data.scoreboard.gameDate, game_status=game.gameStatusText, + game_start_unix=unix_timestamp, home_team=TeamData( id=game.homeTeam.teamId, name=f"{game.homeTeam.teamCity} {game.homeTeam.teamName}", diff --git a/api/api/constants.py b/api/api/constants.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/api/api/constants.py @@ -0,0 +1 @@ + diff --git a/api/api/model/games/daily_game.py b/api/api/model/games/daily_game.py index 3a3d254..41b48c9 100644 --- a/api/api/model/games/daily_game.py +++ b/api/api/model/games/daily_game.py @@ -4,9 +4,41 @@ from pydantic import BaseModel +from api import constants from api.model.games.injury import InjuryItem - +LOCATION_DATA = { + "ATL": {"name": "State Farm Arena", "city": "Atlanta", "state": "GA"}, + "BOS": {"name": "TD Garden", "city": "Boston", "state": "MA"}, + "BRK": {"name": "Barclays Center", "city": "Brooklyn", "state": "NY"}, + "CHA": {"name": "Spectrum Center", "city": "Charlotte", "state": "NC"}, + "CHI": {"name": "United Center", "city": "Chicago", "state": "IL"}, + "CLE": {"name": "Rocket Mortgage FieldHouse", "city": "Cleveland", "state": "OH"}, + "DAL": {"name": "American Airlines Center", "city": "Dallas", "state": "TX"}, + "DEN": {"name": "Ball Arena", "city": "Denver", "state": "CO"}, + "DET": {"name": "Little Caesars Arena", "city": "Detroit", "state": "MI"}, + "GSW": {"name": "Chase Center", "city": "San Francisco", "state": "CA"}, + "HOU": {"name": "Toyota Center", "city": "Houston", "state": "TX"}, + "IND": {"name": "Gainbridge Fieldhouse", "city": "Indianapolis", "state": "IN"}, + "LAC": {"name": "Crypto.com Arena", "city": "Los Angeles", "state": "CA"}, + "LAL": {"name": "Crypto.com Arena", "city": "Los Angeles", "state": "CA"}, + "MEM": {"name": "FedExForum", "city": "Memphis", "state": "TN"}, + "MIA": {"name": "FTX Arena", "city": "Miami", "state": "FL"}, + "MIL": {"name": "Fiserv Forum", "city": "Milwaukee", "state": "WI"}, + "MIN": {"name": "Target Center", "city": "Minneapolis", "state": "MN"}, + "NOP": {"name": "Smoothie King Center", "city": "New Orleans", "state": "LA"}, + "NYK": {"name": "Madison Square Garden", "city": "New York", "state": "NY"}, + "OKC": {"name": "Paycom Center", "city": "Oklahoma City", "state": "OK"}, + "ORL": {"name": "Amway Center", "city": "Orlando", "state": "FL"}, + "PHI": {"name": "Wells Fargo Center", "city": "Philadelphia", "state": "PA"}, + "PHX": {"name": "Footprint Center", "city": "Phoenix", "state": "AZ"}, + "POR": {"name": "Moda Center", "city": "Portland", "state": "OR"}, + "SAC": {"name": "Golden 1 Center", "city": "Sacramento", "state": "CA"}, + "SAS": {"name": "AT&T Center", "city": "San Antonio", "state": "TX"}, + "TOR": {"name": "Scotiabank Arena", "city": "Toronto", "state": "ON"}, + "UTA": {"name": "Vivint Arena", "city": "Salt Lake City", "state": "UT"}, + "WAS": {"name": "Capital One Arena", "city": "Washington D.C.", "state": "DC"}, +} class Meta(BaseModel): version: int request: str @@ -150,6 +182,7 @@ class DailyGame(BaseModel): game_id: str game_date: str game_status: str + game_start_unix: float home_team: TeamData away_team: TeamData @@ -165,11 +198,20 @@ class Odds(BaseModel): class TeamDataExt(TeamData): injuries: list[InjuryItem] +class Location(BaseModel): + name: str + city: str + state: str + +NBA_STAD_DICT = {abbr: Location(**stadium) for abbr, stadium in LOCATION_DATA.items()} + class DailyGameResponse(BaseModel): id: str date: str status: str + start_time_unix: float + location: Optional[Location] = None home_team: TeamDataExt away_team: TeamDataExt odds: Optional[list[Odds]] = None @@ -187,6 +229,8 @@ def craft_response( DailyGameResponse( id=game.game_id, date=game.game_date, + start_time_unix=game.game_start_unix, + location=NBA_STAD_DICT.get(game.home_team.abbreviation, None), status=game.game_status, home_team=TeamDataExt( id=game.home_team.id,