milb logging and manual cache clearing

This commit is contained in:
Chuck
2025-08-09 10:44:58 -05:00
parent a672abba6a
commit b4d5aef876
4 changed files with 168 additions and 1 deletions

View File

@@ -1104,7 +1104,13 @@ class DisplayController:
logger.debug(f"[DisplayController] Calling MiLB live display with {len(self.milb_live.live_games)} live games")
self.milb_live.display(force_clear=self.force_clear)
elif self.current_display_mode == 'milb_live' and self.milb_live:
logger.debug(f"[DisplayController] MiLB live manager exists but has {len(self.milb_live.live_games)} live games, skipping display")
logger.debug(f"[DisplayController] MiLB live manager exists but has {len(self.milb_live.live_games)} live games, switching to next mode")
# Switch to next mode since there are no live games
self.current_mode_index = (self.current_mode_index + 1) % len(self.available_modes)
self.current_display_mode = self.available_modes[self.current_mode_index]
self.force_clear = True
self.last_switch = current_time
logger.info(f"[DisplayController] Switched from milb_live (no games) to {self.current_display_mode}")
elif self.current_display_mode == 'ncaa_fb_upcoming' and self.ncaa_fb_upcoming:
self.ncaa_fb_upcoming.display(force_clear=self.force_clear)
elif self.current_display_mode == 'ncaam_basketball_recent' and self.ncaam_basketball_recent:

View File

@@ -534,6 +534,9 @@ class BaseMiLBManager:
if not self.favorite_teams or is_favorite_game:
status_obj = game['status']
status_state = status_obj.get('abstractGameState', 'Final')
# Debug: Log the original status information
self.logger.debug(f"[MiLB] Status mapping for {away_abbr} @ {home_abbr}: original abstractGameState='{status_state}', full status_obj={status_obj}")
mapped_status = 'unknown'
mapped_status_state = 'unknown'
@@ -737,8 +740,29 @@ class MiLBLiveManager(BaseMiLBManager):
# Find all live games involving favorite teams
new_live_games = []
for game in games.values():
# Debug: Log the status for all games to understand what's happening
self.logger.debug(f"[MiLB] Game status check: {game['away_team']} @ {game['home_team']} - status_state='{game['status_state']}', status='{game['status']}', abstractGameState='{game.get('abstractGameState', 'N/A')}'")
# Only process games that are actually in progress
if game['status_state'] == 'in' and game['status'] == 'status_in_progress':
# Additional check: Verify the game is from today or very recent
game_date_str = game.get('start_time', '')
if game_date_str:
try:
# Parse the game date (assuming it's in ISO format)
game_date = datetime.fromisoformat(game_date_str.replace('Z', '+00:00'))
current_utc = datetime.now(timezone.utc)
hours_diff = (current_utc - game_date).total_seconds() / 3600
# If game is more than 6 hours old, it's probably not actually live
if hours_diff > 6:
self.logger.warning(f"[MiLB] Skipping potentially stale live game: {game['away_team']} @ {game['home_team']} - game date: {game_date_str}, hours old: {hours_diff:.1f}")
continue
else:
self.logger.debug(f"[MiLB] Game time check passed: {game['away_team']} @ {game['home_team']} - hours old: {hours_diff:.1f}")
except Exception as e:
self.logger.warning(f"[MiLB] Could not parse game date {game_date_str}: {e}")
self.logger.debug(f"[MiLB] Found live game: {game['away_team']} @ {game['home_team']}")
if not self.favorite_teams or (
game['home_team'] in self.favorite_teams or

View File

@@ -97,6 +97,12 @@ class BaseSoccerManager:
self.config_manager = ConfigManager(config)
def _get_timezone(self):
try:
return pytz.timezone(self.config_manager.get_timezone())
except pytz.UnknownTimeZoneError:
return pytz.utc
def _fetch_odds(self, game: Dict) -> None:
"""Fetch odds for a game and attach it to the game dictionary."""
# Check if odds should be shown for this sport