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
77import os
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
2424ssid = os .getenv ("CIRCUITPY_WIFI_SSID" )
4646OSN_CREDENTIALS_B = b"" + str (OSN_CREDENTIALS ) + ""
4747BASE64_ASCII = b2a_base64 (OSN_CREDENTIALS_B )
4848BASE64_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
5151if DEBUG :
5252 print ("Original Binary Data: " , OSN_CREDENTIALS_B )
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 )}
6060OPENSKY_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