Auto download airports.dat
This commit is contained in:
parent
7cb7c538d6
commit
1953a87a08
|
@ -9,7 +9,9 @@ if platform.system() == "Windows":
|
||||||
init(convert=True)
|
init(convert=True)
|
||||||
from planeClass import Plane
|
from planeClass import Plane
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from defAirport import DownloadAirports
|
||||||
import pytz
|
import pytz
|
||||||
|
DownloadAirports()
|
||||||
main_config = configparser.ConfigParser()
|
main_config = configparser.ConfigParser()
|
||||||
main_config.read('./configs/mainconf.ini')
|
main_config.read('./configs/mainconf.ini')
|
||||||
import os
|
import os
|
||||||
|
@ -83,4 +85,3 @@ while True:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
sys.stdout.write(Back.RED + ('\x1b[1K\r' +"Slept for " +str(sleep_sec)) + Style.RESET_ALL)
|
sys.stdout.write(Back.RED + ('\x1b[1K\r' +"Slept for " +str(sleep_sec)) + Style.RESET_ALL)
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,27 @@
|
||||||
#https://www.geeksforgeeks.org/python-calculate-distance-between-two-places-using-geopy/
|
#https://www.geeksforgeeks.org/python-calculate-distance-between-two-places-using-geopy/
|
||||||
#https://openflights.org/data.html
|
#https://openflights.org/data.html
|
||||||
def getAirport(latitude, longitude):
|
def DownloadAirports():
|
||||||
|
import os
|
||||||
|
if not os.path.isfile('airports.dat'):
|
||||||
|
print("No airports.dat file, downloading now")
|
||||||
|
try:
|
||||||
|
import requests
|
||||||
|
url = 'https://raw.githubusercontent.com/jpatokal/openflights/master/data/airports.dat'
|
||||||
|
airports = requests.get(url)
|
||||||
|
|
||||||
|
open('airports.dat', 'wb').write(airports.content)
|
||||||
|
except:
|
||||||
|
raise("Error getting airports.dat or storing")
|
||||||
|
else:
|
||||||
|
#Writes current date to airports.dat to show when it was aqquired
|
||||||
|
import datetime
|
||||||
|
date = datetime.datetime.now()
|
||||||
|
with open('airports.dat', 'a') as airports:
|
||||||
|
airports.write("#" + str(date))
|
||||||
|
print("Successfully got airports.dat")
|
||||||
|
elif os.path.isfile('airports.dat'):
|
||||||
|
print("Already Have airports.dat, continuing")
|
||||||
|
def getClosestAirport(latitude, longitude):
|
||||||
import json
|
import json
|
||||||
import csv
|
import csv
|
||||||
from geopy.distance import geodesic
|
from geopy.distance import geodesic
|
||||||
|
@ -9,7 +30,7 @@ def getAirport(latitude, longitude):
|
||||||
airports = []
|
airports = []
|
||||||
first_run = True
|
first_run = True
|
||||||
with open('airports.dat', encoding='utf-8') as csvf:
|
with open('airports.dat', encoding='utf-8') as csvf:
|
||||||
reader = csv.DictReader( csvf, header)
|
reader = csv.DictReader(filter(lambda row: row[0]!='#', csvf), header)
|
||||||
#for row in reader:
|
#for row in reader:
|
||||||
# airports.append(row)
|
# airports.append(row)
|
||||||
for row in reader:
|
for row in reader:
|
||||||
|
|
|
@ -47,7 +47,7 @@ class Plane:
|
||||||
import platform
|
import platform
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from tabulate import tabulate
|
from tabulate import tabulate
|
||||||
from defAirport import getAirport
|
from defAirport import getClosestAirport
|
||||||
if self.config.get('MAP', 'OPTION') == "GOOGLESTATICMAP":
|
if self.config.get('MAP', 'OPTION') == "GOOGLESTATICMAP":
|
||||||
from defMap import getMap
|
from defMap import getMap
|
||||||
elif self.config.get('MAP', 'OPTION') == "ADSBX":
|
elif self.config.get('MAP', 'OPTION') == "ADSBX":
|
||||||
|
@ -304,7 +304,7 @@ class Plane:
|
||||||
raise Exception("Map option not set correctly in this planes conf")
|
raise Exception("Map option not set correctly in this planes conf")
|
||||||
#Discord
|
#Discord
|
||||||
if self.config.getboolean('DISCORD', 'ENABLE'):
|
if self.config.getboolean('DISCORD', 'ENABLE'):
|
||||||
nearest = getAirport(self.latitude, self.longitude)
|
nearest = getClosestAirport(self.latitude, self.longitude)
|
||||||
self.dis_message = (self.dis_title + " " + self.tookoff_message + nearest['icao'] + ", " + nearest["name"]).strip()
|
self.dis_message = (self.dis_title + " " + self.tookoff_message + nearest['icao'] + ", " + nearest["name"]).strip()
|
||||||
sendDis(self.dis_message, self.map_file_name, self.config)
|
sendDis(self.dis_message, self.map_file_name, self.config)
|
||||||
#PushBullet
|
#PushBullet
|
||||||
|
@ -346,7 +346,7 @@ class Plane:
|
||||||
raise Exception("Map option not set correctly in this planes conf")
|
raise Exception("Map option not set correctly in this planes conf")
|
||||||
#Discord
|
#Discord
|
||||||
if self.config.getboolean('DISCORD', 'ENABLE'):
|
if self.config.getboolean('DISCORD', 'ENABLE'):
|
||||||
nearest = getAirport(self.last_latitude, self.last_longitude)
|
nearest = getClosestAirport(self.last_latitude, self.last_longitude)
|
||||||
self.dis_message = (self.dis_title + " " +self.landed_message + nearest['icao'] + ", " + nearest["name"]).strip()
|
self.dis_message = (self.dis_title + " " +self.landed_message + nearest['icao'] + ", " + nearest["name"]).strip()
|
||||||
sendDis(self.dis_message, self.map_file_name, self.config)
|
sendDis(self.dis_message, self.map_file_name, self.config)
|
||||||
#PushBullet
|
#PushBullet
|
||||||
|
|
Loading…
Reference in New Issue