/
code.py
38 lines (33 loc) · 1.32 KB
/
code.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# SPDX-FileCopyrightText: 2019 Limor Fried for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import time
import board
from adafruit_pyportal import PyPortal
# Set up where we'll be fetching data from
DATA_SOURCE = "https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY"
# There's a few different places we look for data in the photo of the day
IMAGE_LOCATION = ["url"]
TITLE_LOCATION = ["title"]
DATE_LOCATION = ["date"]
# the current working directory (where this file is)
cwd = ("/"+__file__).rsplit('/', 1)[0]
pyportal = PyPortal(url=DATA_SOURCE,
json_path=(TITLE_LOCATION, DATE_LOCATION),
status_neopixel=board.NEOPIXEL,
default_bg=cwd+"/nasa_background.bmp",
text_font=cwd+"/fonts/Arial-12.bdf",
text_position=((5, 220), (5, 200)),
text_color=(0xFFFFFF, 0xFFFFFF),
text_maxlen=(50, 50), # cut off characters
image_json_path=IMAGE_LOCATION,
image_resize=(320, 240),
image_position=(0, 0))
while True:
response = None
try:
response = pyportal.fetch()
print("Response is", response)
except RuntimeError as e:
print("Some error occured, retrying! -", e)
time.sleep(30*60) # 30 minutes till next check