1+ import random
2+ import board
3+ import adafruit_pyportal
4+
5+ cwd = ("/" + __file__ ).rsplit ('/' , 1 )[0 ] # the current working directory (where this file is)
6+
7+ DAY = ["Day of the year" ]
8+ PERSON = ["Person" ]
9+ NOTABLE = ["Notable for" ]
10+ YEAR = ["year" ]
11+ ACCOMPLISH = ["Accomplishment" ]
12+ WEB = ["Web Reference" ]
13+
14+ DATA = Fake_Requests (cwd + "/jan1_hist_json.py" )
15+
16+ # create pyportal object w no data source (we'll feed it text later)
17+ pyportal = PyPortal (url = DATA ,
18+ json_path = (DAY , PERSON , NOTABLE , YEAR , ACCOMPLISH , WEB ),
19+ status_neopixel = board .NEOPIXEL ,
20+ default_bg = None ,
21+ text_font = cwd + "fonts/Arial-ItalicMT-17.bdf" ,
22+ text_position = ((5 , 10 ), (5 , 50 ), (5 , 90 ),(5 , 130 ), (5 , 170 ), (5 , 210 )),
23+ text_color = (0xFFFFFF , 0xFFFFFF , 0xFFFFFF , 0xFFFFFF , 0xFFFFFF , 0xFFFFFF ),
24+ text_maxlen = (50 , 50 , 50 , 50 , 50 , 50 ), # cut off characters
25+ )
26+
27+ pyportal .set_text ("loading ..." ) # display while user waits
28+ pyportal .preload_font () # speed things up by preloading font
29+ pyportal .set_text ("What happened today in history?" ) # show title
30+
31+ while True :
32+ if pyportal .touchscreen .touch_point :
33+ while True :
34+ response = None
35+ try :
36+ response = pyportal .fetch ()
37+ print ("Response is" , response )
38+ except RuntimeError as e :
39+ print ("Some error occured, retrying! -" , e )
0 commit comments