Skip to content

Commit 65d8f70

Browse files
committed
Don't use secrets.py
1 parent 4f98554 commit 65d8f70

14 files changed

+62
-130
lines changed

examples/requests_wifi_adafruit_discord_active_online.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
# 600 = 10 mins, 900 = 15 mins, 1800 = 30 mins, 3600 = 1 hour
2727
sleep_time = 900
2828

29-
# this example uses settings.toml for credentials
30-
ssid = os.getenv("WIFI_SSID")
31-
appw = os.getenv("WIFI_PASSWORD")
29+
# Get WiFi details, ensure these are setup in settings.toml
30+
ssid = os.getenv("CIRCUITPY_WIFI_SSID")
31+
appw = os.getenv("CIRCUITPY_WIFI_PASSWORD")
3232

3333

3434
# Converts seconds to minutes/hours/days

examples/requests_wifi_api_discord.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# Ensure this is in settings.toml
2020
# "Discord_Authorization": "Request Header Auth here"
2121

22-
# Uses settings.toml for credentials
22+
# Get WiFi details, ensure these are setup in settings.toml
2323
ssid = os.getenv("CIRCUITPY_WIFI_SSID")
2424
appw = os.getenv("CIRCUITPY_WIFI_PASSWORD")
2525
Discord_Auth = os.getenv("Discord_Authorization")

examples/requests_wifi_api_fitbit.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,17 @@
3636
# Fitbit_First_Refresh_Token = "64 character string"
3737
# Fitbit_UserID = "UserID authorizing the ClientID"
3838

39+
# Get WiFi details, ensure these are setup in settings.toml
40+
ssid = os.getenv("CIRCUITPY_WIFI_SSID")
41+
appw = os.getenv("CIRCUITPY_WIFI_PASSWORD")
42+
3943
Fitbit_ClientID = os.getenv("Fitbit_ClientID")
4044
Fitbit_Token = os.getenv("Fitbit_Token")
4145
Fitbit_First_Refresh_Token = os.getenv(
4246
"Fitbit_First_Refresh_Token"
4347
) # overides nvm first run only
4448
Fitbit_UserID = os.getenv("Fitbit_UserID")
4549

46-
wifi_ssid = os.getenv("CIRCUITPY_WIFI_SSID")
47-
wifi_pw = os.getenv("CIRCUITPY_WIFI_PASSWORD")
48-
4950
# Time between API refreshes
5051
# 300 = 5 mins, 900 = 15 mins, 1800 = 30 mins, 3600 = 1 hour
5152
sleep_time = 900
@@ -78,7 +79,7 @@ def time_calc(input_time):
7879
requests = adafruit_requests.Session(pool, ssl.create_default_context())
7980
while not wifi.radio.ipv4_address:
8081
try:
81-
wifi.radio.connect(wifi_ssid, wifi_pw)
82+
wifi.radio.connect(ssid, appw)
8283
except ConnectionError as e:
8384
print("Connection Error:", e)
8485
print("Retrying in 10 seconds")

examples/requests_wifi_api_github.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""DJDevon3 Adafruit Feather ESP32-S2 Github_API_Example"""
55
import gc
66
import json
7+
import os
78
import ssl
89
import time
910

@@ -12,23 +13,19 @@
1213

1314
import adafruit_requests
1415

15-
# Github developer token required.
16-
# Ensure these are uncommented and in secrets.py or .env
17-
# "Github_username": "Your Github Username",
18-
# "Github_token": "Your long API token",
19-
2016
# Initialize WiFi Pool (There can be only 1 pool & top of script)
2117
pool = socketpool.SocketPool(wifi.radio)
2218

2319
# Time between API refreshes
2420
# 900 = 15 mins, 1800 = 30 mins, 3600 = 1 hour
2521
sleep_time = 900
2622

27-
try:
28-
from secrets import secrets
29-
except ImportError:
30-
print("Secrets File Import Error")
31-
raise
23+
# Get WiFi details, ensure these are setup in settings.toml
24+
ssid = os.getenv("CIRCUITPY_WIFI_SSID")
25+
appw = os.getenv("CIRCUITPY_WIFI_PASSWORD")
26+
# Github developer token required.
27+
github_username = os.getenv("Github_username")
28+
github_token = os.getenv("Github_token")
3229

3330
if sleep_time < 60:
3431
sleep_time_conversion = "seconds"
@@ -43,16 +40,16 @@
4340
sleep_int = sleep_time / 60 / 60 / 24
4441
sleep_time_conversion = "days"
4542

46-
github_header = {"Authorization": " token " + secrets["Github_token"]}
47-
GH_SOURCE = "https://api.github.com/users/" + secrets["Github_username"]
43+
github_header = {"Authorization": " token " + github_token}
44+
GH_SOURCE = "https://api.github.com/users/" + github_username
4845

4946
# Connect to Wi-Fi
5047
print("\n===============================")
5148
print("Connecting to WiFi...")
5249
requests = adafruit_requests.Session(pool, ssl.create_default_context())
5350
while not wifi.radio.ipv4_address:
5451
try:
55-
wifi.radio.connect(secrets["ssid"], secrets["password"])
52+
wifi.radio.connect(ssid, appw)
5653
except ConnectionError as e:
5754
print("Connection Error:", e)
5855
print("Retrying in 10 seconds")

examples/requests_wifi_api_mastodon.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Coded for Circuit Python 8.0
44
"""DJDevon3 Adafruit Feather ESP32-S2 Mastodon_API_Example"""
55
import gc
6+
import os
67
import ssl
78
import time
89

@@ -29,11 +30,9 @@
2930
# 900 = 15 mins, 1800 = 30 mins, 3600 = 1 hour
3031
sleep_time = 900
3132

32-
try:
33-
from secrets import secrets
34-
except ImportError:
35-
print("Secrets File Import Error")
36-
raise
33+
# Get WiFi details, ensure these are setup in settings.toml
34+
ssid = os.getenv("CIRCUITPY_WIFI_SSID")
35+
appw = os.getenv("CIRCUITPY_WIFI_PASSWORD")
3736

3837

3938
# Converts seconds in minutes/hours/days
@@ -71,7 +70,7 @@ def time_calc(input_time):
7170
requests = adafruit_requests.Session(pool, ssl.create_default_context())
7271
while not wifi.radio.ipv4_address:
7372
try:
74-
wifi.radio.connect(secrets["ssid"], secrets["password"])
73+
wifi.radio.connect(ssid, appw)
7574
except ConnectionError as e:
7675
print("Connection Error:", e)
7776
print("Retrying in 10 seconds")

examples/requests_wifi_api_openskynetwork_private.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@
3030
# https://openskynetwork.github.io/opensky-api/rest.html#limitations
3131
sleep_time = 1800
3232

33-
# this example uses settings.toml for credentials
34-
# timezone offset is in seconds plus or minus GMT
35-
ssid = os.getenv("AP_SSID")
36-
appw = os.getenv("AP_PASSWORD")
33+
# Get WiFi details, ensure these are setup in settings.toml
34+
ssid = os.getenv("CIRCUITPY_WIFI_SSID")
35+
appw = os.getenv("CIRCUITPY_WIFI_PASSWORD")
3736
osnu = os.getenv("OSN_Username")
3837
osnp = os.getenv("OSN_Password")
3938

examples/requests_wifi_api_openskynetwork_private_area.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
# https://openskynetwork.github.io/opensky-api/rest.html#limitations
3333
sleep_time = 1800
3434

35-
# this example uses settings.toml for credentials
35+
# Get WiFi details, ensure these are setup in settings.toml
36+
ssid = os.getenv("CIRCUITPY_WIFI_SSID")
37+
appw = os.getenv("CIRCUITPY_WIFI_PASSWORD")
3638
# No token required, only website login
37-
ssid = os.getenv("AP_SSID")
38-
appw = os.getenv("AP_PASSWORD")
3939
osnu = os.getenv("OSN_Username")
4040
osnp = os.getenv("OSN_Password")
4141

examples/requests_wifi_api_openskynetwork_public.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
# https://openskynetwork.github.io/opensky-api/rest.html#limitations
2929
sleep_time = 1800
3030

31-
# Wifi credentials pulled from settings.toml
32-
ssid = os.getenv("AP_SSID")
33-
appw = os.getenv("AP_PASSWORD")
31+
# Get WiFi details, ensure these are setup in settings.toml
32+
ssid = os.getenv("CIRCUITPY_WIFI_SSID")
33+
appw = os.getenv("CIRCUITPY_WIFI_PASSWORD")
3434

3535
# Requests URL - icao24 is their endpoint required for a transponder
3636
# example https://opensky-network.org/api/states/all?icao24=a808c5

examples/requests_wifi_api_steam.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
# Steam Usernumber: Visit https://steamcommunity.com
1919
# click on your profile icon, your usernumber will be in the browser url.
2020

21-
# Ensure these are setup in settings.toml
21+
# Get WiFi details, ensure these are setup in settings.toml
22+
ssid = os.getenv("CIRCUITPY_WIFI_SSID")
23+
appw = os.getenv("CIRCUITPY_WIFI_PASSWORD")
2224
# Requires Steam Developer API key
23-
ssid = os.getenv("AP_SSID")
24-
appw = os.getenv("AP_PASSWORD")
2525
steam_usernumber = os.getenv("steam_id")
2626
steam_apikey = os.getenv("steam_api_key")
2727

examples/requests_wifi_api_twitch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# "Twitch_Client_Secret": "APP ID secret here",
2424
# "Twitch_UserID": "Your Twitch UserID here",
2525

26-
# Use settings.toml for credentials
26+
# Get WiFi details, ensure these are setup in settings.toml
2727
ssid = os.getenv("CIRCUITPY_WIFI_SSID")
2828
appw = os.getenv("CIRCUITPY_WIFI_PASSWORD")
2929
twitch_client_id = os.getenv("Twitch_ClientID")

examples/requests_wifi_api_twitter.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""DJDevon3 Adafruit Feather ESP32-S2 Twitter_API_Example"""
55
import gc
66
import json
7+
import os
78
import ssl
89
import time
910

@@ -24,11 +25,11 @@
2425
# 900 = 15 mins, 1800 = 30 mins, 3600 = 1 hour
2526
sleep_time = 900
2627

27-
try:
28-
from secrets import secrets
29-
except ImportError:
30-
print("Secrets File Import Error")
31-
raise
28+
# Get WiFi details, ensure these are setup in settings.toml
29+
ssid = os.getenv("CIRCUITPY_WIFI_SSID")
30+
appw = os.getenv("CIRCUITPY_WIFI_PASSWORD")
31+
tw_userid = os.getenv("TW_userid")
32+
tw_bearer_token = os.getenv("TW_bearer_token")
3233

3334
if sleep_time < 60:
3435
sleep_time_conversion = "seconds"
@@ -44,10 +45,10 @@
4445
sleep_time_conversion = "days"
4546

4647
# Used with any Twitter 0auth request.
47-
twitter_header = {"Authorization": "Bearer " + secrets["TW_bearer_token"]}
48+
twitter_header = {"Authorization": "Bearer " + tw_bearer_token}
4849
TW_SOURCE = (
4950
"https://api.twitter.com/2/users/"
50-
+ secrets["TW_userid"]
51+
+ tw_userid
5152
+ "?user.fields=public_metrics,created_at,pinned_tweet_id"
5253
+ "&expansions=pinned_tweet_id"
5354
+ "&tweet.fields=created_at,public_metrics,source,context_annotations,entities"
@@ -59,7 +60,7 @@
5960
requests = adafruit_requests.Session(pool, ssl.create_default_context())
6061
while not wifi.radio.ipv4_address:
6162
try:
62-
wifi.radio.connect(secrets["ssid"], secrets["password"])
63+
wifi.radio.connect(ssid, appw)
6364
except ConnectionError as e:
6465
print("Connection Error:", e)
6566
print("Retrying in 10 seconds")

examples/requests_wifi_api_youtube.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""DJDevon3 Adafruit Feather ESP32-S2 YouTube_API_Example"""
55
import gc
66
import json
7+
import os
78
import ssl
89
import time
910

@@ -23,11 +24,12 @@
2324
# 900 = 15 mins, 1800 = 30 mins, 3600 = 1 hour
2425
sleep_time = 900
2526

26-
try:
27-
from secrets import secrets
28-
except ImportError:
29-
print("Secrets File Import Error")
30-
raise
27+
# Get WiFi details, ensure these are setup in settings.toml
28+
ssid = os.getenv("CIRCUITPY_WIFI_SSID")
29+
appw = os.getenv("CIRCUITPY_WIFI_PASSWORD")
30+
yt_username = os.getenv("YT_username")
31+
yt_token = os.getenv("YT_token")
32+
3133

3234
if sleep_time < 60:
3335
sleep_time_conversion = "seconds"
@@ -47,9 +49,9 @@
4749
"https://youtube.googleapis.com/youtube/v3/channels?"
4850
+ "part=statistics"
4951
+ "&forUsername="
50-
+ secrets["YT_username"]
52+
+ yt_username
5153
+ "&key="
52-
+ secrets["YT_token"]
54+
+ yt_token
5355
)
5456

5557
# Connect to Wi-Fi
@@ -58,7 +60,7 @@
5860
requests = adafruit_requests.Session(pool, ssl.create_default_context())
5961
while not wifi.radio.ipv4_address:
6062
try:
61-
wifi.radio.connect(secrets["ssid"], secrets["password"])
63+
wifi.radio.connect(ssid, appw)
6264
except ConnectionError as e:
6365
print("Connection Error:", e)
6466
print("Retrying in 10 seconds")

examples/requests_wifi_https_circuitpython.py

Lines changed: 0 additions & 65 deletions
This file was deleted.

examples/requests_wifi_multiple_cookies.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
for connecting to the internet depending on your device.
77
"""
88

9+
import os
910
import ssl
1011

1112
import socketpool
@@ -15,16 +16,13 @@
1516

1617
COOKIE_TEST_URL = "https://www.adafruit.com"
1718

18-
# Get wifi details and more from a secrets.py file
19-
try:
20-
from secrets import secrets
21-
except ImportError:
22-
print("WiFi secrets are kept in secrets.py, please add them there!")
23-
raise
19+
# Get WiFi details, ensure these are setup in settings.toml
20+
ssid = os.getenv("CIRCUITPY_WIFI_SSID")
21+
appw = os.getenv("CIRCUITPY_WIFI_PASSWORD")
2422

2523
# Connect to the Wi-Fi network
26-
print("Connecting to %s" % secrets["ssid"])
27-
wifi.radio.connect(secrets["ssid"], secrets["password"])
24+
print("Connecting to %s" % ssid)
25+
wifi.radio.connect(ssid, appw)
2826

2927
# Set up the requests library
3028
pool = socketpool.SocketPool(wifi.radio)

0 commit comments

Comments
 (0)