I have written before about my use of a Raspberry Pi to grab ADS-B data from passing aircraft (and rather handily a large proportion of UK-US traffic passes pretty much over the top of my house). Whilst I’m all for gathering data myself, I did want to see what further data sources are out there and what I could do with them. Imagine my nerdy pleasure when I found out that there is not only a rich data source out there, but that it’s free, and it comes with a Python interface for its API!
OpenSky is ridiculously easy to use with Python, and the documentation (found here) gives you plenty to get on with. Doing some initial playing around, it took me less than five minutes to get a working script that grabbed me a rich set of features, and did so for an update every 10 seconds (the free access is rate limited, understandably). The code I use is shown below:
from opensky_api import OpenSkyApi api = OpenSkyApi() states = api.get_states() for s in states.states: print("(%r, %r, %r, %r, %r, %r, %r, %r, %r, %r, %r, %r)" % ( s.icao24, s.callsign, s.origin_country, s.longitude, s.latitude, s.baro_altitude, s.on_ground, s.geo_altitude, s.velocity, s.heading, s.vertical_rate, s.squawk))
That little bit of code (sadly not highlighted as I’m still getting to grips with the changes in WordPress’ new Gutenberg editor) brings back over 6,000 records for what aircraft all around the world are doing. A fantastic little dataset generator, which I’ll look to soon use in Splunk for some exploratory insights.
Speaking of Splunk and data. There are also some free and very useful csv files for data enrichment in this respect available from ourairports.com – with useful info on airports/airlines/runways/navaids/radio frequencies. Put all this together and you can have a real useful insight into what’s going on in aviation around the world, all with just a few lines of Python and a free API.