Vatsim Map
unknown
python
3 years ago
1.8 kB
13
Indexable
import requests import json import time import cartopy.crs as ccrs import cartopy import matplotlib.pyplot as plt from cartopy.io.img_tiles import GoogleTiles from matplotlib import animation import numpy as np #SET AXES fig, ax = plt.subplots() ax=plt.axes(projection=ccrs.PlateCarree()) ax.set_ylim(48,61.5) ax.set_xlim(-12.5, 3.3) #ADD OSM BASEMAP osm_tiles=GoogleTiles(style='satellite') ax.add_image(osm_tiles,4) ax.stock_img() #ax.set_extent([-12.5, 3.3, 48, 61.55]) ax.add_feature(cartopy.feature.BORDERS) #mplcursors.cursor(hover=True) #PLOT TRACK track, = ax.plot([], [], 'wo', markersize=2) # RELOAD API EVERY 15" def update (self): vapi = requests.get("https://data.vatsim.net/v3/vatsim-data.json") # LOAD DATA AS JSON data = vapi.text parse_json = json.loads(data) # LOAD PILOTS pilots = parse_json['pilots'] no_pilots = len(pilots) # GET INFO FOR EACH AIRCRAFT x = 0 callsigns, lat, lon, alt, head, gspeed = [], [], [], [], [], [] while x < no_pilots: xcall = pilots[x]['callsign'] xlat = pilots[x]['latitude'] xlon = pilots[x]['longitude'] xgspeed = pilots[x]['groundspeed'] xalt = pilots[x]['altitude'] xhead = pilots[x]['heading'] callsigns.append(xcall) lat.append(xlat) lon.append(xlon) alt.append(xalt) head.append(xhead) gspeed.append(xgspeed) x += 1 for i, txt in enumerate(callsigns): ax.annotate(txt, (lon[i], lat[i])) track.set_data(lon,lat) return track, callsigns, anim = animation.FuncAnimation(fig, update,interval=10000, blit=False) plt.show()
Editor is loading...