1818ACCOMPLISH = ["Accomplishment" ]
1919WEB = ["Web Reference" ]
2020
21- DATA = "https://raw.githubusercontent.com/adafruit/OTD/master/electronics/01_01.json"
21+ BASE_DATA = "https://raw.githubusercontent.com/adafruit/OTD/master/electronics/"
22+ # https://raw.githubusercontent.com/adafruit/OTD/master/electronics/01_01.json
23+
24+ # a function that returns whatever is passed in
25+ def identity (x ):
26+ return x
2227
2328# create pyportal object w no data source (we'll feed it text later)
24- pyportal = PyPortal (url = DATA ,
29+ pyportal = PyPortal (url = BASE_DATA , debug = True ,
2530 json_path = (DAY , PERSON , NOTABLE , YEAR , ACCOMPLISH , WEB ),
2631 status_neopixel = board .NEOPIXEL ,
2732 default_bg = cwd + "/on_this_day_bg.bmp" ,
2833 text_font = cwd + "fonts/Arial-ItalicMT-17.bdf" ,
34+ text_transform = [identity ]* 6 , # we do this so the date doesnt get commas
2935 text_position = ((10 , 70 ), (10 , 100 ), (10 , 130 ),(60 , 160 ), (105 , 190 ), (10 , 220 )),
3036 text_color = (0xFFFFFF , 0xFFFFFF , 0xFFFFFF , 0xFFFFFF , 0xFFFFFF , 0xFFFFFF ),
3137 text_maxlen = (50 , 50 , 50 , 50 , 50 , 50 ), # cut off characters
3238 )
3339
3440while True :
41+ try :
42+ print ("Getting time from internet!" )
43+ pyportal .get_local_time ()
44+ refresh_time = time .monotonic ()
45+ except RuntimeError as e :
46+ print ("Some error occured, retrying! -" , e )
47+ continue
48+
49+ now = time .localtime ()
50+ print ("Current time:" , now )
51+ url = BASE_DATA + "%02d_%02d.json" % (now .tm_mon , now .tm_mday )
52+ print (url )
3553 response = None
3654 try :
37- response = pyportal .fetch ()
55+ response = pyportal .fetch (url )
3856 print ("Response is" , response )
3957 except RuntimeError as e :
4058 print ("Some error occured, retrying! -" , e )
4159
42- time .sleep (60 )
60+ # Make a QR code from web reference
61+ pyportal .show_QR (bytearray (response [5 ]), qr_size = 3 ,
62+ x = 220 , y = 10 )
63+
64+ # wait 10 minutes before running again
65+ time .sleep (10 * 60 )
0 commit comments