-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathno.py
50 lines (40 loc) · 1.08 KB
/
no.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
"""
Replace all words with no, preserving punctuation. Based on meow.py.
"""
import argparse
import sys
import meow
def no(word):
"""Noify a word"""
length = len(word)
# Words longer than two will have:
# * first letter N
# * all others O
return meow.capify("n" + ("o" * (length - 1)), word)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Replace all words with nos, preserving punctuation."
)
parser.add_argument(
"infile",
nargs="?",
type=argparse.FileType("r"),
default=sys.stdin,
help="Input text",
)
parser.add_argument(
"-t",
"--translation",
action="store_true",
help="Output a line-by-line translation",
)
args = parser.parse_args()
# for line in fileinput.input(openhook=fileinput.hook_encoded("utf-8")):
for line in args.infile:
line = line.rstrip() # No BOM
if args.translation:
print()
print(line)
print(meow.meow_meow(line, no))
# End of file