Fix nfl live update interval (#50)

* Fix NFL live update interval not being respected

- Add NFL managers to _update_modules() method in display_controller.py
- NFL managers now update continuously in background instead of only when displayed
- Fixes issue where NFL live data would only fetch once and never update
- NFL live manager now properly respects 30-second live_update_interval setting
- Also add NFL managers to deferred updates when display is scrolling

* Fix NFL Recent and Upcoming managers to use correct update intervals

- NFL Recent Manager now uses recent_update_interval (3600 seconds) instead of hardcoded 300
- NFL Upcoming Manager now uses upcoming_update_interval (3600 seconds) instead of hardcoded 300
- Ensures proper update intervals: Live=30s, Recent=3600s, Upcoming=3600s
- All managers respect their respective config intervals

* Fix NCAAFB managers to use correct update intervals and add to background updates

- NCAAFB Recent Manager now uses recent_update_interval (3600 seconds) instead of hardcoded 300
- NCAAFB Upcoming Manager now uses upcoming_update_interval (3600 seconds) instead of hardcoded 300
- Add NCAAFB managers to _update_modules() method in display_controller.py
- NCAAFB managers now update continuously in background instead of only when displayed
- Add NCAAFB managers to deferred updates when display is scrolling
- Ensures proper update intervals: Live=30s, Recent=3600s, Upcoming=3600s

* Fix NFL live manager to use cached data for fresh updates

- Change NFL Live Manager to use cache=True instead of cache=False
- NFL Live Manager was bypassing cache and not getting fresh data from background service
- Background service fetches and caches data, but live manager was ignoring the cache
- This fixes the issue where NFL live display shows stale data despite successful background fetches
- Live manager now gets fresh data from the background service cache

* Fix NFL live manager to force fresh data fetch when update interval passes

- NFL Live Manager now forces fresh fetch when update interval (30s) has passed
- Uses cache for immediate response but bypasses cache for fresh updates
- Adds logging to show when fresh fetch is forced
- This ensures live game data updates every 30 seconds with fresh scores/clock
- Fixes issue where live display was showing stale data despite background fetches

* Fix NFL live manager to always fetch fresh data from API

- NFL Live Manager now always fetches fresh data directly from ESPN API
- No cache usage for live games - ensures real-time scores and clock updates
- Live games should always show the latest information, not cached data
- This ensures live display updates every 30 seconds with current game state

* Fix NFL live manager to use synchronous API fetch for real-time updates

- NFL Live Manager now uses _fetch_nfl_api_data_sync() for direct API calls
- Bypasses background service and cache for immediate fresh data
- Ensures live games get real-time scores and clock updates every 30 seconds
- Direct API calls are faster and more reliable for live game data

* Fix NFL live manager to fetch only current games instead of entire season

- Create _fetch_current_nfl_games() method for live updates
- Only fetches current week's games, not entire 2025 season (335 events)
- Much faster API calls - only gets relevant live games
- Reduces API load and improves performance for live updates
- NFL Live Manager now fetches ~10-15 current games instead of 335 season games

* ensure live games aren't pulling whole season

* bugbot catches
This commit is contained in:
Chuck
2025-09-18 23:29:11 -04:00
committed by GitHub
parent 9dc1118d79
commit 86049ca679
3 changed files with 31 additions and 5 deletions

View File

@@ -581,8 +581,16 @@ class DisplayController:
# Defer sport manager updates that might do heavy API fetching
if hasattr(self, 'ncaa_fb_live') and self.ncaa_fb_live:
self.display_manager.defer_update(self.ncaa_fb_live.update, priority=3)
if hasattr(self, 'ncaa_fb_recent') and self.ncaa_fb_recent:
self.display_manager.defer_update(self.ncaa_fb_recent.update, priority=3)
if hasattr(self, 'ncaa_fb_upcoming') and self.ncaa_fb_upcoming:
self.display_manager.defer_update(self.ncaa_fb_upcoming.update, priority=3)
if hasattr(self, 'nfl_live') and self.nfl_live:
self.display_manager.defer_update(self.nfl_live.update, priority=3)
if hasattr(self, 'nfl_recent') and self.nfl_recent:
self.display_manager.defer_update(self.nfl_recent.update, priority=3)
if hasattr(self, 'nfl_upcoming') and self.nfl_upcoming:
self.display_manager.defer_update(self.nfl_upcoming.update, priority=3)
# Continue with non-scrolling-sensitive updates
if self.weather: self.weather.get_weather()
if self.calendar: self.calendar.update(time.time())

View File

@@ -1193,7 +1193,7 @@ class NCAAFBRecentManager(BaseNCAAFBManager): # Renamed class
self.games_list = [] # Filtered list for display (favorite teams)
self.current_game_index = 0
self.last_update = 0
self.update_interval = 300 # Check for recent games every 5 mins
self.update_interval = self.ncaa_fb_config.get("recent_update_interval", 3600) # Check for recent games every hour
self.last_game_switch = 0
self.game_display_duration = 15 # Display each recent game for 15 seconds
self.logger.info(f"Initialized NCAAFBRecentManager with {len(self.favorite_teams)} favorite teams") # Changed log prefix
@@ -1492,7 +1492,7 @@ class NCAAFBUpcomingManager(BaseNCAAFBManager): # Renamed class
self.games_list = [] # Filtered list for display (favorite teams)
self.current_game_index = 0
self.last_update = 0
self.update_interval = 300 # Check for upcoming games every 5 mins
self.update_interval = self.ncaa_fb_config.get("upcoming_update_interval", 3600) # Check for upcoming games every hour
self.last_log_time = 0
self.log_interval = 300
self.last_warning_time = 0

View File

@@ -313,11 +313,29 @@ class BaseNFLManager: # Renamed class
return None
def _fetch_current_nfl_games(self) -> Optional[Dict]:
"""Fetch only current NFL games for live updates (not entire season)."""
try:
# Fetch current week's games only
url = "https://site.api.espn.com/apis/site/v2/sports/football/nfl/scoreboard"
response = self.session.get(url, headers=self.headers, timeout=10)
response.raise_for_status()
data = response.json()
events = data.get('events', [])
self.logger.info(f"[NFL Live] Fetched {len(events)} current games")
return {'events': events}
except requests.exceptions.RequestException as e:
self.logger.error(f"[NFL Live] API error fetching current games: {e}")
return None
def _fetch_data(self, date_str: str = None) -> Optional[Dict]:
"""Fetch data using shared data mechanism or direct fetch for live."""
if isinstance(self, NFLLiveManager):
return self._fetch_nfl_api_data(use_cache=False)
# Live games should fetch only current games, not entire season
return self._fetch_current_nfl_games()
else:
# Recent and Upcoming managers should use cached season data
return self._fetch_nfl_api_data(use_cache=True)
def _load_fonts(self):
@@ -1005,7 +1023,7 @@ class NFLRecentManager(BaseNFLManager): # Renamed class
self.games_list = [] # Filtered list for display (favorite teams)
self.current_game_index = 0
self.last_update = 0
self.update_interval = 300 # Check for recent games every 5 mins
self.update_interval = self.nfl_config.get("recent_update_interval", 3600) # Check for recent games every hour
self.last_game_switch = 0
self.game_display_duration = 15 # Display each recent game for 15 seconds
self.logger.info(f"Initialized NFLRecentManager with {len(self.favorite_teams)} favorite teams")
@@ -1245,7 +1263,7 @@ class NFLUpcomingManager(BaseNFLManager): # Renamed class
self.games_list = [] # Filtered list for display (favorite teams)
self.current_game_index = 0
self.last_update = 0
self.update_interval = 300 # Check for upcoming games every 5 mins
self.update_interval = self.nfl_config.get("upcoming_update_interval", 3600) # Check for upcoming games every hour
self.last_log_time = 0
self.log_interval = 300
self.last_warning_time = 0