annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9567
a53b2e6acb15 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
1 #! /usr/bin/env python
a53b2e6acb15 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
2
a53b2e6acb15 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
3 import csv
a53b2e6acb15 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
4 import sys
a53b2e6acb15 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
5
a53b2e6acb15 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
6 fields = dict(name=1, iata=4, icao=5)
a53b2e6acb15 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
7 if len(sys.argv) != 3: sys.stderr.write('usage: airport name|iata|icao key\n'); sys.exit(1)
a53b2e6acb15 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
8 kind, q = sys.argv[1:3]
a53b2e6acb15 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
9 if kind not in fields: sys.stderr.write('unknown search type: %s\n' % kind); sys.exit(1)
a53b2e6acb15 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
10
a53b2e6acb15 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
11 with open('share/airports.dat', 'rb') as datafile:
a53b2e6acb15 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
12 for row in csv.reader(datafile):
a53b2e6acb15 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
13 if q.lower() in row[fields[kind]].lower():
a53b2e6acb15 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
14 print '%s (%s, %s)' % (row[1], row[4] if row[4] else '?', row[5] if row[5] else '?')