-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathradar.py
51 lines (41 loc) · 1.76 KB
/
radar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# requests is a module that allows you to send HTTP requests
import requests
# json is for handling JSON files
import json
# simplekml is for generating KML files
import simplekml
# The geographic location of your virtual radar
Latitude = "52.0688114"
Longitude = "19.4709897"
# Range of your virtual radar in kilometers
# Too high range may cause performance issues.
Radius = "450"
# ADS-B Data URL
URL = "https://public-api.adsbexchange.com/VirtualRadar/AircraftList.json?lat="+Latitude+"&lng="+Longitude+"&fDstU="+Radius
# Unfortunately adsbexchange.com blocks requests generated by urllib so we have to spoof some headers
Headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36"}
# Download data from given URL
RawFlightData = requests.get(URL, headers=Headers)
# Parse downloaded JSON
FlightData = json.loads(RawFlightData.content)
# Now it's time to generate our map
kml = simplekml.Kml()
for airplane in FlightData["acList"]:
point = kml.newpoint()
point.coords = [(airplane["Long"],airplane["Lat"])]
point.name = str(airplane["Icao"])
description = ""
if("Reg" in airplane):
description += "Registration number: "+str(airplane["Reg"])+"\n<br>"
if("Alt" in airplane):
description += "Altitude: "+str(airplane["Alt"])+" ft.\n<br>"
if("Spd" in airplane):
description += "Ground speed: "+str(airplane["Spd"])+" knots\n<br>"
if("Trak" in airplane):
description += "Heading: "+str(airplane["Trak"])+"°\n<br>"
point.style.iconstyle.rotation = round(airplane["Trak"])
if("Op" in airplane):
description += "Operator: "+airplane["Op"]
point.description = description
# Save our KML file
kml.save("./radar.kml")