Browse Source

Auto download airports.dat

pull/2/head
Jack Sweeney 4 years ago committed by GitHub
parent
commit
2cfaa7d161
  1. 5
      NotifyBotMulti.py
  2. 21
      defAirport.py

5
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()

21
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

Loading…
Cancel
Save