Skip to content

Commit 6d627d9

Browse files
committed
update with requested changes
1 parent ca41b26 commit 6d627d9

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

examples/wifi/expanded/requests_wifi_api_openskynetwork_private.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# SPDX-License-Identifier: MIT
33
# Coded for Circuit Python 8.2.x
44
"""OpenSky-Network.org Single Flight Private API Example"""
5-
# pylint: disable=import-error
65

76
import binascii
87
import os
@@ -18,7 +17,7 @@
1817
# All active flights JSON: https://opensky-network.org/api/states/all # PICK ONE! :)
1918
# JSON order: transponder, callsign, country
2019
# ACTIVE transpondes only, for multiple "c822af&icao24=cb3993&icao24=c63923"
21-
TRANSPONDER = "ad4f1c"
20+
TRANSPONDER = "4b1812"
2221

2322
# Get WiFi details, ensure these are setup in settings.toml
2423
ssid = os.getenv("CIRCUITPY_WIFI_SSID")
@@ -44,18 +43,17 @@
4443
# -- Base64 Conversion --
4544
OSN_CREDENTIALS = str(osnusername) + ":" + str(osnpassword)
4645
# base64 encode and strip appended \n from bytearray
47-
OSN_CREDENTIALS_B = binascii.b2a_base64(b"" + str(OSN_CREDENTIALS)).strip()
48-
BASE64_STRING = str(OSN_CREDENTIALS_B) # bytearray
49-
SLICED_BASE64_STRING = BASE64_STRING[2:-1] # slice bytearray head/tail
46+
OSN_CREDENTIALS_B = binascii.b2a_base64(OSN_CREDENTIALS.encode()).strip()
47+
BASE64_STRING = OSN_CREDENTIALS_B.decode() # bytearray
48+
5049

5150
if DEBUG:
5251
print("Base64 ByteArray: ", BASE64_STRING)
53-
print(f"Base64 Sliced String: {SLICED_BASE64_STRING}")
5452

5553
# Requests URL - icao24 is their endpoint required for a transponder
5654
# example https://opensky-network.org/api/states/all?icao24=a808c5
5755
# OSN private: requires your website username:password to be base64 encoded
58-
OPENSKY_HEADER = {"Authorization": "Basic " + str(SLICED_BASE64_STRING)}
56+
OPENSKY_HEADER = {"Authorization": "Basic " + BASE64_STRING}
5957
OPENSKY_SOURCE = "https://opensky-network.org/api/states/all?" + "icao24=" + TRANSPONDER
6058

6159

0 commit comments

Comments
 (0)