Use EST for Active Games and 1 Day lookback (#129)

Signed-off-by: Alex Resnick <adr8292@gmail.com>
This commit is contained in:
Alex Resnick
2025-10-31 10:22:45 -05:00
committed by GitHub
parent 0a312cc912
commit cd0c43fb3a

View File

@@ -497,11 +497,14 @@ class SportsCore(ABC):
def _fetch_todays_games(self) -> Optional[Dict]:
"""Fetch only today's games for live updates (not entire season)."""
try:
now = datetime.now()
tz = pytz.timezone("EST")
now = datetime.now(tz)
yesterday = now - timedelta(days=1)
formatted_date = now.strftime("%Y%m%d")
formatted_date_yesterday = yesterday.strftime("%Y%m%d")
# Fetch todays games only
url = f"https://site.api.espn.com/apis/site/v2/sports/{self.sport}/{self.league}/scoreboard"
response = self.session.get(url, params={"dates": formatted_date, "limit": 1000}, headers=self.headers, timeout=10)
response = self.session.get(url, params={"dates": f"{formatted_date_yesterday}-{formatted_date}", "limit": 1000}, headers=self.headers, timeout=10)
response.raise_for_status()
data = response.json()
events = data.get('events', [])
@@ -1305,4 +1308,4 @@ class SportsLive(SportsCore):
self.current_game = self.live_games[self.current_game_index]
self.last_game_switch = current_time
self.logger.info(f"Switched live view to: {self.current_game['away_abbr']}@{self.current_game['home_abbr']}") # Changed log prefix
# Force display update via flag or direct call if needed, but usually let main loop handle
# Force display update via flag or direct call if needed, but usually let main loop handle