|
14 | 14 | from adafruit_pyportal import PyPortal |
15 | 15 |
|
16 | 16 | # Set up where we'll be fetching data from |
17 | | -DATA_SOURCE = "https://api.wordnik.com/v4/words.json/wordOfTheDay?api_key=" + os.getenv("WORDNIK_TOKEN") |
18 | | -PART_OF_SPEECH = ['definitions', 0, 'partOfSpeech'] |
19 | | -DEF_LOCATION = ['definitions', 0, 'text'] |
20 | | -EXAMPLE_LOCATION = ['examples', 0, 'text'] |
21 | | -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" |
22 | 24 | DEFINITION_EXAMPLE_ARR = [DEF_LOCATION, EXAMPLE_LOCATION] |
23 | | -#defintion and example array variable initialized at 0 |
| 25 | +# defintion and example array variable initialized at 0 |
24 | 26 | definition_example = 0 |
25 | 27 |
|
26 | 28 | # determine the current working directory |
27 | 29 | # needed so we know where to find files |
28 | | -cwd = ("/"+__file__).rsplit('/', 1)[0] |
| 30 | +cwd = ("/" + __file__).rsplit("/", 1)[0] |
29 | 31 |
|
30 | 32 | # Initialize the pyportal object and let us know what data to fetch and where |
31 | 33 | # to display it |
32 | | -pyportal = PyPortal(url=DATA_SOURCE, |
33 | | - status_neopixel=board.NEOPIXEL, |
34 | | - default_bg=cwd+"/wordoftheday_background.bmp", |
35 | | - text_font=cwd+"/fonts/Arial-ItalicMT-17.bdf", |
36 | | - text_position=((50, 30), # word location |
37 | | - (50, 50), # part of speech location |
38 | | - (50, 135)), # definition location |
39 | | - text_color=(0x8080FF, |
40 | | - 0xFF00FF, |
41 | | - 0xFFFFFF), |
42 | | - text_wrap=(0, # characters to wrap for text |
43 | | - 0, |
44 | | - 28), |
45 | | - text_maxlen=(180, 30, 115), # max text size for word, part of speech and def |
46 | | - caption_text=CAPTION, |
47 | | - caption_font=cwd+"/fonts/Arial-ItalicMT-17.bdf", |
48 | | - caption_position=(50, 220), |
49 | | - 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 | +) |
50 | 52 |
|
51 | | -print("loading...") # print to repl while waiting for font to load |
52 | | -pyportal.preload_font() # speed things up by preloading font |
53 | | -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 |
54 | 56 |
|
55 | 57 | while True: |
56 | 58 | if pyportal.touchscreen.touch_point: |
57 | 59 | try: |
58 | | - #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 |
59 | 61 | # pylint: disable=protected-access |
60 | | - pyportal._json_path=(['word'], |
61 | | - PART_OF_SPEECH, |
62 | | - DEFINITION_EXAMPLE_ARR[definition_example]) |
| 62 | + pyportal._json_path = ( |
| 63 | + ["word"], |
| 64 | + PART_OF_SPEECH, |
| 65 | + DEFINITION_EXAMPLE_ARR[definition_example], |
| 66 | + ) |
63 | 67 | value = pyportal.fetch() |
64 | 68 | print("Response is", value) |
65 | 69 | except RuntimeError as e: |
66 | 70 | print("Some error occured, retrying! -", e) |
67 | | - #Change between definition and example |
| 71 | + # Change between definition and example |
68 | 72 | if definition_example == 0: |
69 | 73 | definition_example = 1 |
70 | 74 | elif definition_example == 1: |
|
0 commit comments