Common download method/check for required files
-Remove duplicated download/check code - Common list of file/url of file that will all be checked on start
This commit is contained in:
parent
316888bafc
commit
226f4e9458
|
@ -1,21 +1,3 @@
|
|||
def download_font():
|
||||
import os
|
||||
fontfile = "Roboto-Regular.ttf"
|
||||
if not os.path.isfile(fontfile):
|
||||
print("No font file, downloading now")
|
||||
try:
|
||||
import requests
|
||||
url = 'https://github.com/google/fonts/raw/master/apache/roboto/static/Roboto-Regular.ttf'
|
||||
font = requests.get(url)
|
||||
|
||||
open(fontfile, 'wb').write(font.content)
|
||||
except:
|
||||
raise("Error getting font or storing")
|
||||
else:
|
||||
print("Successfully got font", fontfile)
|
||||
elif os.path.isfile(fontfile):
|
||||
print("Already have font, continuing")
|
||||
|
||||
def append_airport(filename, icao, airport, distance_mi):
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
distance_km = distance_mi * 1.609
|
||||
|
|
|
@ -8,11 +8,25 @@ if platform.system() == "Windows":
|
|||
init(convert=True)
|
||||
from planeClass import Plane
|
||||
from datetime import datetime
|
||||
from defAirport import download_airports
|
||||
from AppendAirport import download_font
|
||||
import pytz
|
||||
download_airports()
|
||||
download_font()
|
||||
import os
|
||||
required_files = [("Roboto-Regular.ttf", 'https://github.com/google/fonts/raw/master/apache/roboto/static/Roboto-Regular.ttf'), ('airports.csv', 'https://ourairports.com/data/airports.csv')]
|
||||
for file in required_files:
|
||||
file_name = file[0]
|
||||
url = file[1]
|
||||
if not os.path.isfile(file_name):
|
||||
print(file_name, "does not exist downloading now")
|
||||
try:
|
||||
import requests
|
||||
file_content = requests.get(url)
|
||||
|
||||
open(file_name, 'wb').write(file_content.content)
|
||||
except:
|
||||
raise("Error getting", file_name, "from", url)
|
||||
else:
|
||||
print("Successfully got", file_name)
|
||||
elif os.path.isfile(file_name):
|
||||
print("Already have", file_name, "continuing")
|
||||
main_config = configparser.ConfigParser()
|
||||
main_config.read('./configs/mainconf.ini')
|
||||
source = main_config.get('DATA', 'SOURCE')
|
||||
|
@ -21,7 +35,6 @@ webhook = DiscordWebhook(url= main_config.get('DISCORD', 'URL'), content=(str("S
|
|||
webhook.execute()
|
||||
try:
|
||||
print("Source is set to", source)
|
||||
import os
|
||||
import sys
|
||||
#Setup plane objects from plane configs
|
||||
planes = {}
|
||||
|
|
|
@ -1,26 +1,6 @@
|
|||
#https://www.geeksforgeeks.org/python-calculate-distance-between-two-places-using-geopy/
|
||||
#https://openflights.org/data.html
|
||||
def download_airports():
|
||||
import os
|
||||
if not os.path.isfile('airports.csv'):
|
||||
print("No airports.csv file, downloading now")
|
||||
try:
|
||||
import requests
|
||||
url = 'https://ourairports.com/data/airports.csv'
|
||||
airports = requests.get(url)
|
||||
|
||||
open('airports.csv', '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.csv', 'a') as airports:
|
||||
airports.write("#" + str(date))
|
||||
print("Successfully got airports.csv")
|
||||
elif os.path.isfile('airports.csv'):
|
||||
print("Already Have airports.csv, continuing")
|
||||
#OLD Airport lookup
|
||||
# def getClosestAirport(latitude, longitude):
|
||||
# import csv
|
||||
|
|
Loading…
Reference in New Issue