Skip to content

Commit 75e8cf2

Browse files
authored
Merge pull request #2772 from adafruit/dhalbert-patch-8
PyPortal_Google_Calendar: update to settings.toml
2 parents cf6ffd5 + c676edc commit 75e8cf2

2 files changed

Lines changed: 16 additions & 32 deletions

File tree

PyPortal/PyPortal_Google_Calendar/authenticator/code.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
# SPDX-FileCopyrightText: 2021 Brent Rubell, written for Adafruit Industries
22
#
33
# SPDX-License-Identifier: Unlicense
4+
5+
import os
6+
47
from adafruit_display_text.label import Label
58
from adafruit_bitmap_font import bitmap_font
69
from adafruit_oauth2 import OAuth2
710
from adafruit_pyportal import Network, Graphics
811

9-
# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and
10-
# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other
11-
# source control.
12-
# pylint: disable=no-name-in-module,wrong-import-order
13-
try:
14-
from secrets import secrets
15-
except ImportError:
16-
print("WiFi secrets are kept in secrets.py, please add them there!")
17-
raise
18-
1912
network = Network()
2013
network.connect()
2114

@@ -50,8 +43,8 @@
5043
# Initialize an oauth2 object
5144
google_auth = OAuth2(
5245
network.requests,
53-
secrets["google_client_id"],
54-
secrets["google_client_secret"],
46+
os.getenv("GOOGLE_CLIENT_ID"),
47+
os.getenv("GOOGLE_CLIENT_SECRET"),
5548
scopes,
5649
)
5750

@@ -87,18 +80,18 @@
8780

8881
print("Successfully Authenticated with Google!")
8982

90-
# print formatted keys for adding to secrets.py
91-
print("Add the following lines to your secrets.py file:")
92-
print("\t'google_access_token' " + ":" + " '%s'," % google_auth.access_token)
93-
print("\t'google_refresh_token' " + ":" + " '%s'" % google_auth.refresh_token)
83+
# print formatted keys for adding to settings.toml
84+
print("Add the following lines to your settings.toml file:")
85+
print(f'GOOGLE_ACCESS_TOKEN = "{google_auth.access_token}"')
86+
print(f'GOOGLE_REFRESH_TOKEN = "{google_auth.refresh_token}"')
9487
# Remove QR code and code/verification labels
9588
graphics.splash.pop()
9689
graphics.splash.pop()
9790
graphics.splash.pop()
9891

9992
label_overview_text.text = "Successfully Authenticated!"
10093
label_verification_url.text = (
101-
"Check the REPL for tokens to add\n\tto your secrets.py file"
94+
"Check the REPL for tokens to add\n\tto your settings.toml file"
10295
)
10396

10497
# prevent exit

PyPortal/PyPortal_Google_Calendar/code.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-FileCopyrightText: 2021 Brent Rubell, written for Adafruit Industries
22
#
33
# SPDX-License-Identifier: Unlicense
4+
import os
45
import time
56
from adafruit_oauth2 import OAuth2
67
from adafruit_display_shapes.line import Line
@@ -42,16 +43,6 @@
4243
6: "Sunday",
4344
}
4445

45-
# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and
46-
# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other
47-
# source control.
48-
# pylint: disable=no-name-in-module,wrong-import-order
49-
try:
50-
from secrets import secrets
51-
except ImportError:
52-
print("WiFi secrets are kept in secrets.py, please add them there!")
53-
raise
54-
5546
# Create the PyPortal object
5647
pyportal = PyPortal()
5748
r = rtc.RTC()
@@ -63,18 +54,18 @@
6354
scopes = ["https://www.googleapis.com/auth/calendar.readonly"]
6455
google_auth = OAuth2(
6556
pyportal.network.requests,
66-
secrets["google_client_id"],
67-
secrets["google_client_secret"],
57+
os.getenv("GOOGLE_CLIENT_ID"),
58+
os.getenv("GOOGLE_CLIENT_SECRET"),
6859
scopes,
69-
secrets["google_access_token"],
70-
secrets["google_refresh_token"],
60+
os.getenv("GOOGLE_ACCESS_TOKEN"),
61+
os.getenv("GOOGLE_REFRESH_TOKEN"),
7162
)
7263

7364

7465
def get_current_time(time_max=False):
7566
"""Gets local time from Adafruit IO and converts to RFC3339 timestamp."""
7667
# Get local time from Adafruit IO
77-
pyportal.get_local_time(secrets["timezone"])
68+
pyportal.get_local_time(os.getenv("TIMEZONE"))
7869
# Format as RFC339 timestamp
7970
cur_time = r.datetime
8071
if time_max: # maximum time to fetch events is midnight (4:59:59UTC)

0 commit comments

Comments
 (0)