Living under the airport flight path?


#1

We live under the approach of the Raleigh-Durham airport. Planes fly over around 2300 feet - we can hear them clearly. Why wouldn’t I want to know what flight it is?

It takes two things.
One, a very simple (and re-usable) piston that takes a text argument and speaks over Alexa Speaks.

Two is a python script that runs on a Raspberry Pi, below.
-Edit the first url boundary box to be the GPS coordinates you care about (it’s a box, so takes 2 lattitude and 2 longitude)
-Edit the second url to be the execute url of your Webcore announcement piston.
-Edit the airport code from RDU to the airport by you
-Edit the three file paths if the script is running from anywhere besides /home/pi/Documents/

Set it up in crontab to run every two minutes. Attached. Oh, and grab the airport-codes.csv from github: https://github.com/datasets/airport-codes/blob/master/data/airport-codes.csv
and put in the same directory as the script.

import json
import requests
import time
import csv


##get flight data for a bounding box over our house in Raleigh
##bounds=north,south,west,east
url = 'https://data-live.flightradar24.com/zones/fcgi/feed.js?bounds=35.9881,35.9116,-78.7739,-78.6480,-78.7739&faa=1&mlat=1&flarm=1&adsb=1&gnd=0&air=1&vehicles=0&estimated=0&gliders=0&stats=0'

s = requests.Session()
s.headers.update({'User-Agent':'Mozilla/5.0','referer':'http://foo.bar.horse:3000/'})
response=s.get(url)

data = json.loads(response.text)


##iterate through results; ignore the full_count and version;
##everything else is a flight; creates a list of lists
flightslist = []

for key in data:
    if key != "full_count" and key != "version":
        value = data[key]
        flightslist.append(value)


##read the translation file to change airport codes to city name
with open("/home/pi/Documents/airports.json", "r") as read_file:
    airportcodes = json.load(read_file)


#load previous flight history into dict
flighthistoryold = {}
with open("/home/pi/Documents/flights.csv") as f:
    for line in f:
        (key, val) = line.split(',')
        flighthistoryold[key] = val.rstrip()
print(flighthistoryold)


#create dict for flights in this current run
flighthistorynew = {}


##iterate through the flights in flight list; items 11-13 are
##airport code from, airport code to, and flight number
for flight in flightslist:
    flightnumber = flight[13]
    airportfrom = flight[11]
    airportto = flight[12]
    ##filter down to just the ones that are commercial and landing at RDU
    if airportto == "RDU" and flightnumber != "" and airportfrom != "":
        #add to flighthistorynew dict so we don't repeat announcements
        flighthistorynew[flightnumber] = time.time()
        #check if this flight number was seen last time
        if flightnumber not in flighthistoryold:
            ##parses the airport translation file down to airport code matching departure
            cityfrom = [x for x in airportcodes if x['iata'] == airportfrom]
            ##there can be only one matching airport code, so grab the city from first record
            cityfrom = cityfrom[0]['city']
            #build the announcement string; listify the stringcolonate flightnumber
            #to pronounce better from Alexa
            announcement = "Here comes flight " + ":".join(flightnumber) + " arriving from " + cityfrom
            print(announcement)
            ##call webCore piston; pass announcement as argument
            url = 'https://graph-na02-useast1.api.smartthings.com/api/token/xxxxxxsmartapps/installations/yyyyyyyyy/execute/:0zzzzzzzzzzz:'
            response=requests.get(url + "?text='" + announcement + "'")

#write out new flights - or lack thereof - into a file
w = csv.writer(open("/home/pi/Documents/flights.csv", "w"))
for key, val in flighthistorynew.items():
    w.writerow([key, val])

End result: around the time I hear a plane flying over, I hear Alexa say something like “Here comes flight C27508 arriving from Wilmington”. Because why the heck wouldn’t I?

Enjoy!


Gauge for Length of Day (showing Solstices & Equinoxes)
#2

I would be curious as to when it will say unidentified plane just went by… :laughing:


#3

Does it also detect Unidentified Flying Objects? :alien:


#4

I KNEW that someone would go there…


#5

If you were in South Florida, I might have asked whether it detected Treetop Flyers


#6

Wow. Endless possibilities with webcore.


#7

I love it…
Now I want to live under an airport approach way:))))


#8

Now I want to live under an airport approach way:))))

No, no you don’t. 66 planes in the last 6 hours have flown over our neighborhood today. (ok, so I am logging those to InfluxDB and dashboarding in Grafana because I log EVERYTHING…)


#9

I will be a teenager and say OMG!!! LOL


#10

That’s a really cool idea for a piston. Now I want to see what kinds of local notifications I can get, lol


#11

Stupid question… does it have to be run on a Raspberry Pi, or is there a chance I could get it going on Linux? I have a lot of things running on Linux VMs in my vSphere system. I’m just not up on it enough to know whether it’s cross-platform enough, or if things would need to be extensively modified to port it from RPi to Linux.


#12

It’s just python 3, ought to run under any other linux just fine. Windows, too, although Windows you’d have to change the format of the airports.json file location.


#13

@milhouse

Re: having it run every two minutes…
Is that just to make sure it stays updated with the latest data (and we can modify that frequency to our liking?)?


#14

Yes, adjust to your liking. Probably based on the size of your GPS box.

Remember it’s point-in-time - what flights are current within the GPS box. So running it less frequently won’t get you a list of what has gone by. And running it more frequently than every minute is probably not very useful (as well as rude to the API providers!).


#15

Yep. Totally makes sense.
Thanks for posting this.


#16

Did your piston identify the low flying military planes on Saturday night and Sunday morning? :wink:


#17

I wish. flightradar24 doesn’t show military craft which is too bad, because some of those were LOUD last night!