Skip to content

Commit d7be911

Browse files
committed
initial commit
1 parent 3e010f1 commit d7be911

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

Dashblock_API/dashblock_learn.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""
2+
Dashblock API Adafruit Learn Guide Count demo
3+
Isaac Wellish
4+
"""
5+
6+
import board
7+
import time
8+
from adafruit_pyportal import PyPortal
9+
10+
# Get wifi details and more from a secrets.py file
11+
try:
12+
from secrets import secrets
13+
except ImportError:
14+
print("WiFi settings are kept in settings.py, please add them there!")
15+
raise
16+
17+
# 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+
GUIDE_COUNT = ['entities', 0, 'guide count']
20+
CAPTION = 'learn.adafruit.com'
21+
22+
# determine the current working directory
23+
# needed so we know where to find files
24+
cwd = ("/"+__file__).rsplit('/', 1)[0]
25+
26+
# Initialize the pyportal object and let us know what data to fetch and where
27+
# to display it
28+
pyportal = PyPortal(url=DATA_SOURCE,
29+
json_path = (GUIDE_COUNT),
30+
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
34+
text_color=(0x8080FF),
35+
text_wrap=(0),
36+
text_maxlen=(180), # max text size for word, part of speech and def
37+
caption_text=CAPTION,
38+
caption_font=cwd+"/fonts/Arial-ItalicMT-17.bdf",
39+
caption_position=(50, 220),
40+
caption_color=0xFFFFFF)
41+
42+
print("loading...") # print to repl while waiting for font to load
43+
pyportal.preload_font() # speed things up by preloading font
44+
45+
while True:
46+
try:
47+
# pylint: disable=protected-access
48+
value = pyportal.fetch()
49+
print("Response is", value)
50+
except RuntimeError as e:
51+
print("Some error occured, retrying! -", e)
52+
53+
time.sleep(3600) #update every hour

0 commit comments

Comments
 (0)