Closed jedgarpark closed 3 years ago
@jedgarpark Mind posting the full code.py
? That'll make it easier for me to reproduce.
@tannewt here's sample code I was trying:
import time
import terminalio
from adafruit_magtag.magtag import MagTag
# in seconds, we can refresh about 100 times on a battery
TIME_BETWEEN_REFRESHES = 24 * 60 * 60 # once a day delay
#DATA_SOURCE = "http://site.api.espn.com/apis/site/v2/sports/basketball/mens-college-basketball/teams"
#NAME_LOCATION = ['sports', 0, 'name']
#TEAM_LOCATION = ['sports', 0, 'leagues', 0, 'teams', 0, 'team', 'nickname']
DATA_SOURCE = "http://site.api.espn.com/apis/site/v2/sports/basketball/mens-college-basketball/scoreboard"
NAME_LOCATION = ['events', 0, 'name']
# These functions take the JSON data keys and does checks to determine
# how to display the data. They're used in the add_text blocks below
def sport_name_transform(val):
if val == None:
val = "Unavailable"
return "Sport name: " + val
def team_name_transform(val2):
if val2 == None:
val2 = "Unavailable"
return "Team name: " + val2
# Set up the MagTag with the JSON data parameters
magtag = MagTag(
url=DATA_SOURCE,
json_path=(NAME_LOCATION)#, TEAM_LOCATION)
)
magtag.add_text(
text_font="/fonts/Lato-Bold-ltd-25.bdf",
text_position=(10, 15),
is_data=False
)
# Display heading text below with formatting above
magtag.set_text("ESPN")
# Formatting for the name text
magtag.add_text(
text_font="/fonts/Arial-Bold-12.pcf",
text_position=(10, 38),
text_transform=sport_name_transform
)
# Formatting for nickname text
'''magtag.add_text(
text_font="/fonts/Arial-Bold-12.pcf",
text_position=(10, 68),
text_transform=team_name_transform
)'''
try:
# Have the MagTag connect to the internet
magtag.network.connect()
# This statement gets the JSON data and displays it automagically
value = magtag.fetch()
print("Response is", value)
except (ValueError, RuntimeError) as e:
print("Some error occured, retrying! -", e)
# wait 2 seconds for display to complete
time.sleep(2)
magtag.exit_and_deep_sleep(TIME_BETWEEN_REFRESHES)
@jedgarpark Could you please send me the font files too?
Nevermind. I think I found the issue.
Trying to grab sports scores from ESPN API v2, some json files are too large it seems to use. This one is 47KB (just team info) is fine: http://site.api.espn.com/apis/site/v2/sports/basketball/mens-college-basketball/teams
NAME_LOCATION = ['sports', 0, 'name']
But this one is 80KB (and has useful game schedule info) is failing: http://site.api.espn.com/apis/site/v2/sports/basketball/mens-college-basketball/scoreboardNAME_LOCATION = ['events', 0, 'name']
Here's the error:Retrieving data...Reply is OK! Couldn't parse json: Some error occured, retrying! - syntax error in JSON
Running on MagTag with 6.1.0-rc.0 and latest libraries.