I enjoy tracking and visualizing aviation data, as there is so much going on above us that we do not see as we go about our daily lives. Thus, I wrote this script to be able to access and store open source aviation data through OpenSky Network. I have used this data to visualize and learn more about what aircraft are flying above us.
I hope you too find interest in this dataset!
# Andrew Caietti
#
# live_aviation.py
#
# Recent Edit: 2020-09-03
#
# This script calls an opensource API from OpenSkyNetwork.com.
# The data can then be saved as a CSV or worked with in its converted two-dimensional
# array format. Each sub-array represents an individual aircraft with
# 17 total fields.
##################
# MODULES NEEDED #
##################
import pandas as pd
from opensky_api import OpenSkyApi
import argparse
from time import gmtime, strftime
from tkinter.filedialog import askdirectory
###############
# Functions #
###############
# Generate the a 2-dimensional array where each sub-array is an individual aircraft
def RetrievePlaneData():
= OpenSkyApi() # Call the API
api = api.get_states()
states = []
main_array for s in states.states: # Iterate through and store states object attributes (StateVector)
=[0]*17
temp_array0]=s.icao24
temp_array[1]=s.callsign
temp_array[2]=s.origin_country
temp_array[3]=s.time_position
temp_array[4]=s.last_contact
temp_array[5]=s.longitude
temp_array[6]=s.latitude
temp_array[7]=s.baro_altitude
temp_array[8]=s.velocity
temp_array[9]=s.heading
temp_array[10]=s.vertical_rate
temp_array[11]=s.on_ground
temp_array[12]=s.sensors
temp_array[13]=s.geo_altitude
temp_array[14]=s.squawk
temp_array[15]=s.spi
temp_array[16]=s.position_source
temp_array[
main_array.append(temp_array)return main_array
# Pass a path name, where you would like to save the file, and the data you called from RetrievePlaneData, to generate a CSV file on your desktop.
def PlaneDatatoCSV(path_name,data):
= pd.DataFrame(data)
df = ['icao24','Callsign','Origin Country','Time Position','Last Contact','Longitude','Latitude','Baro Altitude','Velocity','Heading','Vertical Rate','On Ground','Sensors','Geo Altitude','Squawk','Spi','Position Source']
df.columns = strftime(r'%Y_%m_%d__%H_%M_%S') # Record current time to time-stamp the file
ts +r"\Aviation_Data__"+ts+r'.csv',index=False,header=True)
df.to_csv(path_name
##########
## MAIN ##
##########
if __name__ =='__main__':
= argparse.ArgumentParser(description="Retrieve live, open-source aviation data about what planes are flying where in the world.")
parser '--link', default = 'https://opensky-network.org/', help='Link to the API (datasource).')
parser.add_argument(= parser.parse_args()
args
= RetrievePlaneData()
current_data = askdirectory(title='Select Folder') # Allow user to choose what folder to save data in
my_path PlaneDatatoCSV(my_path,current_data)