Skip to content

Commit 507000f

Browse files
authored
Merge pull request #2771 from adafruit/dhalbert-patch-7
PyPortal_Word_Of_the_Day: update to settings.toml
2 parents d3dd8cd + b6d127c commit 507000f

1 file changed

Lines changed: 38 additions & 40 deletions

File tree

  • PyPortal/PyPortal_Word_of_the_Day

PyPortal/PyPortal_Word_of_the_Day/code.py

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,69 +8,67 @@
88
will appear automatically on the display. Tap the screen to start
99
as well as to switch between the word's definition and an example sentence.
1010
"""
11+
import os
1112

1213
import board
1314
from adafruit_pyportal import PyPortal
1415

15-
# Get wifi details and more from a secrets.py file
16-
try:
17-
from secrets import secrets
18-
except ImportError:
19-
print("WiFi settings are kept in settings.py, please add them there!")
20-
raise
21-
2216
# Set up where we'll be fetching data from
23-
DATA_SOURCE = "https://api.wordnik.com/v4/words.json/wordOfTheDay?api_key="+secrets['wordnik_token']
24-
PART_OF_SPEECH = ['definitions', 0, 'partOfSpeech']
25-
DEF_LOCATION = ['definitions', 0, 'text']
26-
EXAMPLE_LOCATION = ['examples', 0, 'text']
27-
CAPTION = 'wordnik.com/word-of-the-day'
17+
DATA_SOURCE = "https://api.wordnik.com/v4/words.json/wordOfTheDay?api_key=" + os.getenv(
18+
"WORDNIK_TOKEN"
19+
)
20+
PART_OF_SPEECH = ["definitions", 0, "partOfSpeech"]
21+
DEF_LOCATION = ["definitions", 0, "text"]
22+
EXAMPLE_LOCATION = ["examples", 0, "text"]
23+
CAPTION = "wordnik.com/word-of-the-day"
2824
DEFINITION_EXAMPLE_ARR = [DEF_LOCATION, EXAMPLE_LOCATION]
29-
#defintion and example array variable initialized at 0
25+
# defintion and example array variable initialized at 0
3026
definition_example = 0
3127

3228
# determine the current working directory
3329
# needed so we know where to find files
34-
cwd = ("/"+__file__).rsplit('/', 1)[0]
30+
cwd = ("/" + __file__).rsplit("/", 1)[0]
3531

3632
# Initialize the pyportal object and let us know what data to fetch and where
3733
# to display it
38-
pyportal = PyPortal(url=DATA_SOURCE,
39-
status_neopixel=board.NEOPIXEL,
40-
default_bg=cwd+"/wordoftheday_background.bmp",
41-
text_font=cwd+"/fonts/Arial-ItalicMT-17.bdf",
42-
text_position=((50, 30), # word location
43-
(50, 50), # part of speech location
44-
(50, 135)), # definition location
45-
text_color=(0x8080FF,
46-
0xFF00FF,
47-
0xFFFFFF),
48-
text_wrap=(0, # characters to wrap for text
49-
0,
50-
28),
51-
text_maxlen=(180, 30, 115), # max text size for word, part of speech and def
52-
caption_text=CAPTION,
53-
caption_font=cwd+"/fonts/Arial-ItalicMT-17.bdf",
54-
caption_position=(50, 220),
55-
caption_color=0x808080)
34+
pyportal = PyPortal(
35+
url=DATA_SOURCE,
36+
status_neopixel=board.NEOPIXEL,
37+
default_bg=cwd + "/wordoftheday_background.bmp",
38+
text_font=cwd + "/fonts/Arial-ItalicMT-17.bdf",
39+
text_position=(
40+
(50, 30), # word location
41+
(50, 50), # part of speech location
42+
(50, 135),
43+
), # definition location
44+
text_color=(0x8080FF, 0xFF00FF, 0xFFFFFF),
45+
text_wrap=(0, 0, 28), # characters to wrap for text
46+
text_maxlen=(180, 30, 115), # max text size for word, part of speech and def
47+
caption_text=CAPTION,
48+
caption_font=cwd + "/fonts/Arial-ItalicMT-17.bdf",
49+
caption_position=(50, 220),
50+
caption_color=0x808080,
51+
)
5652

57-
print("loading...") # print to repl while waiting for font to load
58-
pyportal.preload_font() # speed things up by preloading font
59-
pyportal.set_text("\nWord of the Day") # show title
53+
print("loading...") # print to repl while waiting for font to load
54+
pyportal.preload_font() # speed things up by preloading font
55+
pyportal.set_text("\nWord of the Day") # show title
6056

6157
while True:
6258
if pyportal.touchscreen.touch_point:
6359
try:
64-
#set the JSON path here to be able to change between definition and example
60+
# set the JSON path here to be able to change between definition and example
6561
# pylint: disable=protected-access
66-
pyportal._json_path=(['word'],
67-
PART_OF_SPEECH,
68-
DEFINITION_EXAMPLE_ARR[definition_example])
62+
pyportal._json_path = (
63+
["word"],
64+
PART_OF_SPEECH,
65+
DEFINITION_EXAMPLE_ARR[definition_example],
66+
)
6967
value = pyportal.fetch()
7068
print("Response is", value)
7169
except RuntimeError as e:
7270
print("Some error occured, retrying! -", e)
73-
#Change between definition and example
71+
# Change between definition and example
7472
if definition_example == 0:
7573
definition_example = 1
7674
elif definition_example == 1:

0 commit comments

Comments
 (0)