def refresh_playoff(self): """ Currently the series ticker request all the games of a series everytime its asked to load on screen. This create a lot of delay between showing each series. TODO: Add a refresh function to the Series object instead and trigger a refresh only at specific time in the renderer.(End of a game, new day) """ attempts_remaining = 5 while attempts_remaining > 0: try: # Get the plaoffs data from the nhl api self.playoffs = nhl_api.playoff(self.status.season_id) # Check if there is any rounds avaialable and grab the most recent one available. if self.playoffs.rounds: self.current_round = self.playoffs.rounds[str(2)] self.current_round_name = self.current_round.names.name if self.current_round_name == "Stanley Cup Qualifier": self.current_round_name = "Qualifier" if self.playoffs.default_round == 4: self.stanleycup_round = True debug.info("defaultround number is : {}".format(self.playoffs.default_round)) try: self.series = [] # Grab the series of the current round of playoff. self.series_list = self.current_round.series # Check if prefered team are part of the current round of playoff self.pref_series = prioritize_pref_series(filter_list_of_series(self.series_list, self.pref_teams), self.pref_teams) # If the user as set to show his favorite teams in the seriesticker if self.config.seriesticker_preferred_teams_only and self.pref_series: self.series_list = self.pref_series for s in self.series_list: self.series.append(Series(s,self)) self.isPlayoff = True except AttributeError: debug.error("The {} Season playoff has not started yet or is unavailable".format(self.playoffs.season)) self.isPlayoff = False break break except ValueError as error_message: self.network_issues = True debug.error("Failed to refresh the list of Series. {} attempt remaining.".format(attempts_remaining)) debug.error(error_message) attempts_remaining -= 1 sleep(NETWORK_RETRY_SLEEP_TIME)
def render(self): if not self.data.current_round: debug.log("No Playoff to render on seriesticker") return self.allseries = self.data.series self.index = 0 self.num_series = len(self.allseries) for s in self.allseries: self.matrix.clear() series = Series(s, self.data) banner_text = "Stanley Cup" color_banner_bg = (200, 200, 200) color_banner_text = (0, 0, 0) round_name = "Final" if not self.data.current_round.number == 4: color_conf = self.team_colors.color("{}.primary".format( series.conference)) banner_text = series.conference color_banner_bg = (color_conf['r'], color_conf['g'], color_conf['b']) round_name = self.data.current_round_name self.show_indicator(self.index, self.num_series) self.matrix.draw_text((1, 7), round_name, font=self.font, fill=(255, 255, 255)) # Conference banner, Round Title self.matrix.draw.rectangle([0, 0, self.matrix.width, 5], fill=color_banner_bg) self.matrix.draw_text((1, 1), banner_text, font=self.font, fill=(0, 0, 0)) self.index += 1 # # If something fails in the process of drawing the series table due to failed API request # # Continue in the loop and skip this series. # if not self.draw_series_table(series): # debug.error('Failed Draw the series table due to failed API request. Skiping to the next series') # continue self.draw_series_table(series) self.matrix.render() self.sleepEvent.wait(self.data.config.seriesticker_rotation_rate)