Skip to content

Commit

Permalink
added location and start time of game in unix
Browse files Browse the repository at this point in the history
  • Loading branch information
day-mon committed Jan 16, 2024
1 parent 613fbb7 commit 6cd3a5c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
6 changes: 6 additions & 0 deletions api/api/business/daily_games.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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}",
Expand Down
1 change: 1 addition & 0 deletions api/api/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

46 changes: 45 additions & 1 deletion api/api/model/games/daily_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 6cd3a5c

Please sign in to comment.