|
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 |
3 | 4 | import time
|
4 | 5 | import board
|
5 | 6 | import busio
|
|
15 | 16 | import rtc
|
16 | 17 |
|
17 | 18 | # Calendar ID
|
18 |
| -CALENDAR_ID = "YOUR_CALENDAR_ID" |
| 19 | +CALENDAR_ID = "YOUR_CAL_ID" |
19 | 20 |
|
20 | 21 | # Maximum amount of events to display
|
21 | 22 | MAX_EVENTS = 5
|
|
38 | 39 | 12: "Dec",
|
39 | 40 | }
|
40 | 41 |
|
| 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 | + |
41 | 53 | # Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and
|
42 | 54 | # "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other
|
43 | 55 | # source control.
|
@@ -93,7 +105,15 @@ def get_current_time(time_max=False):
|
93 | 105 | cur_time = r.datetime
|
94 | 106 | if time_max: # maximum time to fetch events is midnight (4:59:59UTC)
|
95 | 107 | 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], |
97 | 117 | )
|
98 | 118 | cur_time = cur_time_max
|
99 | 119 | cur_time = "{:04d}-{:02d}-{:02d}T{:02d}:{:02d}:{:02d}{:s}".format(
|
@@ -161,9 +181,11 @@ def format_datetime(datetime, pretty_date=False):
|
161 | 181 | # convert to 12hr time
|
162 | 182 | hours -= 12
|
163 | 183 | # 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) |
165 | 185 | 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 | + ) |
167 | 189 | return formatted_date
|
168 | 190 | # Event occurs today, return the time only
|
169 | 191 | return formatted_time
|
@@ -208,20 +230,12 @@ def display_calendar_events(resp_events):
|
208 | 230 | line_header = Line(0, 50, 320, 50, color=0x000000)
|
209 | 231 | pyportal.splash.append(line_header)
|
210 | 232 |
|
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) |
218 | 235 | pyportal.splash.append(label_header)
|
219 | 236 |
|
220 | 237 | # Set up calendar event fonts
|
221 | 238 | font_events = bitmap_font.load_font("fonts/Arial-14.pcf")
|
222 |
| -font_events.load_glyphs( |
223 |
| - b"abcdefghjiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890- ()" |
224 |
| -) |
225 | 239 |
|
226 | 240 | if not google_auth.refresh_access_token():
|
227 | 241 | raise RuntimeError("Unable to refresh access token - has the token been revoked?")
|
|
0 commit comments