Skip to content

Commit f7e680a

Browse files
committed
inital commit for getting current date in right form
1 parent e1c9f4b commit f7e680a

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

PyPortal_on_this_day/get_date.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""
2+
Get the current day and return string as 'xx/xx'
3+
"""
4+
5+
import time
6+
import board
7+
import neopixel
8+
from adafruit_pyportal import PyPortal
9+
from adafruit_bitmap_font import bitmap_font
10+
from adafruit_display_text.Label import Label
11+
12+
# determine the current working directory
13+
# needed so we know where to find files
14+
cwd = ("/"+__file__).rsplit('/', 1)[0]
15+
16+
# initialize the pyportal object and let us know what data to fetch and where
17+
# to display it
18+
pyportal = PyPortal(status_neopixel=board.NEOPIXEL,
19+
default_bg=0x000000)
20+
21+
22+
23+
while True:
24+
try:
25+
print("Getting time from internet!")
26+
pyportal.get_local_time()
27+
except RuntimeError as e:
28+
print("Some error occured, retrying! -", e)
29+
continue
30+
break
31+
32+
33+
refresh_time = None
34+
35+
while True:
36+
time_now = time.localtime()
37+
# only query the online time once per hour (and on first run)
38+
if (not refresh_time) or (time.monotonic() - refresh_time) > 3600:
39+
try:
40+
print("Getting time from internet!")
41+
pyportal.get_local_time()
42+
refresh_time = time.monotonic()
43+
month, day = time_now[1:3]
44+
#month = time_now[1]
45+
#day = time_now[2]
46+
print("the day is")
47+
print(month, "_", day)
48+
49+
except RuntimeError as e:
50+
print("Some error occured, retrying! -", e)
51+
continue
52+

0 commit comments

Comments
 (0)