Skip to content

Commit 3eaa064

Browse files
authored
Merge pull request #3016 from justmobilize/secrets-cleanup-q-w
Secrets Cleanup Q-W
2 parents b415616 + 2642e48 commit 3eaa064

File tree

25 files changed

+308
-191
lines changed

25 files changed

+308
-191
lines changed

Minesweep/.circuitpython.skip

Lines changed: 0 additions & 1 deletion
This file was deleted.
File renamed without changes.

Minesweep/code.py renamed to PyPortal/Minesweep/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def play_a_game():
201201
set_data(touch_x, touch_y, BOMBDEATH) #reveal a red bomb
202202
tilegrid[touch_x, touch_y] = BOMBDEATH
203203
return False #lost
204-
elif under_the_tile > OPEN0 and under_the_tile <= OPEN8:
204+
elif OPEN0 < under_the_tile <= OPEN8:
205205
tilegrid[touch_x, touch_y] = under_the_tile
206206
elif under_the_tile == OPEN0:
207207
tilegrid[touch_x, touch_y] = BLANK
File renamed without changes.
File renamed without changes.

Twitter_API/code.py renamed to PyPortal/Twitter_API/code.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,23 @@
1717
"""
1818

1919
#pylint:disable=invalid-name
20+
21+
from os import getenv
2022
import time
2123
import board
2224
from adafruit_pyportal import PyPortal
2325

24-
try:
25-
from secrets import secrets
26-
except ImportError:
27-
print("""WiFi settings are kept in secrets.py, please add them there!
28-
the secrets dictionary must contain 'ssid' and 'password' at a minimum""")
29-
raise
26+
# Get WiFi details, ensure these are setup in settings.toml
27+
ssid = getenv("CIRCUITPY_WIFI_SSID")
28+
password = getenv("CIRCUITPY_WIFI_PASSWORD")
29+
30+
if None in [ssid, password]:
31+
raise RuntimeError(
32+
"WiFi settings are kept in settings.toml, "
33+
"please add them there. The settings file must contain "
34+
"'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', "
35+
"at a minimum."
36+
)
3037

3138
# Set this to the username you'd like to display tweets from
3239
username = 'codewisdom'
@@ -53,7 +60,7 @@
5360
caption_color=0x808080)
5461

5562
# Set OAuth2.0 Bearer Token
56-
bearer_token = secrets['twitter_bearer_token']
63+
bearer_token = getenv('twitter_bearer_token')
5764
pyportal.set_headers({'Authorization': 'Bearer ' + bearer_token})
5865

5966
while True:

QT_Py/AT_Py_ESP32-S2_Sunrise_Lamp/AIO/code.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5+
from os import getenv
56
import time
67
import ssl
78
import board
@@ -22,26 +23,26 @@
2223
NEO_CNT = 12 # neopixel count
2324
# -------------------------------------------------
2425

26+
# Get WiFi details and Adafruit IO keys, ensure these are setup in settings.toml
27+
# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.)
28+
ssid = getenv("CIRCUITPY_WIFI_SSID")
29+
password = getenv("CIRCUITPY_WIFI_PASSWORD")
30+
aio_username = getenv("ADAFRUIT_AIO_USERNAME")
31+
aio_key = getenv("ADAFRUIT_AIO_KEY")
32+
2533
# Set up NeoPixels
2634
pixels = neopixel.NeoPixel(NEO_PIN, NEO_CNT)
2735

28-
# Get wifi details and more from a secrets.py file
29-
try:
30-
from secrets import secrets
31-
except ImportError:
32-
print("WiFi secrets are kept in secrets.py, please add them there!")
33-
raise
34-
3536
# Setup AIO time query URL
3637
TIME_URL = "https://io.adafruit.com/api/v2/"
37-
TIME_URL += secrets["aio_username"]
38+
TIME_URL += aio_username
3839
TIME_URL += "/integrations/time/strftime?x-aio-key="
39-
TIME_URL += secrets["aio_key"]
40+
TIME_URL += aio_key
4041
TIME_URL += "&fmt=%25Y%3A%25m%3A%25d%3A%25H%3A%25M%3A%25S"
4142

4243
# Connect to local network
4344
try:
44-
wifi.radio.connect(secrets["ssid"], secrets["password"])
45+
wifi.radio.connect(ssid, password)
4546
except ConnectionError:
4647
print("Wifi failed to connect.")
4748
while True:

QT_Py/AT_Py_ESP32-S2_Sunrise_Lamp/NTP/code.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5+
from os import getenv
56
import time
67
import board
78
import rtc
@@ -25,16 +26,13 @@
2526
# Set up NeoPixels
2627
pixels = neopixel.NeoPixel(NEO_PIN, NEO_CNT)
2728

28-
# Get wifi details and more from a secrets.py file
29-
try:
30-
from secrets import secrets
31-
except ImportError:
32-
print("WiFi secrets are kept in secrets.py, please add them there!")
33-
raise
29+
# Get WiFi details, ensure these are setup in settings.toml
30+
ssid = getenv("CIRCUITPY_WIFI_SSID")
31+
password = getenv("CIRCUITPY_WIFI_PASSWORD")
3432

3533
# Connect to local network
3634
try:
37-
wifi.radio.connect(secrets["ssid"], secrets["password"])
35+
wifi.radio.connect(ssid, password)
3836
except ConnectionError:
3937
print("Wifi failed to connect.")
4038
while True:

0 commit comments

Comments
 (0)