pylint cahnges
"""
Dashblock API Adafruit Learn Guide Count demo
-Isaac Wellish
+Using Dashblock to cerate a custom API,
+display the number of learn guides on learn.adafruit.com
"""
-import board
import time
+import board
from adafruit_pyportal import PyPortal
# Get wifi details and more from a secrets.py file
@@ -15,7 +16,7 @@ except ImportError:
raise
# Set up where we'll be fetching data from
-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"
+DATA_SOURCE = "https://api.dashblock.io/model/v1?api_key=" + secrets['dashblock_key']
GUIDE_COUNT = ['entities', 0, 'guide count']
CAPTION = 'total tutorials:'
@@ -32,8 +33,7 @@ pyportal = PyPortal(url=DATA_SOURCE,
text_font=cwd+"/fonts/Collegiate-50.bdf",
text_position=((40, 100)), # definition location
text_color=(0x8080FF),
- text_wrap=(20),
- text_maxlen=(4), # max text size for word, part of speech and def
+ text_maxlen=(4), # max text length, only want first 4 chars for number of guides
caption_text=CAPTION,
caption_font=cwd+"/fonts/Collegiate-24.bdf",
caption_position=(40, 60),
@@ -42,18 +42,15 @@ pyportal = PyPortal(url=DATA_SOURCE,
# track the last value so we can play a sound when it updates
last_value = 0
-print("loading...") # print to repl while waiting for font to load
-pyportal.preload_font() # speed things up by preloading font
-
while True:
try:
value = pyportal.fetch()
print("Response is", value)
- int_value = int(value[:4])
+ int_value = int(value[:4]) # save only first 4 chars and cast to int
print(int_value)
if last_value < int_value: # ooh it went up!
print("New follower!")
- pyportal.play_file(cwd+"/coin.wav") # uncomment make a noise!
+ pyportal.play_file(cwd+"/coin.wav") # make a noise!
last_value = int_value
except RuntimeError as e:
print("Some error occured, retrying! -", e)
