@@ -62,11 +62,17 @@ def render(self):
62
62
font = self .font ,
63
63
fill = (0 ,0 ,0 )
64
64
)
65
+ self .index += 1
65
66
67
+ # # If something fails in the process of drawing the series table due to failed API request
68
+ # # Continue in the loop and skip this series.
69
+ # if not self.draw_series_table(series):
70
+ # debug.error('Failed Draw the series table due to failed API request. Skiping to the next series')
71
+ # continue
72
+
73
+
66
74
self .draw_series_table (series )
67
-
68
75
self .matrix .render ()
69
- self .index += 1
70
76
self .sleepEvent .wait (10 )
71
77
72
78
def draw_series_table (self , series ):
@@ -106,49 +112,61 @@ def draw_series_table(self, series):
106
112
offset_correction = 0
107
113
108
114
for game in series .games :
109
-
110
- # Request the game overview
111
- overview = nhl_api .overview (game ["gameId" ])
112
-
113
- # get the scoreboard
114
- scoreboard = Scoreboard (overview , self .data )
115
-
116
- if self .data .status .is_final (overview .status ) and hasattr (scoreboard , "winning_team" ):
117
- if scoreboard .winning_team == series .top_team .id :
118
- winning_row = top_row
119
- loosing_row = bottom_row
120
- winning_team_color = color_top_team
121
- winning_bg_color = color_top_bg
122
- else :
123
- winning_row = bottom_row
124
- loosing_row = top_row
125
- winning_team_color = color_bottom_team
126
- winning_bg_color = color_bottom_bg
127
-
128
- # Look loosing score text needs an offset
129
- if len (str (scoreboard .winning_score )) == 2 and len (str (scoreboard .winning_score )) == 1 :
130
- offset_correction = 1
131
-
132
- self .matrix .draw_text (
133
- ((rec_width + 15 + offset_correction ), loosing_row ),
134
- str (scoreboard .loosing_score ),
135
- font = self .font ,
136
- fill = loosing_color ,
137
- backgroundColor = None ,
138
- backgroundOffset = [1 , 1 , 1 , 1 ]
139
- )
140
-
141
- position = self .matrix .draw_text (
142
- (rec_width + 15 , winning_row ),
143
- str (scoreboard .winning_score ),
144
- font = self .font ,
145
- fill = (winning_team_color ['r' ], winning_team_color ['g' ], winning_team_color ['b' ]),
146
- backgroundColor = (winning_bg_color ['r' ], winning_bg_color ['g' ], winning_bg_color ['b' ]),
147
- backgroundOffset = [1 , 1 , 1 , 1 ]
148
- )
149
-
150
- # Increment
151
- rec_width += (position ["size" ][0 ] + 4 )
115
+ attempts_remaining = 5
116
+ while attempts_remaining > 0 :
117
+ try :
118
+ # Request the game overview
119
+ overview = nhl_api .overview (game ["gameId" ])
120
+ # get the scoreboard
121
+ scoreboard = Scoreboard (overview , self .data )
122
+
123
+ if self .data .status .is_final (overview .status ) and hasattr (scoreboard , "winning_team" ):
124
+ if scoreboard .winning_team == series .top_team .id :
125
+ winning_row = top_row
126
+ loosing_row = bottom_row
127
+ winning_team_color = color_top_team
128
+ winning_bg_color = color_top_bg
129
+ else :
130
+ winning_row = bottom_row
131
+ loosing_row = top_row
132
+ winning_team_color = color_bottom_team
133
+ winning_bg_color = color_bottom_bg
134
+
135
+ # Look loosing score text needs an offset
136
+ if len (str (scoreboard .winning_score )) == 2 and len (str (scoreboard .winning_score )) == 1 :
137
+ offset_correction = 1
138
+
139
+ self .matrix .draw_text (
140
+ ((rec_width + 15 + offset_correction ), loosing_row ),
141
+ str (scoreboard .loosing_score ),
142
+ font = self .font ,
143
+ fill = loosing_color ,
144
+ backgroundColor = None ,
145
+ backgroundOffset = [1 , 1 , 1 , 1 ]
146
+ )
147
+
148
+ position = self .matrix .draw_text (
149
+ (rec_width + 15 , winning_row ),
150
+ str (scoreboard .winning_score ),
151
+ font = self .font ,
152
+ fill = (winning_team_color ['r' ], winning_team_color ['g' ], winning_team_color ['b' ]),
153
+ backgroundColor = (winning_bg_color ['r' ], winning_bg_color ['g' ], winning_bg_color ['b' ]),
154
+ backgroundOffset = [1 , 1 , 1 , 1 ]
155
+ )
156
+
157
+ # Increment
158
+ rec_width += (position ["size" ][0 ] + 4 )
159
+ break
160
+
161
+ except ValueError as error_message :
162
+ self .data .network_issues = True
163
+ debug .error ("Failed to get the Games for the {} VS {} series: {} attempts remaining" .format (series .top_team .abbrev , series .bottom_team .abbrev , attempts_remaining ))
164
+ debug .error (error_message )
165
+ attempts_remaining -= 1
166
+ sleep (2 )
167
+ # If one of the request for player info failed after 5 attempts, return an empty dictionary
168
+ if attempts_remaining == 0 :
169
+ return False
152
170
153
171
154
172
def show_indicator (self , index , slides ):
0 commit comments