Skip to content

Secrets Cleanup Q-W #3016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Minesweep/.circuitpython.skip

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion Minesweep/code.py → PyPortal/Minesweep/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def play_a_game():
set_data(touch_x, touch_y, BOMBDEATH) #reveal a red bomb
tilegrid[touch_x, touch_y] = BOMBDEATH
return False #lost
elif under_the_tile > OPEN0 and under_the_tile <= OPEN8:
elif OPEN0 < under_the_tile <= OPEN8:
tilegrid[touch_x, touch_y] = under_the_tile
elif under_the_tile == OPEN0:
tilegrid[touch_x, touch_y] = BLANK
Expand Down
File renamed without changes.
File renamed without changes.
21 changes: 14 additions & 7 deletions Twitter_API/code.py → PyPortal/Twitter_API/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,23 @@
"""

#pylint:disable=invalid-name

from os import getenv
import time
import board
from adafruit_pyportal import PyPortal

try:
from secrets import secrets
except ImportError:
print("""WiFi settings are kept in secrets.py, please add them there!
the secrets dictionary must contain 'ssid' and 'password' at a minimum""")
raise
# Get WiFi details, ensure these are setup in settings.toml
ssid = getenv("CIRCUITPY_WIFI_SSID")
password = getenv("CIRCUITPY_WIFI_PASSWORD")

if None in [ssid, password]:
raise RuntimeError(
"WiFi settings are kept in settings.toml, "
"please add them there. The settings file must contain "
"'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', "
"at a minimum."
)

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

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

while True:
Expand Down
21 changes: 11 additions & 10 deletions QT_Py/AT_Py_ESP32-S2_Sunrise_Lamp/AIO/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# SPDX-License-Identifier: MIT

from os import getenv
import time
import ssl
import board
Expand All @@ -22,26 +23,26 @@
NEO_CNT = 12 # neopixel count
# -------------------------------------------------

# Get WiFi details and Adafruit IO keys, ensure these are setup in settings.toml
# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.)
ssid = getenv("CIRCUITPY_WIFI_SSID")
password = getenv("CIRCUITPY_WIFI_PASSWORD")
aio_username = getenv("ADAFRUIT_AIO_USERNAME")
aio_key = getenv("ADAFRUIT_AIO_KEY")

# Set up NeoPixels
pixels = neopixel.NeoPixel(NEO_PIN, NEO_CNT)

# Get wifi details and more from a secrets.py file
try:
from secrets import secrets
except ImportError:
print("WiFi secrets are kept in secrets.py, please add them there!")
raise

# Setup AIO time query URL
TIME_URL = "https://io.adafruit.com/api/v2/"
TIME_URL += secrets["aio_username"]
TIME_URL += aio_username
TIME_URL += "/integrations/time/strftime?x-aio-key="
TIME_URL += secrets["aio_key"]
TIME_URL += aio_key
TIME_URL += "&fmt=%25Y%3A%25m%3A%25d%3A%25H%3A%25M%3A%25S"

# Connect to local network
try:
wifi.radio.connect(secrets["ssid"], secrets["password"])
wifi.radio.connect(ssid, password)
except ConnectionError:
print("Wifi failed to connect.")
while True:
Expand Down
12 changes: 5 additions & 7 deletions QT_Py/AT_Py_ESP32-S2_Sunrise_Lamp/NTP/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# SPDX-License-Identifier: MIT

from os import getenv
import time
import board
import rtc
Expand All @@ -25,16 +26,13 @@
# Set up NeoPixels
pixels = neopixel.NeoPixel(NEO_PIN, NEO_CNT)

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

# Connect to local network
try:
wifi.radio.connect(secrets["ssid"], secrets["password"])
wifi.radio.connect(ssid, password)
except ConnectionError:
print("Wifi failed to connect.")
while True:
Expand Down
28 changes: 22 additions & 6 deletions QT_Py/QT_Py_Cube/code.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# SPDX-FileCopyrightText: 2022 Charlyn Gonda for Adafruit Industries
#
# SPDX-License-Identifier: MIT
from secrets import secrets

from os import getenv
import ssl
import busio
import board
Expand All @@ -16,6 +17,21 @@

from cube import Cube

# Get WiFi details and Adafruit IO keys, ensure these are setup in settings.toml
# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.)
ssid = getenv("CIRCUITPY_WIFI_SSID")
password = getenv("CIRCUITPY_WIFI_PASSWORD")
aio_username = getenv("ADAFRUIT_AIO_USERNAME")
aio_key = getenv("ADAFRUIT_AIO_KEY")

if None in [ssid, password, aio_username, aio_key]:
raise RuntimeError(
"WiFi and Adafruit IO settings are kept in settings.toml, "
"please add them there. The settings file must contain "
"'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', "
"'ADAFRUIT_AIO_USERNAME' and 'ADAFRUIT_AIO_KEY' at a minimum."
)

# Specify pins
top_cin = board.A0
top_din = board.A1
Expand All @@ -42,9 +58,9 @@
connected = False
while not connected:
try:
wifi.radio.connect(secrets["ssid"], secrets["password"])
print("Connected to %s!" % secrets["ssid"])
print("My IP address is", wifi.radio.ipv4_address)
wifi.radio.connect(ssid, password)
print(f"Connected to {ssid}!")
print(f"My IP address is {wifi.radio.ipv4_address}")
connected = True
# pylint: disable=broad-except
except Exception as error:
Expand All @@ -54,8 +70,8 @@

# Setup for http requests
pool = socketpool.SocketPool(wifi.radio)
REQUESTS = adafruit_requests.Session(pool, ssl.create_default_context())
IO = IO_HTTP(secrets["aio_username"], secrets["aio_key"], REQUESTS)
requests = adafruit_requests.Session(pool, ssl.create_default_context())
IO = IO_HTTP(aio_username, aio_key, requests)

# Data for top pixels, will be updated by update_data()
TOP_PIXELS_ON = []
Expand Down
24 changes: 15 additions & 9 deletions Raspberry_Pi_Azure_IoT_Hub_Dashboard/featherTft_bme680/code.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries
# SPDX-License-Identifier: MIT

from os import getenv
import json
import time
import digitalio
Expand All @@ -17,18 +18,23 @@
from adafruit_display_text import bitmap_label, wrap_text_to_lines
from adafruit_bitmap_font import bitmap_font
from adafruit_azureiot import IoTHubDevice
import adafruit_bme680
from adafruit_lc709203f import LC709203F, PackSize
import adafruit_bme680

# Get WiFi details, ensure these are setup in settings.toml
ssid = getenv("CIRCUITPY_WIFI_SSID")
password = getenv("CIRCUITPY_WIFI_PASSWORD")

# Get wifi details and more from a secrets.py file
try:
from secrets import secrets
except ImportError:
print("WiFi secrets are kept in secrets.py, please add them there!")
raise
if None in [ssid, password]:
raise RuntimeError(
"WiFi settings are kept in settings.toml, "
"please add them there. The settings file must contain "
"'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', "
"at a minimum."
)

print("Connecting to WiFi...")
wifi.radio.connect(secrets["ssid"], secrets["password"])
wifi.radio.connect(ssid, password)

print("Connected to WiFi!")

Expand All @@ -47,7 +53,7 @@
esp = None
pool = socketpool.SocketPool(wifi.radio)
# Create an IoT Hub device client and connect
device = IoTHubDevice(pool, esp, secrets["device_connection_string"])
device = IoTHubDevice(pool, esp, getenv("device_connection_string"))

print("Connecting to Azure IoT Hub...")

Expand Down
22 changes: 14 additions & 8 deletions Raspberry_Pi_Azure_IoT_Hub_Dashboard/qtPyEsp32S2_co2/code.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries
# SPDX-License-Identifier: MIT

from os import getenv
import time
import json
import digitalio
Expand All @@ -13,15 +14,20 @@
from adafruit_azureiot import IoTHubDevice
import adafruit_scd4x

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

if None in [ssid, password]:
raise RuntimeError(
"WiFi settings are kept in settings.toml, "
"please add them there. The settings file must contain "
"'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', "
"at a minimum."
)

print("Connecting to WiFi...")
wifi.radio.connect(secrets["ssid"], secrets["password"])
wifi.radio.connect(ssid, password)

print("Connected to WiFi!")

Expand All @@ -40,7 +46,7 @@
esp = None
pool = socketpool.SocketPool(wifi.radio)
# Create an IoT Hub device client and connect
device = IoTHubDevice(pool, esp, secrets["device_connection_string"])
device = IoTHubDevice(pool, esp, getenv("device_connection_string"))

print("Connecting to Azure IoT Hub...")

Expand Down
39 changes: 23 additions & 16 deletions Shadow_Box/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,35 @@
"""
Clock & sky colorbox for Adafruit MagTag: displays current time while
NeoPixels provide theme lighting for the time of day. Requires WiFi
internet access -- configure credentials in secrets.py. An Adafruit IO
internet access -- configure credentials in settings.toml. An Adafruit IO
user name and API key are also needed there, plus timezone and
geographic coords.
"""

# pylint: disable=import-error

from os import getenv
import time
import json
import board
import neopixel
from adafruit_magtag.magtag import MagTag
import adafruit_fancyled.adafruit_fancyled as fancy

# UTC offset queries require some info from the secrets table...
try:
from secrets import secrets
except ImportError:
print('Please set up secrets.py with network credentials.')
# Get WiFi details and Adafruit IO keys, ensure these are setup in settings.toml
# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.)
ssid = getenv("CIRCUITPY_WIFI_SSID")
password = getenv("CIRCUITPY_WIFI_PASSWORD")
aio_username = getenv("ADAFRUIT_AIO_USERNAME")
aio_key = getenv("ADAFRUIT_AIO_KEY")

if None in [ssid, password, aio_username, aio_key]:
raise RuntimeError(
"WiFi and Adafruit IO settings are kept in settings.toml, "
"please add them there. The settings file must contain "
"'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', "
"'ADAFRUIT_AIO_USERNAME' and 'ADAFRUIT_AIO_KEY' at a minimum."
)

# CONFIGURABLE SETTINGS ----------------------------------------------------

Expand Down Expand Up @@ -179,16 +189,13 @@ def blend(palette1, palette2, weight2, offset):
# Since time is synced only once per hour, the extra request
# isn't particularly burdensome.
try:
RESPONSE = MAGTAG.network.requests.get(
'https://io.adafruit.com/api/v2/%s/integrations/time/'
'strftime?x-aio-key=%s&tz=%s' % (secrets.get('aio_username'),
secrets.get('aio_key'),
secrets.get('timezone')) +
'&fmt=%25z')
if RESPONSE.status_code == 200:
url = f"https://io.adafruit.com/api/v2/{aio_username}/integrations/time/strftime"
url += f'x-aio-key={aio_key}tz={getenv("timezone")}&fmt=%25z'
response = MAGTAG.network.requests.get(url)
if response.status_code == 200:
# Arrives as sHHMM, convert to sHH:MM
print(RESPONSE.text)
UTC_OFFSET = RESPONSE.text[:3] + ':' + RESPONSE.text[-2:]
print(response.text)
UTC_OFFSET = response.text[:3] + ':' + response.text[-2:]
except: # pylint: disable=bare-except
# If query fails, prior value is kept until next query.
# Only changes 2X a year anyway -- worst case, if these
Expand Down Expand Up @@ -217,7 +224,7 @@ def blend(palette1, palette2, weight2, offset):
try:
URL = ('https://api.met.no/weatherapi/sunrise/2.0/.json?'
'lat=%s&lon=%s&date=%s-%s-%s&offset=%s' %
(secrets.get('latitude'), secrets.get('longitude'),
(getenv('latitude'), getenv('longitude'),
str(NOW.tm_year), '{0:0>2}'.format(NOW.tm_mon),
'{0:0>2}'.format(NOW.tm_mday), UTC_OFFSET))
print('Fetching sun data via', URL)
Expand Down
Loading