mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-12 13:42:59 +00:00
Fix NHL upcoming games rotation to properly handle teams with no games
This commit is contained in:
@@ -637,34 +637,6 @@ class NHLUpcomingManager(BaseNHLManager):
|
|||||||
team_games[team] = []
|
team_games[team] = []
|
||||||
team_games[team].append(game)
|
team_games[team].append(game)
|
||||||
|
|
||||||
# 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 upcoming_games:
|
|
||||||
self.current_team_index = 0
|
|
||||||
self.current_game_index = 0
|
|
||||||
else:
|
|
||||||
# Find which team we're currently showing
|
|
||||||
for i, team in enumerate(self.favorite_teams):
|
|
||||||
if team in team_games and self.current_game in team_games[team]:
|
|
||||||
self.current_team_index = i
|
|
||||||
self.current_game_index = team_games[team].index(self.current_game)
|
|
||||||
break
|
|
||||||
|
|
||||||
# Get the current team's games
|
|
||||||
current_team = self.favorite_teams[self.current_team_index]
|
|
||||||
current_team_games = team_games.get(current_team, [])
|
|
||||||
|
|
||||||
if current_team_games:
|
|
||||||
# Move to next game for current team
|
|
||||||
self.current_game_index = (self.current_game_index + 1) % len(current_team_games)
|
|
||||||
self.current_game = current_team_games[self.current_game_index]
|
|
||||||
|
|
||||||
# If we've shown all games for this team, move to next team
|
|
||||||
if self.current_game_index == 0:
|
|
||||||
self.current_team_index = (self.current_team_index + 1) % len(self.favorite_teams)
|
|
||||||
next_team = self.favorite_teams[self.current_team_index]
|
|
||||||
if next_team in team_games and team_games[next_team]:
|
|
||||||
self.current_game = team_games[next_team][0]
|
|
||||||
|
|
||||||
# Debug: Print all favorite team games we found
|
# Debug: Print all favorite team games we found
|
||||||
print("\nDEBUG - Favorite team games found:")
|
print("\nDEBUG - Favorite team games found:")
|
||||||
for team, games in team_games.items():
|
for team, games in team_games.items():
|
||||||
@@ -672,10 +644,59 @@ class NHLUpcomingManager(BaseNHLManager):
|
|||||||
for game in games:
|
for game in games:
|
||||||
print(f" {game['away_abbr']} vs {game['home_abbr']}")
|
print(f" {game['away_abbr']} vs {game['home_abbr']}")
|
||||||
|
|
||||||
if self.current_game:
|
# Find the first team that has games
|
||||||
logging.info(f"[NHL] Rotating to upcoming game: {self.current_game['away_abbr']} vs {self.current_game['home_abbr']}")
|
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 not self.current_game or self.current_game not in upcoming_games:
|
||||||
|
self.current_team_index = self.favorite_teams.index(first_team_with_games)
|
||||||
|
self.current_game_index = 0
|
||||||
|
else:
|
||||||
|
# Find which team we're currently showing
|
||||||
|
for i, team in enumerate(self.favorite_teams):
|
||||||
|
if team in team_games and self.current_game in team_games[team]:
|
||||||
|
self.current_team_index = i
|
||||||
|
self.current_game_index = team_games[team].index(self.current_game)
|
||||||
|
break
|
||||||
|
|
||||||
|
# Get the current team's games
|
||||||
|
current_team = self.favorite_teams[self.current_team_index]
|
||||||
|
current_team_games = team_games.get(current_team, [])
|
||||||
|
|
||||||
|
if current_team_games:
|
||||||
|
# Move to next game for current team
|
||||||
|
self.current_game_index = (self.current_game_index + 1) % len(current_team_games)
|
||||||
|
self.current_game = current_team_games[self.current_game_index]
|
||||||
|
|
||||||
|
# If we've shown all games for this team, move to next team
|
||||||
|
if self.current_game_index == 0:
|
||||||
|
# Find the next team that has games
|
||||||
|
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]:
|
||||||
|
self.current_team_index = next_team_index
|
||||||
|
self.current_game = team_games[next_team][0]
|
||||||
|
break
|
||||||
|
|
||||||
|
# If no next team has games, go back to the first team with games
|
||||||
|
if not next_team or next_team not in team_games or not team_games[next_team]:
|
||||||
|
self.current_team_index = self.favorite_teams.index(first_team_with_games)
|
||||||
|
self.current_game = team_games[first_team_with_games][0]
|
||||||
|
|
||||||
|
if self.current_game:
|
||||||
|
logging.info(f"[NHL] Rotating to upcoming game: {self.current_game['away_abbr']} vs {self.current_game['home_abbr']}")
|
||||||
|
else:
|
||||||
|
logging.info("[NHL] No current game to display")
|
||||||
else:
|
else:
|
||||||
logging.info("[NHL] No current game to display")
|
logging.info("[NHL] No upcoming games found for favorite teams")
|
||||||
|
self.current_game = None
|
||||||
else:
|
else:
|
||||||
logging.info("[NHL] No upcoming games found")
|
logging.info("[NHL] No upcoming games found")
|
||||||
self.current_game = None
|
self.current_game = None
|
||||||
|
|||||||
Reference in New Issue
Block a user