Mercurial > repo
annotate bin/airport-lookup @ 12298:cea93c2c666a draft
<b_jonas> learn Burlesque is only the sexiest language on Earth. mroman created it for finance analysis because the traditionally used K and Dyalog APL are unreadable. (See: http://mroman.ch/burlesque )
author | HackEso <hackeso@esolangs.org> |
---|---|
date | Sat, 04 Jan 2020 22:50:21 +0000 |
parents | 204fe444dca2 |
children |
rev | line source |
---|---|
9571 | 1 #! /usr/bin/env python |
2 | |
3 import csv | |
4 import sys | |
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 | 7 kind, q = sys.argv[1], ' '.join(sys.argv[2:]) |
8 | |
9 fieldnames = dict(name=1, iata=4, icao=5) | |
10 if kind == 'any': fields = [1, 4, 5] | |
11 elif kind in fieldnames: fields = [fieldnames[kind]] | |
12 else: sys.stderr.write('unknown search type: %s\n' % kind); sys.exit(1) | |
13 | |
14 def f(s): return s if s and s != '\N' else '?' | |
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 | 17 for row in csv.reader(datafile): |
18 for fi in fields: | |
19 if q.lower() in row[fi].lower(): | |
20 print '%s (%s, %s)' % (row[1], f(row[4]), f(row[5])) |