Skip to content

Instantly share code, notes, and snippets.

@kenners
Last active May 15, 2020 20:10
Show Gist options
  • Save kenners/8abe1d2f62400f87958d to your computer and use it in GitHub Desktop.
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.
#!/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)
@tcasalert
Copy link

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)]

@maxboettinger
Copy link

Is this still working? All other workarounds stopped working since flightradar24 changed their api-urls...

@wdcurry
Copy link

wdcurry commented Nov 15, 2017

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