Last active
May 15, 2020 20:10
-
-
Save kenners/8abe1d2f62400f87958d 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 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
#!/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]*3.048) 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) |
Awesome script, thank you! My first delvings in Python but it's working fine at least from a command line. Hoping to get this working with a PHP input form next. To scale the altitude, change the line:
path = [(x[1], x[0], x[2]) for x in reversed(temp_path)]
to
path = [(x[1], x[0], x[2]*3.048) for x in reversed(temp_path)]
Is this still working? All other workarounds stopped working since flightradar24 changed their api-urls...
Isn't FR24's not publicly consumable?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
flightradar24 returns altitude in tens of feet, while KML assumes all altitudes to be in meters. Could you please add altitude scaling by 3.048 factor?
BTW: thanks a heap for this very handy script! 👍