mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 21:03:01 +00:00
update logic on all sports displays that upcoming and recent games to show are based on each team, not just the first X # of games found
This commit is contained in:
@@ -1502,9 +1502,28 @@ class MiLBRecentManager(BaseMiLBManager):
|
|||||||
logger.info(f"[MiLB] All games found ({len(all_games_log)}): {all_games_log}")
|
logger.info(f"[MiLB] All games found ({len(all_games_log)}): {all_games_log}")
|
||||||
logger.info(f"[MiLB] Favorite team games found ({len(favorite_games_log)}): {favorite_games_log}")
|
logger.info(f"[MiLB] Favorite team games found ({len(favorite_games_log)}): {favorite_games_log}")
|
||||||
|
|
||||||
# Sort by game time (most recent first) and limit to recent_games_to_show
|
# Sort by game time (most recent first) and apply per-team logic
|
||||||
new_recent_games.sort(key=lambda x: x.get('start_time', ''), reverse=True)
|
new_recent_games.sort(key=lambda x: x.get('start_time', ''), reverse=True)
|
||||||
new_recent_games = new_recent_games[:self.recent_games_to_show]
|
|
||||||
|
# If showing favorite teams only, select one game per team
|
||||||
|
if self.milb_config.get("show_favorite_teams_only", False):
|
||||||
|
# Select one game per favorite team (most recent game for each team)
|
||||||
|
team_games = []
|
||||||
|
for team in self.favorite_teams:
|
||||||
|
# Find games where this team is playing
|
||||||
|
team_specific_games = [game for game in new_recent_games
|
||||||
|
if game.get('home_team') == team or game.get('away_team') == team]
|
||||||
|
|
||||||
|
if team_specific_games:
|
||||||
|
# Take the most recent (first in sorted list)
|
||||||
|
team_games.append(team_specific_games[0])
|
||||||
|
|
||||||
|
# Sort the final list by game time (most recent first)
|
||||||
|
team_games.sort(key=lambda x: x.get('start_time', ''), reverse=True)
|
||||||
|
new_recent_games = team_games
|
||||||
|
else:
|
||||||
|
# Limit to configured number if not using favorite teams only
|
||||||
|
new_recent_games = new_recent_games[:self.recent_games_to_show]
|
||||||
|
|
||||||
if new_recent_games:
|
if new_recent_games:
|
||||||
logger.info(f"[MiLB] Found {len(new_recent_games)} recent final games for favorite teams: {self.favorite_teams}")
|
logger.info(f"[MiLB] Found {len(new_recent_games)} recent final games for favorite teams: {self.favorite_teams}")
|
||||||
@@ -1716,9 +1735,28 @@ class MiLBUpcomingManager(BaseMiLBManager):
|
|||||||
self.logger.info(f"[MiLB] Added upcoming game: {game.get('away_team')} @ {game.get('home_team')} at {game_time}")
|
self.logger.info(f"[MiLB] Added upcoming game: {game.get('away_team')} @ {game.get('home_team')} at {game_time}")
|
||||||
self.logger.debug(f"[MiLB] Game data for upcoming: {game}")
|
self.logger.debug(f"[MiLB] Game data for upcoming: {game}")
|
||||||
|
|
||||||
# Sort by game time (soonest first) and limit to upcoming_games_to_show
|
# Sort by game time (soonest first) and apply per-team logic
|
||||||
new_upcoming_games.sort(key=lambda x: x.get('start_time', ''))
|
new_upcoming_games.sort(key=lambda x: x.get('start_time', ''))
|
||||||
new_upcoming_games = new_upcoming_games[:self.upcoming_games_to_show]
|
|
||||||
|
# If showing favorite teams only, select one game per team
|
||||||
|
if self.milb_config.get("show_favorite_teams_only", False):
|
||||||
|
# Select one game per favorite team (earliest upcoming game for each team)
|
||||||
|
team_games = []
|
||||||
|
for team in self.favorite_teams:
|
||||||
|
# Find games where this team is playing
|
||||||
|
team_specific_games = [game for game in new_upcoming_games
|
||||||
|
if game.get('home_team') == team or game.get('away_team') == team]
|
||||||
|
|
||||||
|
if team_specific_games:
|
||||||
|
# Take the earliest (first in sorted list)
|
||||||
|
team_games.append(team_specific_games[0])
|
||||||
|
|
||||||
|
# Sort the final list by game time
|
||||||
|
team_games.sort(key=lambda x: x.get('start_time', ''))
|
||||||
|
new_upcoming_games = team_games
|
||||||
|
else:
|
||||||
|
# Limit to configured number if not using favorite teams only
|
||||||
|
new_upcoming_games = new_upcoming_games[:self.upcoming_games_to_show]
|
||||||
self.logger.info(f"[MiLB] Found {len(new_upcoming_games)} upcoming games after processing")
|
self.logger.info(f"[MiLB] Found {len(new_upcoming_games)} upcoming games after processing")
|
||||||
|
|
||||||
# Compare new list with old list to see if an update is needed
|
# Compare new list with old list to see if an update is needed
|
||||||
|
|||||||
@@ -1223,9 +1223,28 @@ class MLBRecentManager(BaseMLBManager):
|
|||||||
self.logger.info(f"[MLB] All games found ({len(all_games_log)}): {all_games_log}")
|
self.logger.info(f"[MLB] All games found ({len(all_games_log)}): {all_games_log}")
|
||||||
self.logger.info(f"[MLB] Favorite team games found ({len(favorite_games_log)}): {favorite_games_log}")
|
self.logger.info(f"[MLB] Favorite team games found ({len(favorite_games_log)}): {favorite_games_log}")
|
||||||
|
|
||||||
# Sort by game time (most recent first) and limit to recent_games_to_show
|
# Sort by game time (most recent first) and apply per-team logic
|
||||||
new_recent_games.sort(key=lambda x: x['start_time'], reverse=True)
|
new_recent_games.sort(key=lambda x: x['start_time'], reverse=True)
|
||||||
new_recent_games = new_recent_games[:self.recent_games_to_show]
|
|
||||||
|
# If showing favorite teams only, select one game per team
|
||||||
|
if self.mlb_config.get("show_favorite_teams_only", False):
|
||||||
|
# Select one game per favorite team (most recent game for each team)
|
||||||
|
team_games = []
|
||||||
|
for team in self.favorite_teams:
|
||||||
|
# Find games where this team is playing
|
||||||
|
team_specific_games = [game for game in new_recent_games
|
||||||
|
if game['home_team'] == team or game['away_team'] == team]
|
||||||
|
|
||||||
|
if team_specific_games:
|
||||||
|
# Take the most recent (first in sorted list)
|
||||||
|
team_games.append(team_specific_games[0])
|
||||||
|
|
||||||
|
# Sort the final list by game time (most recent first)
|
||||||
|
team_games.sort(key=lambda x: x['start_time'], reverse=True)
|
||||||
|
new_recent_games = team_games
|
||||||
|
else:
|
||||||
|
# Limit to configured number if not using favorite teams only
|
||||||
|
new_recent_games = new_recent_games[:self.recent_games_to_show]
|
||||||
|
|
||||||
if new_recent_games:
|
if new_recent_games:
|
||||||
logger.info(f"[MLB] Found {len(new_recent_games)} recent games for favorite teams: {self.favorite_teams}")
|
logger.info(f"[MLB] Found {len(new_recent_games)} recent games for favorite teams: {self.favorite_teams}")
|
||||||
@@ -1345,9 +1364,28 @@ class MLBUpcomingManager(BaseMLBManager):
|
|||||||
else:
|
else:
|
||||||
self.logger.info(f"[MLB] Skipping game {game_id} - not upcoming.")
|
self.logger.info(f"[MLB] Skipping game {game_id} - not upcoming.")
|
||||||
|
|
||||||
# Sort by game time (soonest first) and limit to upcoming_games_to_show
|
# Sort by game time (soonest first) and apply per-team logic
|
||||||
new_upcoming_games.sort(key=lambda x: x['start_time'])
|
new_upcoming_games.sort(key=lambda x: x['start_time'])
|
||||||
new_upcoming_games = new_upcoming_games[:self.upcoming_games_to_show]
|
|
||||||
|
# If showing favorite teams only, select one game per team
|
||||||
|
if self.mlb_config.get("show_favorite_teams_only", False):
|
||||||
|
# Select one game per favorite team (earliest upcoming game for each team)
|
||||||
|
team_games = []
|
||||||
|
for team in self.favorite_teams:
|
||||||
|
# Find games where this team is playing
|
||||||
|
team_specific_games = [game for game in new_upcoming_games
|
||||||
|
if game['home_team'] == team or game['away_team'] == team]
|
||||||
|
|
||||||
|
if team_specific_games:
|
||||||
|
# Take the earliest (first in sorted list)
|
||||||
|
team_games.append(team_specific_games[0])
|
||||||
|
|
||||||
|
# Sort the final list by game time
|
||||||
|
team_games.sort(key=lambda x: x['start_time'])
|
||||||
|
new_upcoming_games = team_games
|
||||||
|
else:
|
||||||
|
# Limit to configured number if not using favorite teams only
|
||||||
|
new_upcoming_games = new_upcoming_games[:self.upcoming_games_to_show]
|
||||||
|
|
||||||
if new_upcoming_games:
|
if new_upcoming_games:
|
||||||
logger.info(f"[MLB] Found {len(new_upcoming_games)} upcoming games for favorite teams")
|
logger.info(f"[MLB] Found {len(new_upcoming_games)} upcoming games for favorite teams")
|
||||||
|
|||||||
@@ -759,15 +759,30 @@ class NBARecentManager(BaseNBAManager):
|
|||||||
|
|
||||||
# Filter for favorite teams only if the config is set
|
# Filter for favorite teams only if the config is set
|
||||||
if self.nba_config.get("show_favorite_teams_only", False):
|
if self.nba_config.get("show_favorite_teams_only", False):
|
||||||
team_games = [game for game in new_recent_games
|
# Get all games involving favorite teams
|
||||||
if game['home_abbr'] in self.favorite_teams or
|
favorite_team_games = [game for game in new_recent_games
|
||||||
game['away_abbr'] in self.favorite_teams]
|
if game['home_abbr'] in self.favorite_teams or
|
||||||
|
game['away_abbr'] in self.favorite_teams]
|
||||||
|
|
||||||
|
# Select one game per favorite team (most recent game for each team)
|
||||||
|
team_games = []
|
||||||
|
for team in self.favorite_teams:
|
||||||
|
# Find games where this team is playing
|
||||||
|
team_specific_games = [game for game in favorite_team_games
|
||||||
|
if game['home_abbr'] == team or game['away_abbr'] == team]
|
||||||
|
|
||||||
|
if team_specific_games:
|
||||||
|
# Sort by game time and take the most recent
|
||||||
|
team_specific_games.sort(key=lambda g: g.get('start_time_utc') or datetime.min.replace(tzinfo=timezone.utc), reverse=True)
|
||||||
|
team_games.append(team_specific_games[0])
|
||||||
|
|
||||||
|
# Sort the final list by game time (most recent first)
|
||||||
|
team_games.sort(key=lambda g: g.get('start_time_utc') or datetime.min.replace(tzinfo=timezone.utc), reverse=True)
|
||||||
else:
|
else:
|
||||||
team_games = new_recent_games
|
team_games = new_recent_games
|
||||||
|
# Sort games by start time, most recent first, then limit to recent_games_to_show
|
||||||
# Sort games by start time, most recent first, then limit to recent_games_to_show
|
team_games.sort(key=lambda x: x.get('start_time_utc') or datetime.min.replace(tzinfo=timezone.utc), reverse=True)
|
||||||
team_games.sort(key=lambda x: x.get('start_time_utc') or datetime.min.replace(tzinfo=timezone.utc), reverse=True)
|
team_games = team_games[:self.recent_games_to_show]
|
||||||
team_games = team_games[:self.recent_games_to_show]
|
|
||||||
self.recent_games = team_games
|
self.recent_games = team_games
|
||||||
|
|
||||||
if self.recent_games:
|
if self.recent_games:
|
||||||
@@ -838,15 +853,30 @@ class NBAUpcomingManager(BaseNBAManager):
|
|||||||
|
|
||||||
# Filter for favorite teams only if the config is set
|
# Filter for favorite teams only if the config is set
|
||||||
if self.nba_config.get("show_favorite_teams_only", False):
|
if self.nba_config.get("show_favorite_teams_only", False):
|
||||||
team_games = [game for game in new_upcoming_games
|
# Get all games involving favorite teams
|
||||||
if game['home_abbr'] in self.favorite_teams or
|
favorite_team_games = [game for game in new_upcoming_games
|
||||||
game['away_abbr'] in self.favorite_teams]
|
if game['home_abbr'] in self.favorite_teams or
|
||||||
|
game['away_abbr'] in self.favorite_teams]
|
||||||
|
|
||||||
|
# Select one game per favorite team (earliest upcoming game for each team)
|
||||||
|
team_games = []
|
||||||
|
for team in self.favorite_teams:
|
||||||
|
# Find games where this team is playing
|
||||||
|
team_specific_games = [game for game in favorite_team_games
|
||||||
|
if game['home_abbr'] == team or game['away_abbr'] == team]
|
||||||
|
|
||||||
|
if team_specific_games:
|
||||||
|
# Sort by game time and take the earliest
|
||||||
|
team_specific_games.sort(key=lambda g: g.get('start_time_utc') or datetime.max.replace(tzinfo=timezone.utc))
|
||||||
|
team_games.append(team_specific_games[0])
|
||||||
|
|
||||||
|
# Sort the final list by game time
|
||||||
|
team_games.sort(key=lambda g: g.get('start_time_utc') or datetime.max.replace(tzinfo=timezone.utc))
|
||||||
else:
|
else:
|
||||||
team_games = new_upcoming_games
|
team_games = new_upcoming_games
|
||||||
|
# Sort games by start time, soonest first, then limit to configured count
|
||||||
# Sort games by start time, soonest first, then limit to configured count
|
team_games.sort(key=lambda x: x.get('start_time_utc') or datetime.max.replace(tzinfo=timezone.utc))
|
||||||
team_games.sort(key=lambda x: x.get('start_time_utc') or datetime.max.replace(tzinfo=timezone.utc))
|
team_games = team_games[:self.upcoming_games_to_show]
|
||||||
team_games = team_games[:self.upcoming_games_to_show]
|
|
||||||
self.upcoming_games = team_games
|
self.upcoming_games = team_games
|
||||||
|
|
||||||
if self.upcoming_games:
|
if self.upcoming_games:
|
||||||
|
|||||||
@@ -908,14 +908,32 @@ class NCAABaseballRecentManager(BaseNCAABaseballManager):
|
|||||||
|
|
||||||
# Filter for favorite teams only if the config is set
|
# Filter for favorite teams only if the config is set
|
||||||
if self.ncaa_baseball_config.get("show_favorite_teams_only", False):
|
if self.ncaa_baseball_config.get("show_favorite_teams_only", False):
|
||||||
team_games = [game for game in new_recent_games if game['home_team'] in self.favorite_teams or game['away_team'] in self.favorite_teams]
|
# Get all games involving favorite teams
|
||||||
|
favorite_team_games = [game for game in new_recent_games
|
||||||
|
if game['home_team'] in self.favorite_teams or
|
||||||
|
game['away_team'] in self.favorite_teams]
|
||||||
|
|
||||||
|
# Select one game per favorite team (most recent game for each team)
|
||||||
|
team_games = []
|
||||||
|
for team in self.favorite_teams:
|
||||||
|
# Find games where this team is playing
|
||||||
|
team_specific_games = [game for game in favorite_team_games
|
||||||
|
if game['home_team'] == team or game['away_team'] == team]
|
||||||
|
|
||||||
|
if team_specific_games:
|
||||||
|
# Sort by game time and take the most recent
|
||||||
|
team_specific_games.sort(key=lambda g: g.get('start_time'), reverse=True)
|
||||||
|
team_games.append(team_specific_games[0])
|
||||||
|
|
||||||
|
# Sort the final list by game time (most recent first)
|
||||||
|
team_games.sort(key=lambda g: g.get('start_time'), reverse=True)
|
||||||
else:
|
else:
|
||||||
team_games = new_recent_games
|
team_games = new_recent_games
|
||||||
|
|
||||||
if team_games:
|
|
||||||
# Sort by game time (most recent first), then limit to recent_games_to_show
|
# Sort by game time (most recent first), then limit to recent_games_to_show
|
||||||
team_games = sorted(team_games, key=lambda g: g.get('start_time'), reverse=True)
|
team_games = sorted(team_games, key=lambda g: g.get('start_time'), reverse=True)
|
||||||
team_games = team_games[:self.recent_games_to_show]
|
team_games = team_games[:self.recent_games_to_show]
|
||||||
|
|
||||||
|
if team_games:
|
||||||
logger.info(f"[NCAABaseball] Found {len(team_games)} recent games for favorite teams (limited to {self.recent_games_to_show}): {self.favorite_teams}")
|
logger.info(f"[NCAABaseball] Found {len(team_games)} recent games for favorite teams (limited to {self.recent_games_to_show}): {self.favorite_teams}")
|
||||||
self.recent_games = team_games
|
self.recent_games = team_games
|
||||||
if not self.current_game or self.current_game.get('id') not in [g.get('id') for g in self.recent_games]:
|
if not self.current_game or self.current_game.get('id') not in [g.get('id') for g in self.recent_games]:
|
||||||
@@ -1010,14 +1028,32 @@ class NCAABaseballUpcomingManager(BaseNCAABaseballManager):
|
|||||||
|
|
||||||
# Filter for favorite teams only if the config is set
|
# Filter for favorite teams only if the config is set
|
||||||
if self.ncaa_baseball_config.get("show_favorite_teams_only", False):
|
if self.ncaa_baseball_config.get("show_favorite_teams_only", False):
|
||||||
team_games = [game for game in new_upcoming_games if game['home_team'] in self.favorite_teams or game['away_team'] in self.favorite_teams]
|
# Get all games involving favorite teams
|
||||||
|
favorite_team_games = [game for game in new_upcoming_games
|
||||||
|
if game['home_team'] in self.favorite_teams or
|
||||||
|
game['away_team'] in self.favorite_teams]
|
||||||
|
|
||||||
|
# Select one game per favorite team (earliest upcoming game for each team)
|
||||||
|
team_games = []
|
||||||
|
for team in self.favorite_teams:
|
||||||
|
# Find games where this team is playing
|
||||||
|
team_specific_games = [game for game in favorite_team_games
|
||||||
|
if game['home_team'] == team or game['away_team'] == team]
|
||||||
|
|
||||||
|
if team_specific_games:
|
||||||
|
# Sort by game time and take the earliest
|
||||||
|
team_specific_games.sort(key=lambda g: g.get('start_time'))
|
||||||
|
team_games.append(team_specific_games[0])
|
||||||
|
|
||||||
|
# Sort the final list by game time
|
||||||
|
team_games.sort(key=lambda g: g.get('start_time'))
|
||||||
else:
|
else:
|
||||||
team_games = new_upcoming_games
|
team_games = new_upcoming_games
|
||||||
|
|
||||||
if team_games:
|
|
||||||
# Sort by game time (soonest first), then limit to configured count
|
# Sort by game time (soonest first), then limit to configured count
|
||||||
team_games = sorted(team_games, key=lambda g: g.get('start_time'))
|
team_games = sorted(team_games, key=lambda g: g.get('start_time'))
|
||||||
team_games = team_games[:self.upcoming_games_to_show]
|
team_games = team_games[:self.upcoming_games_to_show]
|
||||||
|
|
||||||
|
if team_games:
|
||||||
logger.info(f"[NCAABaseball] Found {len(team_games)} upcoming games for favorite teams (limited to {self.upcoming_games_to_show})")
|
logger.info(f"[NCAABaseball] Found {len(team_games)} upcoming games for favorite teams (limited to {self.upcoming_games_to_show})")
|
||||||
self.upcoming_games = team_games
|
self.upcoming_games = team_games
|
||||||
if not self.current_game or self.current_game.get('id') not in [g.get('id') for g in self.upcoming_games]:
|
if not self.current_game or self.current_game.get('id') not in [g.get('id') for g in self.upcoming_games]:
|
||||||
|
|||||||
@@ -828,15 +828,30 @@ class NCAAMBasketballRecentManager(BaseNCAAMBasketballManager):
|
|||||||
|
|
||||||
# Filter for favorite teams only if the config is set
|
# Filter for favorite teams only if the config is set
|
||||||
if self.ncaam_basketball_config.get("show_favorite_teams_only", False):
|
if self.ncaam_basketball_config.get("show_favorite_teams_only", False):
|
||||||
new_team_games = [game for game in new_recent_games
|
# Get all games involving favorite teams
|
||||||
if game['home_abbr'] in self.favorite_teams or
|
favorite_team_games = [game for game in new_recent_games
|
||||||
game['away_abbr'] in self.favorite_teams]
|
if game['home_abbr'] in self.favorite_teams or
|
||||||
|
game['away_abbr'] in self.favorite_teams]
|
||||||
|
|
||||||
|
# Select one game per favorite team (most recent game for each team)
|
||||||
|
new_team_games = []
|
||||||
|
for team in self.favorite_teams:
|
||||||
|
# Find games where this team is playing
|
||||||
|
team_specific_games = [game for game in favorite_team_games
|
||||||
|
if game['home_abbr'] == team or game['away_abbr'] == team]
|
||||||
|
|
||||||
|
if team_specific_games:
|
||||||
|
# Sort by game time and take the most recent
|
||||||
|
team_specific_games.sort(key=lambda g: g.get('start_time_utc', datetime.min.replace(tzinfo=timezone.utc)), reverse=True)
|
||||||
|
new_team_games.append(team_specific_games[0])
|
||||||
|
|
||||||
|
# Sort the final list by game time (most recent first)
|
||||||
|
new_team_games.sort(key=lambda g: g.get('start_time_utc', datetime.min.replace(tzinfo=timezone.utc)), reverse=True)
|
||||||
else:
|
else:
|
||||||
new_team_games = new_recent_games
|
new_team_games = new_recent_games
|
||||||
|
# Sort by game time (most recent first), then limit to recent_games_to_show
|
||||||
# Sort by game time (most recent first), then limit to recent_games_to_show
|
new_team_games.sort(key=lambda g: g.get('start_time_utc', datetime.min.replace(tzinfo=timezone.utc)), reverse=True)
|
||||||
new_team_games.sort(key=lambda g: g.get('start_time_utc', datetime.min.replace(tzinfo=timezone.utc)), reverse=True)
|
new_team_games = new_team_games[:self.recent_games_to_show]
|
||||||
new_team_games = new_team_games[:self.recent_games_to_show]
|
|
||||||
|
|
||||||
# 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 = (
|
||||||
@@ -964,15 +979,30 @@ class NCAAMBasketballUpcomingManager(BaseNCAAMBasketballManager):
|
|||||||
|
|
||||||
# Filter for favorite teams only if the config is set
|
# Filter for favorite teams only if the config is set
|
||||||
if self.ncaam_basketball_config.get("show_favorite_teams_only", False):
|
if self.ncaam_basketball_config.get("show_favorite_teams_only", False):
|
||||||
team_games = [game for game in new_upcoming_games
|
# Get all games involving favorite teams
|
||||||
if game['home_abbr'] in self.favorite_teams or
|
favorite_team_games = [game for game in new_upcoming_games
|
||||||
game['away_abbr'] in self.favorite_teams]
|
if game['home_abbr'] in self.favorite_teams or
|
||||||
|
game['away_abbr'] in self.favorite_teams]
|
||||||
|
|
||||||
|
# Select one game per favorite team (earliest upcoming game for each team)
|
||||||
|
team_games = []
|
||||||
|
for team in self.favorite_teams:
|
||||||
|
# Find games where this team is playing
|
||||||
|
team_specific_games = [game for game in favorite_team_games
|
||||||
|
if game['home_abbr'] == team or game['away_abbr'] == team]
|
||||||
|
|
||||||
|
if team_specific_games:
|
||||||
|
# Sort by game time and take the earliest
|
||||||
|
team_specific_games.sort(key=lambda g: g.get('start_time_utc', datetime.max.replace(tzinfo=timezone.utc)))
|
||||||
|
team_games.append(team_specific_games[0])
|
||||||
|
|
||||||
|
# Sort the final list by game time
|
||||||
|
team_games.sort(key=lambda g: g.get('start_time_utc', datetime.max.replace(tzinfo=timezone.utc)))
|
||||||
else:
|
else:
|
||||||
team_games = new_upcoming_games
|
team_games = new_upcoming_games
|
||||||
|
# Sort by game time (soonest first), then limit to configured count
|
||||||
# Sort by game time (soonest first), then limit to configured count
|
team_games.sort(key=lambda g: g.get('start_time_utc', datetime.max.replace(tzinfo=timezone.utc)))
|
||||||
team_games.sort(key=lambda g: g.get('start_time_utc', datetime.max.replace(tzinfo=timezone.utc)))
|
team_games = team_games[:self.upcoming_games_to_show]
|
||||||
team_games = team_games[:self.upcoming_games_to_show]
|
|
||||||
|
|
||||||
|
|
||||||
if self._should_log("team_games_upcoming", 300):
|
if self._should_log("team_games_upcoming", 300):
|
||||||
|
|||||||
@@ -700,15 +700,30 @@ class NHLRecentManager(BaseNHLManager):
|
|||||||
|
|
||||||
# Filter for favorite teams only if the config is set
|
# Filter for favorite teams only if the config is set
|
||||||
if self.nhl_config.get("show_favorite_teams_only", False):
|
if self.nhl_config.get("show_favorite_teams_only", False):
|
||||||
team_games = [game for game in processed_games
|
# Get all games involving favorite teams
|
||||||
if game['home_abbr'] in self.favorite_teams or
|
favorite_team_games = [game for game in processed_games
|
||||||
game['away_abbr'] in self.favorite_teams]
|
if game['home_abbr'] in self.favorite_teams or
|
||||||
|
game['away_abbr'] in self.favorite_teams]
|
||||||
|
|
||||||
|
# Select one game per favorite team (most recent game for each team)
|
||||||
|
team_games = []
|
||||||
|
for team in self.favorite_teams:
|
||||||
|
# Find games where this team is playing
|
||||||
|
team_specific_games = [game for game in favorite_team_games
|
||||||
|
if game['home_abbr'] == team or game['away_abbr'] == team]
|
||||||
|
|
||||||
|
if team_specific_games:
|
||||||
|
# Sort by game time and take the most recent
|
||||||
|
team_specific_games.sort(key=lambda g: g.get('start_time_utc') or datetime.min.replace(tzinfo=timezone.utc), reverse=True)
|
||||||
|
team_games.append(team_specific_games[0])
|
||||||
|
|
||||||
|
# Sort the final list by game time (most recent first)
|
||||||
|
team_games.sort(key=lambda g: g.get('start_time_utc') or datetime.min.replace(tzinfo=timezone.utc), reverse=True)
|
||||||
else:
|
else:
|
||||||
team_games = processed_games
|
team_games = processed_games
|
||||||
|
# Sort games by start time, most recent first, then limit to recent_games_to_show
|
||||||
# Sort games by start time, most recent first, then limit to recent_games_to_show
|
team_games.sort(key=lambda x: x.get('start_time_utc') or datetime.min.replace(tzinfo=timezone.utc), reverse=True)
|
||||||
team_games.sort(key=lambda x: x.get('start_time_utc') or datetime.min.replace(tzinfo=timezone.utc), reverse=True)
|
team_games = team_games[:self.recent_games_to_show]
|
||||||
team_games = team_games[:self.recent_games_to_show]
|
|
||||||
|
|
||||||
self.logger.info(f"[NHL] Found {len(team_games)} recent games for favorite teams (limited to {self.recent_games_to_show})")
|
self.logger.info(f"[NHL] Found {len(team_games)} recent games for favorite teams (limited to {self.recent_games_to_show})")
|
||||||
|
|
||||||
@@ -805,15 +820,30 @@ class NHLUpcomingManager(BaseNHLManager):
|
|||||||
|
|
||||||
# Filter for favorite teams only if the config is set
|
# Filter for favorite teams only if the config is set
|
||||||
if self.nhl_config.get("show_favorite_teams_only", False):
|
if self.nhl_config.get("show_favorite_teams_only", False):
|
||||||
team_games = [game for game in new_upcoming_games
|
# Get all games involving favorite teams
|
||||||
if game['home_abbr'] in self.favorite_teams or
|
favorite_team_games = [game for game in new_upcoming_games
|
||||||
game['away_abbr'] in self.favorite_teams]
|
if game['home_abbr'] in self.favorite_teams or
|
||||||
|
game['away_abbr'] in self.favorite_teams]
|
||||||
|
|
||||||
|
# Select one game per favorite team (earliest upcoming game for each team)
|
||||||
|
team_games = []
|
||||||
|
for team in self.favorite_teams:
|
||||||
|
# Find games where this team is playing
|
||||||
|
team_specific_games = [game for game in favorite_team_games
|
||||||
|
if game['home_abbr'] == team or game['away_abbr'] == team]
|
||||||
|
|
||||||
|
if team_specific_games:
|
||||||
|
# Sort by game time and take the earliest
|
||||||
|
team_specific_games.sort(key=lambda g: g.get('start_time_utc') or datetime.max.replace(tzinfo=timezone.utc))
|
||||||
|
team_games.append(team_specific_games[0])
|
||||||
|
|
||||||
|
# Sort the final list by game time
|
||||||
|
team_games.sort(key=lambda g: g.get('start_time_utc') or datetime.max.replace(tzinfo=timezone.utc))
|
||||||
else:
|
else:
|
||||||
team_games = new_upcoming_games
|
team_games = new_upcoming_games
|
||||||
|
# Sort games by start time, soonest first, then limit to configured count
|
||||||
# Sort games by start time, soonest first, then limit to configured count
|
team_games.sort(key=lambda x: x.get('start_time_utc') or datetime.max.replace(tzinfo=timezone.utc))
|
||||||
team_games.sort(key=lambda x: x.get('start_time_utc') or datetime.max.replace(tzinfo=timezone.utc))
|
team_games = team_games[:self.upcoming_games_to_show]
|
||||||
team_games = team_games[:self.upcoming_games_to_show]
|
|
||||||
|
|
||||||
# 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 = (
|
||||||
|
|||||||
@@ -971,13 +971,30 @@ class SoccerRecentManager(BaseSoccerManager):
|
|||||||
|
|
||||||
# Filter for favorite teams only if the config is set
|
# Filter for favorite teams only if the config is set
|
||||||
if self.soccer_config.get("show_favorite_teams_only", False):
|
if self.soccer_config.get("show_favorite_teams_only", False):
|
||||||
team_games = [game for game in new_recent_games if game['home_abbr'] in self.favorite_teams or game['away_abbr'] in self.favorite_teams]
|
# Get all games involving favorite teams
|
||||||
|
favorite_team_games = [game for game in new_recent_games
|
||||||
|
if game['home_abbr'] in self.favorite_teams or
|
||||||
|
game['away_abbr'] in self.favorite_teams]
|
||||||
|
|
||||||
|
# Select one game per favorite team (most recent game for each team)
|
||||||
|
team_games = []
|
||||||
|
for team in self.favorite_teams:
|
||||||
|
# Find games where this team is playing
|
||||||
|
team_specific_games = [game for game in favorite_team_games
|
||||||
|
if game['home_abbr'] == team or game['away_abbr'] == team]
|
||||||
|
|
||||||
|
if team_specific_games:
|
||||||
|
# Sort by game time and take the most recent
|
||||||
|
team_specific_games.sort(key=lambda g: g['start_time_utc'], reverse=True)
|
||||||
|
team_games.append(team_specific_games[0])
|
||||||
|
|
||||||
|
# Sort the final list by game time (most recent first)
|
||||||
|
team_games.sort(key=lambda g: g['start_time_utc'], reverse=True)
|
||||||
else:
|
else:
|
||||||
team_games = new_recent_games
|
team_games = new_recent_games
|
||||||
|
# Sort games by start time, most recent first, and limit to recent_games_to_show
|
||||||
# Sort games by start time, most recent first, and limit to recent_games_to_show
|
team_games.sort(key=lambda x: x['start_time_utc'], reverse=True)
|
||||||
team_games.sort(key=lambda x: x['start_time_utc'], reverse=True)
|
team_games = team_games[:self.recent_games_to_show]
|
||||||
team_games = team_games[:self.recent_games_to_show]
|
|
||||||
|
|
||||||
# Update only if the list content changes
|
# Update only if the list content changes
|
||||||
new_ids = {g['id'] for g in team_games}
|
new_ids = {g['id'] for g in team_games}
|
||||||
@@ -1078,13 +1095,30 @@ class SoccerUpcomingManager(BaseSoccerManager):
|
|||||||
|
|
||||||
# Filter for favorite teams only if the config is set
|
# Filter for favorite teams only if the config is set
|
||||||
if self.soccer_config.get("show_favorite_teams_only", False):
|
if self.soccer_config.get("show_favorite_teams_only", False):
|
||||||
team_games = [game for game in new_upcoming_games if game['home_abbr'] in self.favorite_teams or game['away_abbr'] in self.favorite_teams]
|
# Get all games involving favorite teams
|
||||||
|
favorite_team_games = [game for game in new_upcoming_games
|
||||||
|
if game['home_abbr'] in self.favorite_teams or
|
||||||
|
game['away_abbr'] in self.favorite_teams]
|
||||||
|
|
||||||
|
# Select one game per favorite team (earliest upcoming game for each team)
|
||||||
|
team_games = []
|
||||||
|
for team in self.favorite_teams:
|
||||||
|
# Find games where this team is playing
|
||||||
|
team_specific_games = [game for game in favorite_team_games
|
||||||
|
if game['home_abbr'] == team or game['away_abbr'] == team]
|
||||||
|
|
||||||
|
if team_specific_games:
|
||||||
|
# Sort by game time and take the earliest
|
||||||
|
team_specific_games.sort(key=lambda g: g['start_time_utc'])
|
||||||
|
team_games.append(team_specific_games[0])
|
||||||
|
|
||||||
|
# Sort the final list by game time
|
||||||
|
team_games.sort(key=lambda g: g['start_time_utc'])
|
||||||
else:
|
else:
|
||||||
team_games = new_upcoming_games
|
team_games = new_upcoming_games
|
||||||
|
# Sort games by start time, soonest first, then limit to configured count
|
||||||
# Sort games by start time, soonest first, then limit to configured count
|
team_games.sort(key=lambda x: x['start_time_utc'])
|
||||||
team_games.sort(key=lambda x: x['start_time_utc'])
|
team_games = team_games[:self.upcoming_games_to_show]
|
||||||
team_games = team_games[:self.upcoming_games_to_show]
|
|
||||||
|
|
||||||
# Update only if the list content changes
|
# Update only if the list content changes
|
||||||
new_ids = {g['id'] for g in team_games}
|
new_ids = {g['id'] for g in team_games}
|
||||||
|
|||||||
Reference in New Issue
Block a user