Fix NHL recent games rotation to properly show all team games

This commit is contained in:
ChuckBuilds
2025-04-18 14:15:25 -05:00
parent 6794ee9962
commit bb63e288b8

View File

@@ -506,10 +506,27 @@ class NHLRecentManager(BaseNHLManager):
team_games[team] = [] team_games[team] = []
team_games[team].append(game) team_games[team].append(game)
# Debug: Print all favorite team games we found
print("\nDEBUG - Favorite team games found:")
for team, games in team_games.items():
print(f"\n{team} games:")
for game in games:
print(f" {game['away_abbr']} vs {game['home_abbr']}")
# Find the first team that has games
first_team_with_games = None
for team in self.favorite_teams:
if team in team_games and team_games[team]:
first_team_with_games = team
break
if first_team_with_games:
# If we don't have a current game or it's not in the new list, start from the beginning # If we don't have a current game or it's not in the new list, start from the beginning
if not self.current_game or self.current_game not in recent_games: if not self.current_game or self.current_game not in recent_games:
self.current_team_index = 0 self.current_team_index = self.favorite_teams.index(first_team_with_games)
self.current_game_index = 0 self.current_game_index = 0
self.current_game = team_games[first_team_with_games][0]
logging.info(f"[NHL] Starting with {first_team_with_games} game: {self.current_game['away_abbr']} vs {self.current_game['home_abbr']}")
else: else:
# Find which team we're currently showing # Find which team we're currently showing
for i, team in enumerate(self.favorite_teams): for i, team in enumerate(self.favorite_teams):
@@ -529,22 +546,30 @@ class NHLRecentManager(BaseNHLManager):
# If we've shown all games for this team, move to next team # If we've shown all games for this team, move to next team
if self.current_game_index == 0: if self.current_game_index == 0:
self.current_team_index = (self.current_team_index + 1) % len(self.favorite_teams) # Find the next team that has games
next_team = self.favorite_teams[self.current_team_index] next_team = None
for i in range(len(self.favorite_teams)):
next_team_index = (self.current_team_index + i + 1) % len(self.favorite_teams)
next_team = self.favorite_teams[next_team_index]
if next_team in team_games and team_games[next_team]: if next_team in team_games and team_games[next_team]:
self.current_team_index = next_team_index
self.current_game = team_games[next_team][0] self.current_game = team_games[next_team][0]
logging.info(f"[NHL] Switching to {next_team} game: {self.current_game['away_abbr']} vs {self.current_game['home_abbr']}")
break
# Debug: Print all favorite team games we found # If no next team has games, go back to the first team with games
print("\nDEBUG - Favorite team games found:") if not next_team or next_team not in team_games or not team_games[next_team]:
for team, games in team_games.items(): self.current_team_index = self.favorite_teams.index(first_team_with_games)
print(f"\n{team} games:") self.current_game = team_games[first_team_with_games][0]
for game in games: logging.info(f"[NHL] No more games, returning to {first_team_with_games} game: {self.current_game['away_abbr']} vs {self.current_game['home_abbr']}")
print(f" {game['away_abbr']} vs {game['home_abbr']}")
if self.current_game: if self.current_game:
logging.info(f"[NHL] Rotating to recent game: {self.current_game['away_abbr']} vs {self.current_game['home_abbr']}") logging.info(f"[NHL] Rotating to recent game: {self.current_game['away_abbr']} vs {self.current_game['home_abbr']}")
else: else:
logging.info("[NHL] No current game to display") logging.info("[NHL] No current game to display")
else:
logging.info("[NHL] No recent games found for favorite teams")
self.current_game = None
else: else:
logging.info("[NHL] No recent games found") logging.info("[NHL] No recent games found")
self.current_game = None self.current_game = None