1
1
# SPDX-FileCopyrightText: 2024 DJDevon3
2
2
# SPDX-License-Identifier: MIT
3
3
# Coded for Circuit Python 8.2.x
4
- """OpenSky-Network.org Private API Example"""
4
+ """OpenSky-Network.org Single Flight Private API Example"""
5
5
# pylint: disable=import-error
6
6
7
7
import os
18
18
# All active flights JSON: https://opensky-network.org/api/states/all # PICK ONE! :)
19
19
# JSON order: transponder, callsign, country
20
20
# ACTIVE transpondes only, for multiple "c822af&icao24=cb3993&icao24=c63923"
21
- TRANSPONDER = "471efd "
21
+ TRANSPONDER = "4b1806 "
22
22
23
23
# Get WiFi details, ensure these are setup in settings.toml
24
24
ssid = os .getenv ("CIRCUITPY_WIFI_SSID" )
46
46
OSN_CREDENTIALS_B = b"" + str (OSN_CREDENTIALS ) + ""
47
47
BASE64_ASCII = b2a_base64 (OSN_CREDENTIALS_B )
48
48
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
50
50
51
51
if DEBUG :
52
52
print ("Original Binary Data: " , OSN_CREDENTIALS_B )
56
56
# Requests URL - icao24 is their endpoint required for a transponder
57
57
# example https://opensky-network.org/api/states/all?icao24=a808c5
58
58
# 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 )}
60
60
OPENSKY_SOURCE = "https://opensky-network.org/api/states/all?" + "icao24=" + TRANSPONDER
61
61
62
62
@@ -94,9 +94,10 @@ def _format_datetime(datetime):
94
94
print ("✅ Wifi!" )
95
95
96
96
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." )
98
99
try :
99
- opensky_response = requests .get (url = OPENSKY_SOURCE , headers = OSN_HEADER )
100
+ opensky_response = requests .get (url = OPENSKY_SOURCE , headers = OPENSKY_HEADER )
100
101
opensky_json = opensky_response .json ()
101
102
except ConnectionError as e :
102
103
print ("Connection Error:" , e )
@@ -106,6 +107,7 @@ def _format_datetime(datetime):
106
107
107
108
if DEBUG :
108
109
print ("Full API GET URL: " , OPENSKY_SOURCE )
110
+ print ("Full API GET Header: " , OPENSKY_HEADER )
109
111
print (opensky_json )
110
112
111
113
# ERROR MESSAGE RESPONSES
@@ -134,7 +136,7 @@ def _format_datetime(datetime):
134
136
135
137
if osn_single_flight_data is not None :
136
138
if DEBUG :
137
- print (f" | | Single Flight Data: { osn_single_flight_data } " )
139
+ print (f" | | Single Private Flight Data: { osn_single_flight_data } " )
138
140
139
141
last_contact = opensky_json ["states" ][0 ][4 ]
140
142
# print(f" | | Last Contact Unix Time: {last_contact}")
0 commit comments