annotate bin/airport-lookup @ 12256:821155c00e34 draft

<fizzie> ` sed -e \'s|wisdom|bin|\' < ../bin/culprits > ../bin/cblprits; chmod a+x ../bin/cblprits
author HackEso <hackeso@esolangs.org>
date Sat, 07 Dec 2019 23:36:22 +0000
parents 204fe444dca2
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
9617
c09e4dd3afd7 <fizzie> ` sed -i -e \'s/usage: airport/usage: airport-lookup/\' bin/airport-lookup
HackBot
parents: 9572
diff changeset
6 if len(sys.argv) < 3: sys.stderr.write('usage: airport-lookup any|name|iata|icao key\n'); sys.exit(1)
9571
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
12106
204fe444dca2 <fizzie> sled /hackenv/bin/airport-lookup//s|share/airports.dat|/hackenv/share/airports.dat|
HackEso <hackeso@esolangs.org>
parents: 9617
diff changeset
16 with open('/hackenv/share/airports.dat', 'rb') as datafile:
9571
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]))