Added new flights.py submitted by @adamkaplan.

pull/222/head
Joe Prochazka 2016-09-09 11:28:11 -04:00
rodzic 01271a7f7a
commit 7fa44bd331
3 zmienionych plików z 36 dodań i 12 usunięć

Wyświetl plik

@ -276,6 +276,9 @@ if [ $ADVANCED = TRUE ]; then
fi
;;
esac
# Flight logging prerequisites.
CheckPackage python-pip
fi
# Reload Lighttpd after installing the prerequisite packages.

Wyświetl plik

@ -39,6 +39,16 @@ PORTALBUILDDIRECTORY="$BUILDDIRECTORY/portal"
DATABASEENGINE=`grep 'db_driver' $LIGHTTPDDOCUMENTROOT/classes/settings.class.php | tail -n1 | cut -d\' -f2`
PYTHONPATH=`which python`
## SETUP PYTHON
# Install the Python inotify module using pip.
echo ""
echo -e "\e[95m Setting up Python...\e[97m"
echo ""
echo -e "\e[94m Installing the Python inotify module...\e[97m"
echo ""
sudo pip install inotify
## SETUP FLIGHT LOGGING
echo ""

Wyświetl plik

@ -28,7 +28,7 @@
# SOFTWARE. #
#================================================================================#
# WHAT THIS DOES:
# WHAT THIS DOES:
# ---------------------------------------------------------------
#
# 1) Read aircraft.json generated by dump1090-mutability.
@ -36,7 +36,9 @@
# 3) Update the last time the flight was seen.
import datetime
import inotify.adapters
import json
import re
import time
import os
#import urllib2
@ -99,7 +101,7 @@ class FlightsProcessor(object):
self.time_now = datetime.datetime.utcnow().strftime("%Y/%m/%d %H:%M:%S")
for aircraft in aircraftList:
self.processAircraft(aircraft)
self.processAircraft(aircraft)
# Close the database connection.
db.commit()
@ -178,16 +180,25 @@ class FlightsProcessor(object):
if __name__ == "__main__":
processor = FlightsProcessor(config)
mutability_dir = '/run/dump1090-mutability/'
i = inotify.adapters.Inotify()
i.add_watch(mutability_dir)
# Main run loop
while True:
# Read dump1090-mutability's aircraft.json.
with open('/run/dump1090-mutability/aircraft.json') as data_file:
data = json.load(data_file)
# For testing using a remote JSON feed.
#response = urllib2.urlopen('http://192.168.254.2/dump1090/data/aircraft.json')
#data = json.load(response)
for event in i.event_gen():
if event is not None:
(header, type_names, watch_path, filename) = event
if 'IN_MOVED_TO' in type_names and re.match('^history_\d+\.json$', filename):
processor.processAircraftList(data["aircraft"])
# Read dump1090-mutability's aircraft.json.
#with open('/run/dump1090-mutability/aircraft.json') as data_file:
with open(mutability_dir + filename) as data_file:
data = json.load(data_file)
# For testing using a remote JSON feed.
#response = urllib2.urlopen('http://192.168.254.2/dump1090/data/aircraft.json')
#data = json.load(response)
processor.processAircraftList(data["aircraft"])
log("Last Run: " + datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S"))
log("Last Run: " + datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S"))
time.sleep(15)