11"""
22Dashblock API Adafruit Learn Guide Count demo
3- Isaac Wellish
3+ Using Dashblock to cerate a custom API,
4+ display the number of learn guides on learn.adafruit.com
45"""
56
6- import board
77import time
8+ import board
89from adafruit_pyportal import PyPortal
910
1011# Get wifi details and more from a secrets.py file
1516 raise
1617
1718# Set up where we'll be fetching data from
18- DATA_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"
19+ DATA_SOURCE = "https://api.dashblock.io/model/v1?api_key=" + secrets [ 'dashblock_key' ]
1920GUIDE_COUNT = ['entities' , 0 , 'guide count' ]
2021CAPTION = 'total tutorials:'
2122
3233 text_font = cwd + "/fonts/Collegiate-50.bdf" ,
3334 text_position = ((40 , 100 )), # definition location
3435 text_color = (0x8080FF ),
35- text_wrap = (20 ),
36- text_maxlen = (4 ), # max text size for word, part of speech and def
36+ text_maxlen = (4 ), # max text length, only want first 4 chars for number of guides
3737 caption_text = CAPTION ,
3838 caption_font = cwd + "/fonts/Collegiate-24.bdf" ,
3939 caption_position = (40 , 60 ),
4242# track the last value so we can play a sound when it updates
4343last_value = 0
4444
45- print ("loading..." ) # print to repl while waiting for font to load
46- pyportal .preload_font () # speed things up by preloading font
47-
4845while True :
4946 try :
5047 value = pyportal .fetch ()
5148 print ("Response is" , value )
52- int_value = int (value [:4 ])
49+ int_value = int (value [:4 ]) # save only first 4 chars and cast to int
5350 print (int_value )
5451 if last_value < int_value : # ooh it went up!
5552 print ("New follower!" )
56- pyportal .play_file (cwd + "/coin.wav" ) # uncomment make a noise!
53+ pyportal .play_file (cwd + "/coin.wav" ) # make a noise!
5754 last_value = int_value
5855 except RuntimeError as e :
5956 print ("Some error occured, retrying! -" , e )
6057 except ValueError as e :
6158 print ("Value error occured, retrying! -" , e )
6259 continue
6360
64- time .sleep (600 ) #update every 10 mins
61+ time .sleep (600 ) #update every 10 mins
0 commit comments