From 2cfaa7d161fe4c56e5ebef5f2e7a23af5e34af48 Mon Sep 17 00:00:00 2001 From: Jack Sweeney Date: Tue, 10 Nov 2020 02:17:07 +0000 Subject: [PATCH] Auto download airports.dat --- NotifyBotMulti.py | 5 +++-- defAirport.py | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/NotifyBotMulti.py b/NotifyBotMulti.py index 620b651..3c29a3a 100644 --- a/NotifyBotMulti.py +++ b/NotifyBotMulti.py @@ -9,7 +9,9 @@ if platform.system() == "Windows": init(convert=True) from planeClass import Plane from datetime import datetime +from defAirport import DownloadAirports import pytz +DownloadAirports() main_config = configparser.ConfigParser() main_config.read('./configs/mainconf.ini') import os @@ -82,5 +84,4 @@ while True: sys.stdout.flush() time.sleep(1) sys.stdout.write(Back.RED + ('\x1b[1K\r' +"Slept for " +str(sleep_sec)) + Style.RESET_ALL) - print() - + print() \ No newline at end of file diff --git a/defAirport.py b/defAirport.py index e84c498..97d4a0f 100644 --- a/defAirport.py +++ b/defAirport.py @@ -1,5 +1,26 @@ #https://www.geeksforgeeks.org/python-calculate-distance-between-two-places-using-geopy/ #https://openflights.org/data.html +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 csv