Skip to content

Commit b42f593

Browse files
committed
Update OpenSky-Network Private Single Flight API Example with Connection Manager
1 parent 231e2eb commit b42f593

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

examples/wifi/expanded/requests_wifi_api_openskynetwork_private.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-FileCopyrightText: 2024 DJDevon3
22
# SPDX-License-Identifier: MIT
33
# Coded for Circuit Python 8.2.x
4-
"""OpenSky-Network.org Private API Example"""
4+
"""OpenSky-Network.org Single Flight Private API Example"""
55
# pylint: disable=import-error
66

77
import os
@@ -18,7 +18,7 @@
1818
# All active flights JSON: https://opensky-network.org/api/states/all # PICK ONE! :)
1919
# JSON order: transponder, callsign, country
2020
# ACTIVE transpondes only, for multiple "c822af&icao24=cb3993&icao24=c63923"
21-
TRANSPONDER = "471efd"
21+
TRANSPONDER = "4b1806"
2222

2323
# Get WiFi details, ensure these are setup in settings.toml
2424
ssid = os.getenv("CIRCUITPY_WIFI_SSID")
@@ -46,7 +46,7 @@
4646
OSN_CREDENTIALS_B = b"" + str(OSN_CREDENTIALS) + ""
4747
BASE64_ASCII = b2a_base64(OSN_CREDENTIALS_B)
4848
BASE64_STRING = str(BASE64_ASCII) # bytearray
49-
TRUNCATED_BASE64_STRING = BASE64_STRING[2:-1] # truncate bytearray head/tail
49+
TRUNCATED_BASE64_STRING = BASE64_STRING[2:-3] # truncate bytearray head/tail
5050

5151
if DEBUG:
5252
print("Original Binary Data: ", OSN_CREDENTIALS_B)
@@ -56,7 +56,7 @@
5656
# Requests URL - icao24 is their endpoint required for a transponder
5757
# example https://opensky-network.org/api/states/all?icao24=a808c5
5858
# OSN private: requires your website username:password to be base64 encoded
59-
OSN_HEADER = {"Authorization": "Basic " + str(TRUNCATED_BASE64_STRING)}
59+
OPENSKY_HEADER = {"Authorization": "Basic " + str(TRUNCATED_BASE64_STRING)}
6060
OPENSKY_SOURCE = "https://opensky-network.org/api/states/all?" + "icao24=" + TRANSPONDER
6161

6262

@@ -94,9 +94,10 @@ def _format_datetime(datetime):
9494
print("✅ Wifi!")
9595

9696
try:
97-
print(" | Attempting to GET OpenSky-Network Single Flight JSON!")
97+
print(" | Attempting to GET OpenSky-Network Single Private Flight JSON!")
98+
print(" | Website Credentials Required! Allows more daily calls than Public.")
9899
try:
99-
opensky_response = requests.get(url=OPENSKY_SOURCE, headers=OSN_HEADER)
100+
opensky_response = requests.get(url=OPENSKY_SOURCE, headers=OPENSKY_HEADER)
100101
opensky_json = opensky_response.json()
101102
except ConnectionError as e:
102103
print("Connection Error:", e)
@@ -106,6 +107,7 @@ def _format_datetime(datetime):
106107

107108
if DEBUG:
108109
print("Full API GET URL: ", OPENSKY_SOURCE)
110+
print("Full API GET Header: ", OPENSKY_HEADER)
109111
print(opensky_json)
110112

111113
# ERROR MESSAGE RESPONSES
@@ -134,7 +136,7 @@ def _format_datetime(datetime):
134136

135137
if osn_single_flight_data is not None:
136138
if DEBUG:
137-
print(f" | | Single Flight Data: {osn_single_flight_data}")
139+
print(f" | | Single Private Flight Data: {osn_single_flight_data}")
138140

139141
last_contact = opensky_json["states"][0][4]
140142
# print(f" | | Last Contact Unix Time: {last_contact}")

0 commit comments

Comments
 (0)