From 2f4d54a7feb15921895a9744e2d24cf3e4693a19 Mon Sep 17 00:00:00 2001 From: Igor Chubin Date: Sun, 16 Feb 2020 19:41:40 +0100 Subject: [PATCH] added lib/airports.py --- lib/airports.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 lib/airports.py diff --git a/lib/airports.py b/lib/airports.py new file mode 100644 index 0000000..e950ceb --- /dev/null +++ b/lib/airports.py @@ -0,0 +1,22 @@ +import csv + +AIRPORTS_DAT_FILE = '/home/igor/wttrin-geo/share/airports.dat' + +def load_aiports_index(): + file_ = open(AIRPORTS_DAT_FILE, "r") + reader = csv.reader(file_) + airport_index = {} + + for line in reader: + airport_index[line[4]] = line + + return airport_index + +AIRPORTS_INDEX = load_aiports_index() + +def get_airport_gps_location(iata_code): + if iata_code in AIRPORTS_INDEX: + airport = AIRPORTS_INDEX[iata_code] + return '%s,%s airport' % (airport[6], airport[7]) #, airport[1]) + return None +