Skip to content

Commit 684bb6d

Browse files
committed
Adding more error catching
the soccer feed was demonstrating unsportsmanlike behavior with the json_stream so adding error handling to pull down the json traditionally in case other feeds do that as well. the s3 can handle the full json, it's just slower than the stream
1 parent c205756 commit 684bb6d

File tree

1 file changed

+41
-2
lines changed
  • Matrix_Portal_S3_ESPN_API/CircuitPython

1 file changed

+41
-2
lines changed

Matrix_Portal_S3_ESPN_API/CircuitPython/code.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ def get_data(data, team, logo, group):
188188
names = []
189189
scores = []
190190
info = []
191+
index = 0
191192
# the team you are following's logo
192193
bitmap0 = displayio.OnDiskBitmap(logo)
193194
grid0 = displayio.TileGrid(bitmap0, pixel_shader=bitmap0.pixel_shader, x = 2)
@@ -227,11 +228,40 @@ def get_data(data, team, logo, group):
227228
# gets info on game
228229
info.append(event["status"]["type"]["shortDetail"])
229230
break
231+
if playing and len(names) != 2:
232+
print("did not get expected response, fetching full JSON..")
233+
try:
234+
resp.close()
235+
# pylint: disable=broad-except
236+
except Exception as e:
237+
print(f"{e}, continuing..")
238+
# pylint: disable=unnecessary-pass
239+
pass
240+
names.clear()
241+
scores.clear()
242+
info.clear()
243+
resp = requests.get(data)
244+
response_as_json = resp.json()
245+
for e in response_as_json["events"]:
246+
if team[0] in e["name"]:
247+
print(index)
248+
info.append(response_as_json["events"][0]["date"])
249+
names.append(response_as_json["events"][0]["competitions"]
250+
[0]["competitors"][0]["team"]["abbreviation"])
251+
names.append(response_as_json["events"][0]["competitions"]
252+
[0]["competitors"][1]["team"]["abbreviation"])
253+
scores.append(response_as_json["events"][0]["competitions"]
254+
[0]["competitors"][0]["score"])
255+
scores.append(response_as_json["events"][0]["competitions"]
256+
[0]["competitors"][1]["score"])
257+
info.append(response_as_json["events"][0]["status"]["type"]["shortDetail"])
258+
else:
259+
index += 1
230260
# debug printing
231261
print(names)
232262
print(scores)
233263
print(info)
234-
if playing:
264+
if playing and len(names) == 2:
235265
# pull out the date
236266
date = info[0]
237267
# convert it to be readable
@@ -301,7 +331,16 @@ def get_data(data, team, logo, group):
301331
group.append(vs_text)
302332
group.append(info_text)
303333
# close the response
304-
resp.close()
334+
try:
335+
# sometimes an OSError is thrown:
336+
# "invalid syntax for integer with base 16"
337+
# the code can continue depite it though
338+
resp.close()
339+
# pylint: disable=broad-except
340+
except Exception as e:
341+
print(f"{e}, continuing..")
342+
# pylint: disable=unnecessary-pass
343+
pass
305344
pixel.fill((0, 0, 0))
306345
# return that data was just fetched
307346
fetch_status = True

0 commit comments

Comments
 (0)