1717# Set up where we'll be fetching data from
1818DATA_SOURCE = "https://api.dashblock.io/model/v1?api_key=39c755c0-c84e-11e9-8ee0-7bf8836bd560&url=https%3A%2F%2Flearn.adafruit.com%2F&model_id=3rOMRrfFn"
1919GUIDE_COUNT = ['entities' , 0 , 'guide count' ]
20- CAPTION = 'learn.adafruit.com '
20+ CAPTION = 'total tutorials: '
2121
2222# determine the current working directory
2323# needed so we know where to find files
2828pyportal = PyPortal (url = DATA_SOURCE ,
2929 json_path = (GUIDE_COUNT ),
3030 status_neopixel = board .NEOPIXEL ,
31- # default_bg=cwd+"/wordoftheday_background .bmp",
32- text_font = cwd + "/fonts/Arial-ItalicMT-17 .bdf" ,
33- text_position = ((50 , 100 )), # definition location
31+ default_bg = cwd + "/adabot_cover .bmp" ,
32+ text_font = cwd + "/fonts/Collegiate-50 .bdf" ,
33+ text_position = ((40 , 100 )), # definition location
3434 text_color = (0x8080FF ),
35- text_wrap = (0 ),
36- text_maxlen = (180 ), # max text size for word, part of speech and def
35+ text_wrap = (20 ),
36+ text_maxlen = (4 ), # max text size for word, part of speech and def
3737 caption_text = CAPTION ,
38- caption_font = cwd + "/fonts/Arial-ItalicMT-17 .bdf" ,
39- caption_position = (50 , 220 ),
38+ caption_font = cwd + "/fonts/Collegiate-24 .bdf" ,
39+ caption_position = (40 , 60 ),
4040 caption_color = 0xFFFFFF )
4141
42+ # track the last value so we can play a sound when it updates
43+ last_value = 0
44+
4245print ("loading..." ) # print to repl while waiting for font to load
4346pyportal .preload_font () # speed things up by preloading font
4447
4548while True :
4649 try :
47- # pylint: disable=protected-access
4850 value = pyportal .fetch ()
4951 print ("Response is" , value )
52+ int_value = int (value [:4 ])
53+ print (int_value )
54+ if last_value < int_value : # ooh it went up!
55+ print ("New follower!" )
56+ pyportal .play_file (cwd + "/coin.wav" ) # uncomment make a noise!
57+ last_value = int_value
5058 except RuntimeError as e :
5159 print ("Some error occured, retrying! -" , e )
60+ except ValueError as e :
61+ print ("Value error occured, retrying! -" , e )
62+ continue
5263
53- time .sleep (3600 ) #update every hour
64+ time .sleep (600 ) #update every 10 mins
0 commit comments