/ PyPortal_Quotes / code.py
code.py
 1  # SPDX-FileCopyrightText: 2019 Limor Fried for Adafruit Industries
 2  #
 3  # SPDX-License-Identifier: MIT
 4  
 5  import time
 6  import board
 7  from adafruit_pyportal import PyPortal
 8  
 9  # Set up where we'll be fetching data from
10  DATA_SOURCE = "https://www.adafruit.com/api/quotes.php"
11  QUOTE_LOCATION = [0, 'text']
12  AUTHOR_LOCATION = [0, 'author']
13  
14  # the current working directory (where this file is)
15  cwd = ("/"+__file__).rsplit('/', 1)[0]
16  pyportal = PyPortal(url=DATA_SOURCE,
17                      json_path=(QUOTE_LOCATION, AUTHOR_LOCATION),
18                      status_neopixel=board.NEOPIXEL,
19                      default_bg=cwd+"/quote_background.bmp",
20                      text_font=cwd+"/fonts/Arial-ItalicMT-17.bdf",
21                      text_position=((20, 120),  # quote location
22                                     (5, 210)), # author location
23                      text_color=(0xFFFFFF,  # quote text color
24                                  0x8080FF), # author text color
25                      text_wrap=(35, # characters to wrap for quote
26                                 0), # no wrap for author
27                      text_maxlen=(180, 30), # max text size for quote & author
28                     )
29  
30  # speed up projects with lots of text by preloading the font!
31  pyportal.preload_font()
32  
33  while True:
34      try:
35          value = pyportal.fetch()
36          print("Response is", value)
37      except (ValueError, RuntimeError, ConnectionError, OSError) as e:
38          print("Some error occured, retrying! -", e)
39      time.sleep(60)