|
2 | 2 | # SPDX-License-Identifier: MIT |
3 | 3 | # Coded for Circuit Python 8.2.x |
4 | 4 | """OpenSky-Network.org Single Flight Private API Example""" |
5 | | -# pylint: disable=import-error |
6 | 5 |
|
7 | 6 | import binascii |
8 | 7 | import os |
|
18 | 17 | # All active flights JSON: https://opensky-network.org/api/states/all # PICK ONE! :) |
19 | 18 | # JSON order: transponder, callsign, country |
20 | 19 | # ACTIVE transpondes only, for multiple "c822af&icao24=cb3993&icao24=c63923" |
21 | | -TRANSPONDER = "ad4f1c" |
| 20 | +TRANSPONDER = "4b1812" |
22 | 21 |
|
23 | 22 | # Get WiFi details, ensure these are setup in settings.toml |
24 | 23 | ssid = os.getenv("CIRCUITPY_WIFI_SSID") |
|
44 | 43 | # -- Base64 Conversion -- |
45 | 44 | OSN_CREDENTIALS = str(osnusername) + ":" + str(osnpassword) |
46 | 45 | # 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 | + |
50 | 49 |
|
51 | 50 | if DEBUG: |
52 | 51 | print("Base64 ByteArray: ", BASE64_STRING) |
53 | | - print(f"Base64 Sliced String: {SLICED_BASE64_STRING}") |
54 | 52 |
|
55 | 53 | # Requests URL - icao24 is their endpoint required for a transponder |
56 | 54 | # example https://opensky-network.org/api/states/all?icao24=a808c5 |
57 | 55 | # 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} |
59 | 57 | OPENSKY_SOURCE = "https://opensky-network.org/api/states/all?" + "icao24=" + TRANSPONDER |
60 | 58 |
|
61 | 59 |
|
|
0 commit comments