mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 21:03:01 +00:00
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).
This commit is contained in:
@@ -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']}")
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 ''
|
||||
|
||||
@@ -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]:
|
||||
|
||||
Reference in New Issue
Block a user