improve filtering on show_favorite_teams_only

This commit is contained in:
ChuckBuilds
2025-08-15 10:14:33 -05:00
parent e3b65588a2
commit a5ce721733
2 changed files with 26 additions and 24 deletions

View File

@@ -809,31 +809,28 @@ class MLBLiveManager(BaseMLBManager):
} }
self.logger.info(f"[MLB Live] Filtered to {len(games)} games for favorite teams.") self.logger.info(f"[MLB Live] Filtered to {len(games)} games for favorite teams.")
# Find all live games involving favorite teams # Find all live games
new_live_games = [] new_live_games = []
for game in games.values(): for game in games.values():
# Only process games that are actually in progress # Only process games that are actually in progress
if game['status_state'] == 'in' and game['status'] == 'status_in_progress': if game['status_state'] == 'in' and game['status'] == 'status_in_progress':
if not self.favorite_teams or ( # Check if this is a favorite team game
game['home_team'] in self.favorite_teams or is_favorite_game = (game['home_team'] in self.favorite_teams or
game['away_team'] in self.favorite_teams game['away_team'] in self.favorite_teams)
):
self._fetch_odds(game) # Only filter by favorite teams if show_favorite_teams_only is True
# Ensure scores are valid numbers if self.mlb_config.get("show_favorite_teams_only", False) and not is_favorite_game:
try: self.logger.debug(f"[MLB Live] Skipping game {game['away_team']} @ {game['home_team']} - not a favorite team.")
game['home_score'] = int(game['home_score']) continue
game['away_score'] = int(game['away_score'])
new_live_games.append(game) self._fetch_odds(game)
except (ValueError, TypeError): # Ensure scores are valid numbers
self.logger.warning(f"Invalid score format for game {game['away_team']} @ {game['home_team']}") try:
else: game['home_score'] = int(game['home_score'])
# Not in favorites-only mode, so add the game game['away_score'] = int(game['away_score'])
try: new_live_games.append(game)
game['home_score'] = int(game['home_score']) except (ValueError, TypeError):
game['away_score'] = int(game['away_score']) self.logger.warning(f"Invalid score format for game {game['away_team']} @ {game['home_team']}")
new_live_games.append(game)
except (ValueError, TypeError):
self.logger.warning(f"Invalid score format for game {game['away_team']} @ {game['home_team']}")
# Only log if there's a change in games or enough time has passed # Only log if there's a change in games or enough time has passed
should_log = ( should_log = (
@@ -1201,7 +1198,8 @@ class MLBRecentManager(BaseMLBManager):
self.logger.info(f"[MLB] Game time (UTC): {game_time}") self.logger.info(f"[MLB] Game time (UTC): {game_time}")
self.logger.info(f"[MLB] Game status: {game['status']}, State: {game['status_state']}") self.logger.info(f"[MLB] Game status: {game['status']}, State: {game['status_state']}")
if not is_favorite_game: # Only filter by favorite teams if show_favorite_teams_only is True
if self.mlb_config.get("show_favorite_teams_only", False) and not is_favorite_game:
self.logger.debug(f"[MLB] Skipping game {game_id} - not a favorite team.") self.logger.debug(f"[MLB] Skipping game {game_id} - not a favorite team.")
continue continue

View File

@@ -887,7 +887,9 @@ class NCAABaseballRecentManager(BaseNCAABaseballManager):
if game_time.tzinfo is None: game_time = game_time.replace(tzinfo=timezone.utc) if game_time.tzinfo is None: game_time = game_time.replace(tzinfo=timezone.utc)
is_favorite_game = (game['home_team'] in self.favorite_teams or game['away_team'] in self.favorite_teams) is_favorite_game = (game['home_team'] in self.favorite_teams or game['away_team'] in self.favorite_teams)
if not is_favorite_game: continue # Only filter by favorite teams if show_favorite_teams_only is True
if self.ncaa_baseball_config.get("show_favorite_teams_only", False) and not is_favorite_game:
continue
logger.info(f"[NCAABaseball] Checking favorite recent game: {game['away_team']} @ {game['home_team']}") logger.info(f"[NCAABaseball] Checking favorite recent game: {game['away_team']} @ {game['home_team']}")
logger.info(f"[NCAABaseball] Game time (UTC): {game_time}") logger.info(f"[NCAABaseball] Game time (UTC): {game_time}")
@@ -983,7 +985,9 @@ class NCAABaseballUpcomingManager(BaseNCAABaseballManager):
for game in games.values(): for game in games.values():
is_favorite_game = (game['home_team'] in self.favorite_teams or game['away_team'] in self.favorite_teams) is_favorite_game = (game['home_team'] in self.favorite_teams or game['away_team'] in self.favorite_teams)
if not is_favorite_game: continue # Only filter by favorite teams if show_favorite_teams_only is True
if self.ncaa_baseball_config.get("show_favorite_teams_only", False) and not is_favorite_game:
continue
game_time = datetime.fromisoformat(game['start_time'].replace('Z', '+00:00')) game_time = datetime.fromisoformat(game['start_time'].replace('Z', '+00:00'))
if game_time.tzinfo is None: game_time = game_time.replace(tzinfo=timezone.utc) if game_time.tzinfo is None: game_time = game_time.replace(tzinfo=timezone.utc)