view bin/airport-lookup @ 11293:a7899ef2d7b6

<wob_jonas> learn Aristotle said that every illness can be cured by balancing the four vitreous humors, and everyone believed him for two thousand years, even though people still died of illnesses. It wasn\'t until the 20th century that Szent-Gy\xc3\xb6rgyi Albert realized that Aristotle didn\'t find fifth kind of vitreous humor, vitamin C, because the Greek alphabet
author HackBot
date Mon, 01 Jan 2018 17:57:43 +0000
parents c09e4dd3afd7
children 204fe444dca2
line wrap: on
line source

#! /usr/bin/env python

import csv
import sys

if len(sys.argv) < 3: sys.stderr.write('usage: airport-lookup any|name|iata|icao key\n'); sys.exit(1)
kind, q = sys.argv[1], ' '.join(sys.argv[2:])

fieldnames = dict(name=1, iata=4, icao=5)
if kind == 'any': fields = [1, 4, 5]
elif kind in fieldnames: fields = [fieldnames[kind]]
else: sys.stderr.write('unknown search type: %s\n' % kind); sys.exit(1)

def f(s): return s if s and s != '\N' else '?'

with open('share/airports.dat', 'rb') as datafile:
  for row in csv.reader(datafile):
    for fi in fields:
      if q.lower() in row[fi].lower():
        print '%s (%s, %s)' % (row[1], f(row[4]), f(row[5]))