comparison bin/airport @ 9568:4e914255974a

<fizzie> ` mv airport bin/airport; chmod a+x bin/airport
author HackBot
date Sun, 30 Oct 2016 23:23:17 +0000
parents airport@a53b2e6acb15
children 98c473a71c18
comparison
equal deleted inserted replaced
9567:a53b2e6acb15 9568:4e914255974a
1 #! /usr/bin/env python
2
3 import csv
4 import sys
5
6 fields = dict(name=1, iata=4, icao=5)
7 if len(sys.argv) != 3: sys.stderr.write('usage: airport name|iata|icao key\n'); sys.exit(1)
8 kind, q = sys.argv[1:3]
9 if kind not in fields: sys.stderr.write('unknown search type: %s\n' % kind); sys.exit(1)
10
11 with open('share/airports.dat', 'rb') as datafile:
12 for row in csv.reader(datafile):
13 if q.lower() in row[fields[kind]].lower():
14 print '%s (%s, %s)' % (row[1], row[4] if row[4] else '?', row[5] if row[5] else '?')