Skip to content

Commit 626605f

Browse files
committed
i want to give black a black eye
i forget every single time
1 parent 1635b7b commit 626605f

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

examples/requests_api_openskynetwork_public.py

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,16 @@
2828

2929
# this example uses settings.toml for credentials
3030
# timezone offset is in seconds plus or minus GMT
31-
ssid = os.getenv('AP_SSID')
32-
appw = os.getenv('AP_PASSWORD')
33-
timezone = os.getenv('timezone')
34-
tz_offset_seconds = os.getenv('timezone_offset')
31+
ssid = os.getenv("AP_SSID")
32+
appw = os.getenv("AP_PASSWORD")
33+
timezone = os.getenv("timezone")
34+
tz_offset_seconds = os.getenv("timezone_offset")
3535

3636
# https://opensky-network.org/api/states/all
3737
# example https://opensky-network.org/api/states/all?icao24=a808c5
3838
# You can use states/own to pull your owned craft data without rate limit.
39-
OPENSKY_SOURCE = (
40-
"https://opensky-network.org/api/states/all?"
41-
+ "icao24="
42-
+ transponder
43-
)
39+
OPENSKY_SOURCE = "https://opensky-network.org/api/states/all?" + "icao24=" + transponder
40+
4441

4542
def time_calc(input_time):
4643
if input_time < 60:
@@ -60,6 +57,7 @@ def time_calc(input_time):
6057
time_output = f"{sleep_int:.0f} days"
6158
return time_output
6259

60+
6361
def _format_datetime(datetime):
6462
return "{:02}/{:02}/{} {:02}:{:02}:{:02}".format(
6563
datetime.tm_mon,
@@ -70,6 +68,7 @@ def _format_datetime(datetime):
7068
datetime.tm_sec,
7169
)
7270

71+
7372
# Connect to Wi-Fi
7473
print("\n===============================")
7574
print("Connecting to WiFi...")
@@ -105,37 +104,43 @@ def _format_datetime(datetime):
105104
osn_debug_keys = True # Set true to print Serial data
106105
if osn_debug_keys:
107106
try:
108-
osn_flight = osn_json['time']
107+
osn_flight = osn_json["time"]
109108
print("Current Unix Time: ", osn_flight)
110-
109+
111110
current_struct_time = time.localtime(osn_flight)
112111
current_date = "{}".format(_format_datetime(current_struct_time))
113112
print(f"Unix to Readable Time: {current_date}")
114113

115-
osn_single_flight_data = osn_json['states']
114+
osn_single_flight_data = osn_json["states"]
116115
if osn_single_flight_data is not None:
117116
print("Flight Data: ", osn_single_flight_data)
118-
transponder = osn_json['states'][0][0]
117+
transponder = osn_json["states"][0][0]
119118
print("Transponder: ", transponder)
120-
callsign = osn_json['states'][0][1]
119+
callsign = osn_json["states"][0][1]
121120
print("Callsign: ", callsign)
122-
country = osn_json['states'][0][2]
121+
country = osn_json["states"][0][2]
123122
print("Flight Country: ", country)
124123
else:
125124
print("This flight has no active data or you're polling too fast.")
126125
print("You will eventually get temp banned for polling too fast!")
127-
print("Please read: https://openskynetwork.github.io/opensky-api/rest.html#limitations")
128-
print("Public Limits: 10 second max poll rate & 400 weighted calls daily")
129-
print("There is no JSON error, states/all html page will say \"Too many requests\" and the script will fail ")
130-
126+
print(
127+
"Please read: https://openskynetwork.github.io/opensky-api/rest.html#limitations"
128+
)
129+
print(
130+
"Public Limits: 10 second max poll rate & 400 weighted calls daily"
131+
)
132+
print(
133+
'There is no JSON error, states/all html page will say "Too many requests" and the script will fail '
134+
)
135+
131136
print("\nFinished!")
132-
print("Board Uptime: ", time_calc(time.monotonic()))
137+
print("Board Uptime: ", time_calc(time.monotonic()))
133138
print("Next Update: ", time_calc(sleep_time))
134139
time.sleep(sleep_time)
135140
print("===============================")
136-
141+
137142
except (ConnectionError, ValueError, NameError) as e:
138143
print("OSN Connection Error:", e)
139144
print("You are likely banned for 24 hours")
140145
print("Next Retry: ", time_calc(sleep_time))
141-
time.sleep(sleep_time)
146+
time.sleep(sleep_time)

0 commit comments

Comments
 (0)