annotate airport @ 9571:a4b3b4ec7681

<fizzie> fetch http://zem.fi/tmp/airport
author HackBot
date Sun, 30 Oct 2016 23:43:42 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9571
a4b3b4ec7681 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
1 #! /usr/bin/env python
a4b3b4ec7681 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
2
a4b3b4ec7681 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
3 import csv
a4b3b4ec7681 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
4 import sys
a4b3b4ec7681 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
5
a4b3b4ec7681 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
6 if len(sys.argv) < 3: sys.stderr.write('usage: airport any|name|iata|icao key\n'); sys.exit(1)
a4b3b4ec7681 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
7 kind, q = sys.argv[1], ' '.join(sys.argv[2:])
a4b3b4ec7681 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
8
a4b3b4ec7681 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
9 fieldnames = dict(name=1, iata=4, icao=5)
a4b3b4ec7681 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
10 if kind == 'any': fields = [1, 4, 5]
a4b3b4ec7681 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
11 elif kind in fieldnames: fields = [fieldnames[kind]]
a4b3b4ec7681 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
12 else: sys.stderr.write('unknown search type: %s\n' % kind); sys.exit(1)
a4b3b4ec7681 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
13
a4b3b4ec7681 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
14 def f(s): return s if s and s != '\N' else '?'
a4b3b4ec7681 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
15
a4b3b4ec7681 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
16 with open('share/airports.dat', 'rb') as datafile:
a4b3b4ec7681 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
17 for row in csv.reader(datafile):
a4b3b4ec7681 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
18 for fi in fields:
a4b3b4ec7681 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
19 if q.lower() in row[fi].lower():
a4b3b4ec7681 <fizzie> fetch http://zem.fi/tmp/airport
HackBot
parents:
diff changeset
20 print '%s (%s, %s)' % (row[1], f(row[4]), f(row[5]))