Updated airport data format, dataset, and queries

This commit is contained in:
2023-12-18 23:21:36 -05:00
parent 8afc98ed33
commit 97be61e297
19 changed files with 306 additions and 225 deletions

61661
data/airports-original.json Normal file

File diff suppressed because it is too large Load Diff

63
data/airports.py Normal file
View File

@@ -0,0 +1,63 @@
import pandas as pd
from datetime import date
import json
# Load the airports.csv file from the web
url = 'https://davidmegginson.github.io/ourairports-data/airports.csv'
df = pd.read_csv(url, index_col=0)
# convert the dataframe to a dictionary
airports = df.to_dict('index')
formated_airports = {}
for airport in airports:
category = airports[airport]['type']
if pd.isnull(category) or category == 'nan' or category == 'NAN':
category = 'UNKNOWN'
elevation = airports[airport]['elevation_ft']
if pd.isnull(elevation) or elevation == 'nan' or elevation == 'NAN':
elevation = 0
country = airports[airport]['iso_country']
if pd.isnull(country) or country == 'nan' or country == 'NAN':
country = 'UNKNOWN'
region = airports[airport]['iso_region']
if pd.isnull(region) or region == 'nan' or region == 'NAN':
region = 'UNKNOWN'
municipality = airports[airport]['municipality']
if pd.isnull(municipality) or municipality == 'nan' or municipality == 'NAN':
municipality = 'UNKNOWN'
iata = airports[airport]['iata_code']
if pd.isnull(iata) or iata == 'nan' or iata == 'NAN':
iata = ''
local = airports[airport]['local_code']
if pd.isnull(local) or local == 'nan' or local == 'NAN':
local = ''
formated_airports[airport] = {
'icao': airports[airport]['ident'],
'category': category,
'name': airports[airport]['name'],
'elevation_ft': elevation,
'iso_country': country,
'iso_region': region,
'municipality': municipality,
'iata_code': iata,
'local_code': local,
'latitude': airports[airport]['latitude_deg'],
'longitude': airports[airport]['longitude_deg']
}
# convert the dictionary to a list of dictionaries
formated_airports = list(formated_airports.values())
# convert the list of dictionaries to a json file
today = date.today()
date = today.strftime("%Y-%m-%d")
with open(f'airports_{date}.json', 'wb') as file:
file.write(json.dumps(formated_airports).encode('utf-8'))

File diff suppressed because one or more lines are too long

0
data/requirements.txt Normal file
View File