|
4 | 4 | """DJDevon3 Adafruit Feather ESP32-S2 Github_API_Example""" |
5 | 5 | import gc |
6 | 6 | import json |
| 7 | +import os |
7 | 8 | import ssl |
8 | 9 | import time |
9 | 10 |
|
|
12 | 13 |
|
13 | 14 | import adafruit_requests |
14 | 15 |
|
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 | | - |
20 | 16 | # Initialize WiFi Pool (There can be only 1 pool & top of script) |
21 | 17 | pool = socketpool.SocketPool(wifi.radio) |
22 | 18 |
|
23 | 19 | # Time between API refreshes |
24 | 20 | # 900 = 15 mins, 1800 = 30 mins, 3600 = 1 hour |
25 | 21 | sleep_time = 900 |
26 | 22 |
|
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") |
32 | 29 |
|
33 | 30 | if sleep_time < 60: |
34 | 31 | sleep_time_conversion = "seconds" |
|
43 | 40 | sleep_int = sleep_time / 60 / 60 / 24 |
44 | 41 | sleep_time_conversion = "days" |
45 | 42 |
|
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 |
48 | 45 |
|
49 | 46 | # Connect to Wi-Fi |
50 | 47 | print("\n===============================") |
51 | 48 | print("Connecting to WiFi...") |
52 | 49 | requests = adafruit_requests.Session(pool, ssl.create_default_context()) |
53 | 50 | while not wifi.radio.ipv4_address: |
54 | 51 | try: |
55 | | - wifi.radio.connect(secrets["ssid"], secrets["password"]) |
| 52 | + wifi.radio.connect(ssid, appw) |
56 | 53 | except ConnectionError as e: |
57 | 54 | print("Connection Error:", e) |
58 | 55 | print("Retrying in 10 seconds") |
|
0 commit comments