-
-
Save dkalisch/02094d6319c46129b664 to your computer and use it in GitHub Desktop.
Use Flightradar24.com's internal API to get flight path and output it as KML.
This file contains 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
#!/usr/bin/env python3 | |
import simplekml | |
import urllib.request | |
try: | |
import simplejson as json | |
except ImportError: | |
import json | |
fr24_flight_code = "" | |
output_file = "" | |
api_url = "http://krk.fr24.com/_external/planedata_json.1.3.php?f={0}".format(fr24_flight_code) | |
kml = simplekml.Kml() | |
html = urllib.request.urlopen(api_url) | |
flight = json.loads(html.read().decode('utf-8')) | |
trail = flight["trail"] | |
temp_path = [trail[x:x+3] for x in range(0, len(trail), 3)] | |
# Rearrange lat/long and format as tuple | |
path = [(x[1], x[0], x[2]) for x in reversed(temp_path)] | |
flight_path = kml.newlinestring( | |
name=fr24_flight_code, | |
description="Flight path of {0}".format(fr24_flight_code), | |
coords=path | |
) | |
flight_path.altitudemode = simplekml.AltitudeMode.absolute | |
flight_path.style.linestyle.width = 3 | |
flight_path.style.linestyle.color = simplekml.Color.red | |
kml.save(output_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment