From 8fb510cb48383ed5a46c48d7e1540de47a987d97 Mon Sep 17 00:00:00 2001 From: Chuck <33324927+ChuckBuilds@users.noreply.github.com> Date: Sun, 20 Jul 2025 18:07:55 -0500 Subject: [PATCH] filter favorite games before loading the rest for odd ticker --- src/odds_manager.py | 2 ++ src/odds_ticker_manager.py | 25 +++++++++++-------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/odds_manager.py b/src/odds_manager.py index 0867b6ef..443bd7f2 100644 --- a/src/odds_manager.py +++ b/src/odds_manager.py @@ -79,5 +79,7 @@ class OddsManager: self.logger.debug(f"Returning extracted odds data: {json.dumps(extracted_data, indent=2)}") return extracted_data + # Log the actual response structure when no items are found self.logger.warning("No 'items' found in ESPN odds data.") + self.logger.warning(f"Actual response structure: {json.dumps(data, indent=2)}") return None \ No newline at end of file diff --git a/src/odds_ticker_manager.py b/src/odds_ticker_manager.py index a3708ff7..0bca14d4 100644 --- a/src/odds_ticker_manager.py +++ b/src/odds_ticker_manager.py @@ -141,20 +141,10 @@ class OddsTickerManager: # Sort games by start time games_data.sort(key=lambda x: x.get('start_time', datetime.max)) - # Filter for favorite teams if enabled + # Filter for favorite teams if enabled (now handled in _fetch_league_games) + # This filtering is now redundant since we filter before fetching odds if self.show_favorite_teams_only: - all_favorite_teams = [] - for league_config in self.league_configs.values(): - all_favorite_teams.extend(league_config.get('favorite_teams', [])) - - logger.info(f"Filtering for favorite teams: {all_favorite_teams}") - original_count = len(games_data) - games_data = [ - game for game in games_data - if (game.get('home_team') in all_favorite_teams or - game.get('away_team') in all_favorite_teams) - ] - logger.info(f"Filtered from {original_count} to {len(games_data)} games") + logger.debug("Favorite team filtering already applied during game fetching") logger.info(f"Total games found: {len(games_data)}") return games_data @@ -201,9 +191,16 @@ class OddsTickerManager: home_abbr = home_team['team']['abbreviation'] away_abbr = away_team['team']['abbreviation'] + # Check if this game involves favorite teams BEFORE fetching odds + if self.show_favorite_teams_only: + favorite_teams = league_config.get('favorite_teams', []) + if home_abbr not in favorite_teams and away_abbr not in favorite_teams: + logger.debug(f"Skipping game {home_abbr} vs {away_abbr} - no favorite teams involved") + continue + logger.info(f"Found upcoming game: {away_abbr} @ {home_abbr} on {game_time}") - # Fetch odds for this game + # Fetch odds for this game (only if it involves favorite teams) odds_data = self.odds_manager.get_odds( sport=sport, league=league,