Skip to content

Instantly share code, notes, and snippets.

@Jxck-S
Created July 3, 2023 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jxck-S/8341dfb56022f10b4d13b6fccdbaeb75 to your computer and use it in GitHub Desktop.
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
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