Created
July 3, 2023 19:50
-
-
Save Jxck-S/8341dfb56022f10b4d13b6fccdbaeb75 to your computer and use it in GitHub Desktop.
Logs flight data from the IFE API's on a Virgin Atlantic Flight
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests, json, time | |
from datetime import datetime | |
l_flight = {'info': {}, 'updates': []} | |
log_keys = ['groundSpeedKnots', | |
'headWindSpeedKnots', | |
'mach', | |
'pitch', | |
'roll', | |
'airSpeedKnots', | |
'altitudeFeet', | |
'trueHeading', | |
'outsideTemp', | |
'windDirection', | |
'windSpeedKnots', | |
'positionValid', | |
'time', | |
'timeToDestination', | |
'distanceToDestinationNauticalMiles', | |
'presentPhase', | |
'presentLat', | |
'presentLon', | |
'weightOnWheels', | |
'doorsClosed'] | |
while True: | |
va_rsp = requests.get("https://vir.mediasuite.zii.aero:8483/fp3d_logs/last") | |
va_json = va_rsp.json() | |
current_count = len(l_flight['updates']) | |
if "tailNumber" in va_json.keys(): | |
va_json["tailNumber"] = va_json["tailNumber"].strip(".") | |
current_update = {} | |
for key, val in va_json.items(): | |
if current_count == 0 and not (key in log_keys): | |
l_flight['info'][key] = val | |
elif key in log_keys: | |
current_update[key] = val | |
l_flight['updates'].append(current_update) | |
print(l_flight) | |
#print(json.dumps(va_json, indent=4)) | |
flight = va_json['flightNumber'] | |
if current_count == 0: | |
print("Print startup with flight v ") | |
print(json.dumps(l_flight['info'], indent=2)) | |
with open(f"{flight}.json", "w") as log_json: | |
json.dump(l_flight, log_json, indent=4) | |
print(f"Updated logged, {l_flight['updates'][current_count]['time']}, ETA: {l_flight['updates'][current_count]['timeToDestination']/60} h") | |
print("Sleeping") | |
time.sleep(45) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment