Skip to content

Commit 7fae0ca

Browse files
author
brentru
committed
update code to look like magtag code!
1 parent c257888 commit 7fae0ca

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

PyPortal_Google_Calendar/code.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# PyPortal Google Calendar Viewer
2-
# Brent Rubell for Adafruit Industries, 2021
1+
# SPDX-FileCopyrightText: 2021 Brent Rubell, written for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
34
import time
45
import board
56
import busio
@@ -15,7 +16,7 @@
1516
import rtc
1617

1718
# Calendar ID
18-
CALENDAR_ID = "YOUR_CALENDAR_ID"
19+
CALENDAR_ID = "YOUR_CAL_ID"
1920

2021
# Maximum amount of events to display
2122
MAX_EVENTS = 5
@@ -38,6 +39,17 @@
3839
12: "Dec",
3940
}
4041

42+
# Dict. of day names for pretty-printing the header
43+
WEEKDAYS = {
44+
0: "Monday",
45+
1: "Tuesday",
46+
2: "Wednesday",
47+
3: "Thursday",
48+
4: "Friday",
49+
5: "Saturday",
50+
6: "Sunday",
51+
}
52+
4153
# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and
4254
# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other
4355
# source control.
@@ -93,7 +105,15 @@ def get_current_time(time_max=False):
93105
cur_time = r.datetime
94106
if time_max: # maximum time to fetch events is midnight (4:59:59UTC)
95107
cur_time_max = time.struct_time(
96-
cur_time[0], cur_time[1], cur_time[2] + 1, 4, 59, 59, 0, -1, -1
108+
cur_time[0],
109+
cur_time[1],
110+
cur_time[2] + 1,
111+
4,
112+
59,
113+
59,
114+
cur_time[6],
115+
cur_time[7],
116+
cur_time[8],
97117
)
98118
cur_time = cur_time_max
99119
cur_time = "{:04d}-{:02d}-{:02d}T{:02d}:{:02d}:{:02d}{:s}".format(
@@ -161,9 +181,11 @@ def format_datetime(datetime, pretty_date=False):
161181
# convert to 12hr time
162182
hours -= 12
163183
# via https://github.com/micropython/micropython/issues/3087
164-
formatted_time = "{:02d}:{:02d}{:s}".format(hours, minutes, am_pm)
184+
formatted_time = "{:01d}:{:02d}{:s}".format(hours, minutes, am_pm)
165185
if pretty_date: # return a nice date for header label
166-
formatted_date = "{}. {:02d}, {:04d} ".format(MONTHS[month], mday, year)
186+
formatted_date = "{} {}.{:02d}, {:04d} ".format(
187+
WEEKDAYS[r.datetime[6]], MONTHS[month], mday, year
188+
)
167189
return formatted_date
168190
# Event occurs today, return the time only
169191
return formatted_time
@@ -208,20 +230,12 @@ def display_calendar_events(resp_events):
208230
line_header = Line(0, 50, 320, 50, color=0x000000)
209231
pyportal.splash.append(line_header)
210232

211-
font_h1 = bitmap_font.load_font("fonts/Arial-Bold-24.pcf")
212-
font_h1.load_glyphs(
213-
b"abcdefghjiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-,. "
214-
)
215-
label_header = label.Label(
216-
font_h1, x=(board.DISPLAY.width // 5) + 1, y=30, color=0x000000, max_glyphs=13
217-
)
233+
font_h1 = bitmap_font.load_font("fonts/Arial-18.pcf")
234+
label_header = label.Label(font_h1, x=10, y=30, color=0x000000, max_glyphs=30)
218235
pyportal.splash.append(label_header)
219236

220237
# Set up calendar event fonts
221238
font_events = bitmap_font.load_font("fonts/Arial-14.pcf")
222-
font_events.load_glyphs(
223-
b"abcdefghjiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890- ()"
224-
)
225239

226240
if not google_auth.refresh_access_token():
227241
raise RuntimeError("Unable to refresh access token - has the token been revoked?")
31.5 KB
Binary file not shown.
-39.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)