Skip to content

Commit 50ced06

Browse files
authored
Merge branch 'master' into master
2 parents a36c4ad + 27b4996 commit 50ced06

File tree

3 files changed

+59323
-0
lines changed

3 files changed

+59323
-0
lines changed

PyPortal_on_this_day/code.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""
2+
'of this day' demo
3+
Display notable info about famous electronics-related peoples
4+
Data sources: https://github.com/adafruit/OTD/tree/master/electronics
5+
"""
6+
7+
import time
8+
import board
9+
from adafruit_pyportal import PyPortal
10+
11+
cwd = ("/"+__file__).rsplit('/', 1)[0] # the current working directory (where this file is)
12+
13+
DAY = ["Day of the year"]
14+
PERSON = ["Person"]
15+
NOTABLE = ["Notable for"]
16+
YEAR = ["Year"]
17+
ACCOMPLISH = ["Accomplishment"]
18+
WEB = ["Web Reference"]
19+
20+
BASE_DATA = "https://raw.githubusercontent.com/adafruit/OTD/master/electronics/"
21+
22+
# a function that returns whatever is passed in
23+
def identity(x):
24+
return x
25+
26+
# create pyportal object w no data source (we'll feed it text later)
27+
pyportal = PyPortal(url = BASE_DATA, debug=True,
28+
json_path = (DAY, PERSON, NOTABLE, YEAR, ACCOMPLISH, WEB),
29+
status_neopixel = board.NEOPIXEL,
30+
default_bg = cwd + "/on_this_day_bg.bmp",
31+
text_font = cwd+"fonts/Arial-ItalicMT-17.bdf",
32+
text_transform = [identity]*6, # we do this so the date doesnt get commas
33+
text_position=((10, 70), (10, 100), (10, 130),(60, 160), (105, 190), (10, 220)),
34+
text_color=(0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF),
35+
text_maxlen=(50, 50, 50, 50, 50, 50), # cut off characters
36+
)
37+
38+
while True:
39+
try:
40+
print("Getting time from internet!")
41+
pyportal.get_local_time()
42+
refresh_time = time.monotonic()
43+
except RuntimeError as e:
44+
print("Some error occured, retrying! -", e)
45+
continue
46+
47+
now = time.localtime()
48+
print("Current time:", now)
49+
url = BASE_DATA+"%02d_%02d.json" % (now.tm_mon, now.tm_mday)
50+
print(url)
51+
response = None
52+
try:
53+
response = pyportal.fetch(url)
54+
print("Response is", response)
55+
except RuntimeError as e:
56+
print("Some error occured, retrying! -", e)
57+
58+
# Make a QR code from web reference
59+
pyportal.show_QR(bytearray(response[5]), qr_size=3,
60+
x=220, y=10)
61+
62+
# wait 10 minutes before running again
63+
time.sleep(10*60)

0 commit comments

Comments
 (0)