From 4da2fd32e2d2641d8e79d57b6216f1e1e141d0cf Mon Sep 17 00:00:00 2001 From: Chuck <33324927+ChuckBuilds@users.noreply.github.com> Date: Tue, 22 Jul 2025 09:31:14 -0500 Subject: [PATCH] change weather logging, changed odds api call to only pull odds for games we will see, expanded game fetch window to see more games on odds ticker (50days from 30). --- config/config.json | 5 +++-- src/milb_manager.py | 19 ++++++++----------- src/mlb_manager.py | 20 ++++++-------------- src/nba_managers.py | 17 +++++++++-------- src/ncaa_fb_managers.py | 18 +++++++++++++----- src/nfl_managers.py | 13 +++++++++---- src/nhl_managers.py | 8 ++++++-- src/odds_ticker_manager.py | 9 +++------ src/weather_manager.py | 12 +++++++----- 9 files changed, 64 insertions(+), 57 deletions(-) diff --git a/config/config.json b/config/config.json index 42f35ff8..f2d0bfd7 100644 --- a/config/config.json +++ b/config/config.json @@ -114,11 +114,12 @@ "max_games_per_league": 5, "show_odds_only": false, "sort_order": "soonest", - "enabled_leagues": ["nfl","mlb", "ncaa_fb"], + "enabled_leagues": ["nfl","mlb", "ncaa_fb", "milb"], "update_interval": 3600, "scroll_speed": 1, "scroll_delay": 0.01, - "loop": true + "loop": true, + "future_fetch_days": 50 }, "calendar": { "enabled": true, diff --git a/src/milb_manager.py b/src/milb_manager.py index 1fe2a48f..117122dd 100644 --- a/src/milb_manager.py +++ b/src/milb_manager.py @@ -1122,21 +1122,17 @@ class MiLBUpcomingManager(BaseMiLBManager): logger.info(f"[MiLB] Processing {len(games)} games for upcoming games...") for game_id, game in games.items(): + # Only fetch odds for games that will be displayed + if self.milb_config.get("show_favorite_teams_only", False): + if not self.favorite_teams: + continue + if game['home_team'] not in self.favorite_teams and game['away_team'] not in self.favorite_teams: + continue # Convert game time to UTC datetime game_time_str = game['start_time'].replace('Z', '+00:00') game_time = datetime.fromisoformat(game_time_str) if game_time.tzinfo is None: game_time = game_time.replace(tzinfo=timezone.utc) - - # Check if this is a favorite team game - is_favorite_game = (game['home_team'] in self.favorite_teams or - game['away_team'] in self.favorite_teams) - - if is_favorite_game: - logger.info(f"[MiLB] Checking favorite team game: {game['away_team']} @ {game['home_team']}") - logger.info(f"[MiLB] Game time (UTC): {game_time}") - logger.info(f"[MiLB] Game status: {game['status']}, State: {game['status_state']}") - # For upcoming games, we'll consider any game that: # 1. Is not final (not 'post' or 'final' state) # 2. Has a future start time @@ -1144,8 +1140,9 @@ class MiLBUpcomingManager(BaseMiLBManager): game['status_state'] not in ['post', 'final', 'completed'] and game_time > datetime.now(timezone.utc) ) - if is_upcoming: + if self.show_odds: + self._fetch_odds(game) new_upcoming_games.append(game) logger.info(f"[MiLB] Added favorite team game to upcoming list: {game['away_team']} @ {game['home_team']}") diff --git a/src/mlb_manager.py b/src/mlb_manager.py index 688e4ff2..a2280ef5 100644 --- a/src/mlb_manager.py +++ b/src/mlb_manager.py @@ -1236,32 +1236,24 @@ class MLBUpcomingManager(BaseMLBManager): for game_id, game in games.items(): self.logger.debug(f"[MLB] Processing game {game_id} for upcoming games...") - # Check if this is a favorite team game first + # Only fetch odds for games that will be displayed + if self.mlb_config.get("show_favorite_teams_only", False): + if not self.favorite_teams: + continue + if game['home_team'] not in self.favorite_teams and game['away_team'] not in self.favorite_teams: + continue is_favorite_game = (game['home_team'] in self.favorite_teams or game['away_team'] in self.favorite_teams) - - if not is_favorite_game: - self.logger.debug(f"[MLB] Skipping game {game_id} - not a favorite team.") - continue - game_time = datetime.fromisoformat(game['start_time'].replace('Z', '+00:00')) - # Ensure game_time is timezone-aware (UTC) if game_time.tzinfo is None: game_time = game_time.replace(tzinfo=timezone.utc) - self.logger.info(f"[MLB] Favorite team game found: {game['away_team']} @ {game['home_team']} at {game_time}") self.logger.info(f"[MLB] Game status: {game['status']}, State: {game['status_state']}") - - # For upcoming games, we'll consider any game that: - # 1. Is not final (not 'post' or 'final' state) - # 2. Has a future start time is_upcoming = ( game['status_state'] not in ['post', 'final', 'completed'] and game_time > datetime.now(timezone.utc) ) - self.logger.info(f"[MLB] Is upcoming: {is_upcoming}") - if is_upcoming: self.logger.info(f"[MLB] Adding game {game_id} to upcoming games list.") self._fetch_odds(game) diff --git a/src/nba_managers.py b/src/nba_managers.py index 0f8f9d9a..ef6cc14b 100644 --- a/src/nba_managers.py +++ b/src/nba_managers.py @@ -748,14 +748,15 @@ class NBALiveManager(BaseNBAManager): for event in data["events"]: details = self._extract_game_details(event) if details and details["is_live"]: - if not self.favorite_teams or ( - details["home_abbr"] in self.favorite_teams or - details["away_abbr"] in self.favorite_teams - ): - # Fetch odds if enabled - if self.show_odds: - self._fetch_odds(details) - new_live_games.append(details) + # Only fetch odds for games that will be displayed + if self.nba_config.get("show_favorite_teams_only", False): + if not self.favorite_teams: + continue + if details["home_abbr"] not in self.favorite_teams and details["away_abbr"] not in self.favorite_teams: + continue + if self.show_odds: + self._fetch_odds(details) + new_live_games.append(details) # Update game list and current game if new_live_games: diff --git a/src/ncaa_fb_managers.py b/src/ncaa_fb_managers.py index 381e8542..dffc3710 100644 --- a/src/ncaa_fb_managers.py +++ b/src/ncaa_fb_managers.py @@ -1195,11 +1195,19 @@ class NCAAFBUpcomingManager(BaseNCAAFBManager): # Renamed class game = self._extract_game_details(event) # Filter criteria: must be upcoming ('pre' state) if game and game['is_upcoming']: - processed_games.append(game) - # Count favorite team games for logging - if (game['home_abbr'] in self.favorite_teams or - game['away_abbr'] in self.favorite_teams): - favorite_games_found += 1 + # Only fetch odds for games that will be displayed + if self.ncaa_fb_config.get("show_favorite_teams_only", False): + if not self.favorite_teams: + continue + if game['home_abbr'] not in self.favorite_teams and game['away_abbr'] not in self.favorite_teams: + continue + processed_games.append(game) + # Count favorite team games for logging + if (game['home_abbr'] in self.favorite_teams or + game['away_abbr'] in self.favorite_teams): + favorite_games_found += 1 + if self.show_odds: + self._fetch_odds(game) # Summary logging instead of verbose debug self.logger.info(f"[NCAAFB Upcoming] Found {len(processed_games)} total upcoming games") diff --git a/src/nfl_managers.py b/src/nfl_managers.py index 28d53748..15acd926 100644 --- a/src/nfl_managers.py +++ b/src/nfl_managers.py @@ -1085,10 +1085,15 @@ class NFLUpcomingManager(BaseNFLManager): # Renamed class game = self._extract_game_details(event) # Filter criteria: must be upcoming ('pre' state) if game and game['is_upcoming']: - # Fetch odds if enabled - if self.show_odds: - self._fetch_odds(game) - processed_games.append(game) + # Only fetch odds for games that will be displayed + if self.nfl_config.get("show_favorite_teams_only", False): + if not self.favorite_teams: + continue + if game['home_abbr'] not in self.favorite_teams and game['away_abbr'] not in self.favorite_teams: + continue + if self.show_odds: + self._fetch_odds(game) + processed_games.append(game) # Debug logging to see what games we have self.logger.debug(f"[NFL Upcoming] Processed {len(processed_games)} upcoming games") diff --git a/src/nhl_managers.py b/src/nhl_managers.py index d9bcb275..85489092 100644 --- a/src/nhl_managers.py +++ b/src/nhl_managers.py @@ -871,9 +871,13 @@ class NHLUpcomingManager(BaseNHLManager): self.logger.debug(f"[NHL] Processing game: {game['away_abbr']} vs {game['home_abbr']}") self.logger.debug(f"[NHL] Game status: is_final={game['is_final']}, is_upcoming={game['is_upcoming']}, is_within_window={game['is_within_window']}") self.logger.debug(f"[NHL] Game time: {game['start_time_utc']}") - + # Only fetch odds for games that will be displayed + if self.nhl_config.get("show_favorite_teams_only", False): + if not self.favorite_teams: + continue + if game['home_abbr'] not in self.favorite_teams and game['away_abbr'] not in self.favorite_teams: + continue if not game['is_final'] and game['is_within_window']: - # Fetch odds if enabled if self.show_odds: self._fetch_odds(game) new_upcoming_games.append(game) diff --git a/src/odds_ticker_manager.py b/src/odds_ticker_manager.py index 77d0de45..7ed94c32 100644 --- a/src/odds_ticker_manager.py +++ b/src/odds_ticker_manager.py @@ -259,12 +259,9 @@ class OddsTickerManager: away_abbr = away_team['team']['abbreviation'] # Only process favorite teams if enabled if self.show_favorite_teams_only: - # Skip if both teams have already met their quota - for team in [home_abbr, away_abbr]: - if team in team_games_found and team_games_found[team] >= max_games: - continue - # Only add if at least one team still needs games - if not ((home_abbr in team_games_found and team_games_found[home_abbr] < max_games) or (away_abbr in team_games_found and team_games_found[away_abbr] < max_games)): + if not favorite_teams: + continue + if home_abbr not in favorite_teams and away_abbr not in favorite_teams: continue # Build game dict (existing logic) home_record = home_team.get('records', [{}])[0].get('summary', '') if home_team.get('records') else '' diff --git a/src/weather_manager.py b/src/weather_manager.py index dea669be..af1ca555 100644 --- a/src/weather_manager.py +++ b/src/weather_manager.py @@ -202,19 +202,21 @@ class WeatherManager: """Get current weather data, fetching new data if needed.""" current_time = time.time() update_interval = self.weather_config.get('update_interval', 300) - + # Add a throttle for log spam + log_throttle_interval = 600 # 10 minutes + if not hasattr(self, '_last_weather_log_time'): + self._last_weather_log_time = 0 # Check if we need to update based on time or if we have no data if (not self.weather_data or current_time - self.last_update > update_interval): - # Check if data has changed before fetching current_state = self._get_weather_state() if current_state and not self.cache_manager.has_data_changed('weather', current_state): - print("Weather data hasn't changed, using existing data") + if current_time - self._last_weather_log_time > log_throttle_interval: + print("Weather data hasn't changed, using existing data") + self._last_weather_log_time = current_time return self.weather_data - self._fetch_weather() - return self.weather_data def _get_weather_state(self) -> Dict[str, Any]: