Skip to content

Commit af1650b

Browse files
committed
another version
1 parent 73c004d commit af1650b

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env python3
2+
"""Kentucky Friar"""
3+
4+
import argparse
5+
import os
6+
import re
7+
8+
9+
# --------------------------------------------------
10+
def get_args():
11+
"""Get command-line arguments"""
12+
13+
parser = argparse.ArgumentParser(
14+
description='Southern fry text',
15+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
16+
17+
parser.add_argument('text', metavar='text', help='Input text or file')
18+
19+
args = parser.parse_args()
20+
21+
if os.path.isfile(args.text):
22+
args.text = open(args.text).read()
23+
24+
return args
25+
26+
27+
# --------------------------------------------------
28+
def main():
29+
"""Make a jazz noise here"""
30+
31+
args = get_args()
32+
splitter = re.compile(r'(\W+)')
33+
34+
for line in args.text.splitlines():
35+
print(''.join(map(fry, splitter(line.rstrip()))))
36+
37+
38+
# --------------------------------------------------
39+
def fry(word):
40+
"""Drop the `g` from `-ing` words, change `you` to `y'all`"""
41+
42+
ing_word = re.search('(.+)ing$', word)
43+
you = re.match('([Yy])ou$', word)
44+
45+
if ing_word:
46+
prefix = ing_word.group(1)
47+
if re.search('[aeiouy]', prefix, re.IGNORECASE):
48+
return prefix + "in'"
49+
elif you:
50+
return you.group(1) + "'all"
51+
52+
return word
53+
54+
55+
# --------------------------------------------------
56+
def test_fry():
57+
"""Test fry"""
58+
59+
assert fry('you') == "y'all"
60+
assert fry('You') == "Y'all"
61+
assert fry('your') == 'your'
62+
assert fry('fishing') == "fishin'"
63+
assert fry('Aching') == "Achin'"
64+
assert fry('swing') == "swing"
65+
66+
67+
# --------------------------------------------------
68+
if __name__ == '__main__':
69+
main()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy