edit comments and clean up code
+"""
+This example uses the Wordnik API to display Wordnik's Word of the Day.
+Each day a new word, it's part of speech, and definition
+will appear automatically on the display.
+"""
+
import time
import board
from adafruit_pyportal import PyPortal
-# Get wifi details and more from a settings.py file
+# Get wifi details and more from a secrets.py file
try:
from secrets import secrets
except ImportError:
@@ -19,7 +25,13 @@ PUBLISH_DATE = ['publishDate']
CAPTION = 'wordnik.com/word-of-the-day'
PRONUNCIATION = [0,'raw']
+# determine the current working directory
+# needed so we know where to find files
cwd = ("/"+__file__).rsplit('/', 1)[0]
+
+
+# Initialize the pyportal object and let us know what data to fetch and where
+# to display it
pyportal = PyPortal(url=DATA_SOURCE,
json_path=(WORD_LOCATION, PART_OF_SPEECH, DEF_LOCATION),
status_neopixel=board.NEOPIXEL,
@@ -29,15 +41,15 @@ pyportal = PyPortal(url=DATA_SOURCE,
(50, 50), # part of speech location
(50, 135), # definition location
),
- text_color=(0x8080FF, # quote text color
+ text_color=(0x8080FF,
0xFF00FF,
0xFFFFFF
- ), # author text color
- text_wrap=(0, # characters to wrap for quote
+ ),
+ text_wrap=(0, # characters to wrap for text
0,
28
- ), # no wrap for author
- text_maxlen=(180, 30, 115), # max text size for word, def, type, and date (10 for date)
+ ),
+ text_maxlen=(180, 30, 115), # max text size for word, part of speech and def
caption_text=CAPTION,
caption_font=cwd+"/fonts/Arial-ItalicMT-17.bdf",
caption_position=(50, 220),
@@ -54,15 +66,5 @@ while True:
print("Response is", value)
except RuntimeError as e:
print("Some error occured, retrying! -", e)
- time.sleep(120)
-
-
- """
- Attempt to switch between definition and example states
-
- if (DEF_EX_VAL == 0):
- DEF_EX_VAL = 1
- elif (DEF_EX_VAL == 1):
- DEF_EX_VAL = 0
+ time.sleep(600) # Update every 10 minutes
- """
\ No newline at end of file
