Mercurial > repo
annotate bin/whatis @ 12152:c7cc64c16398 draft
<oerjan> fetch ../bin/lastfiles https://hack.esolangs.org/get/bin/lastfiles
author | HackEso <hackeso@esolangs.org> |
---|---|
date | Mon, 18 Nov 2019 02:42:33 +0000 |
parents | f79df0b509c8 |
children | 44379732c06b |
rev | line source |
---|---|
11848
fb7d032ba453
<wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff
changeset
|
1 #!/usr/bin/python3 |
12022
dff0129e4a40
<b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
11854
diff
changeset
|
2 import sys, os, re |
11848
fb7d032ba453
<wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff
changeset
|
3 if len(sys.argv) <= 1: |
fb7d032ba453
<wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff
changeset
|
4 print("whatis what?") |
fb7d032ba453
<wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff
changeset
|
5 sys.exit(1) |
fb7d032ba453
<wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff
changeset
|
6 else: |
11853
97b02eed7f57
<b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
11850
diff
changeset
|
7 argorg = [] |
11848
fb7d032ba453
<wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff
changeset
|
8 argfoldv = [] |
11853
97b02eed7f57
<b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
11850
diff
changeset
|
9 foundv = [] |
11848
fb7d032ba453
<wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff
changeset
|
10 for arg in sys.argv[1:]: |
11853
97b02eed7f57
<b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
11850
diff
changeset
|
11 argorg.append(arg) |
11848
fb7d032ba453
<wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff
changeset
|
12 argfoldv.append(arg.casefold()) |
11853
97b02eed7f57
<b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
11850
diff
changeset
|
13 foundv.append(False) |
12023
f79df0b509c8
<b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
12022
diff
changeset
|
14 with open(os.environ.get("HACKENV","/hackenv") + "/share/whatis", errors="surrogateescape") as whatisdb: |
11848
fb7d032ba453
<wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff
changeset
|
15 for line in whatisdb: |
fb7d032ba453
<wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff
changeset
|
16 parts = re.match(r"([^()]+)\(([0-9A-Z_a-z]+)\)", line) |
fb7d032ba453
<wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff
changeset
|
17 if parts: |
fb7d032ba453
<wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff
changeset
|
18 match = False |
11853
97b02eed7f57
<b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
11850
diff
changeset
|
19 for argind, argfold in enumerate(argfoldv): |
97b02eed7f57
<b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
11850
diff
changeset
|
20 if argfold == parts.group(1).casefold(): |
97b02eed7f57
<b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
11850
diff
changeset
|
21 match = True |
97b02eed7f57
<b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
11850
diff
changeset
|
22 foundv[argind] = True |
11848
fb7d032ba453
<wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff
changeset
|
23 if match: |
11853
97b02eed7f57
<b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
11850
diff
changeset
|
24 print(line, end="") |
11854
cc933fc31298
<b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
11853
diff
changeset
|
25 for arg, found in zip(argorg, foundv): |
11853
97b02eed7f57
<b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
11850
diff
changeset
|
26 if not found: |
97b02eed7f57
<b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
11850
diff
changeset
|
27 print(arg + ": nothing appropriate.") |