|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Author : dickdijk <dickdijk@localhost> |
| 4 | +Date : 2020-08-28 |
| 5 | +Purpose: Rock the Casbah |
| 6 | +""" |
| 7 | + |
| 8 | +import argparse |
| 9 | +import os |
| 10 | +import re |
| 11 | +import string |
| 12 | + |
| 13 | + |
| 14 | +# -------------------------------------------------- |
| 15 | +def get_args(): |
| 16 | + """Get command-line arguments""" |
| 17 | + |
| 18 | + parser = argparse.ArgumentParser( |
| 19 | + description='Southern fry text', |
| 20 | + formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
| 21 | + |
| 22 | + parser.add_argument('text', |
| 23 | + metavar='text', |
| 24 | + help='Input text or file') |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + args= parser.parse_args() |
| 29 | + |
| 30 | + if os.path.isfile(args.text): |
| 31 | + lines = [] |
| 32 | + for line in open(args.text): |
| 33 | + lines.append(line.strip()) |
| 34 | + |
| 35 | + args.text = '\n'.join(lines) |
| 36 | + return args |
| 37 | + |
| 38 | +def fry(word): |
| 39 | + pattern1 = '([yY])(ou)([\W]*$)' |
| 40 | + m = re.match(pattern1, word) |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + if m: |
| 45 | + g = m.groups() |
| 46 | + if g[0] and g[1]: |
| 47 | + return f"{g[0]}'all" |
| 48 | + |
| 49 | + vowels = 'aeuoiAEUOI' |
| 50 | + consonants = ''.join(filter(lambda e: e not in vowels, string.ascii_letters)) |
| 51 | + pattern2 = "(["+consonants+"]*)(["+vowels+"]+)[^'](["+consonants+"]*)(ing)(\W)?" |
| 52 | + |
| 53 | + m = re.match(pattern2, word) |
| 54 | + if m: |
| 55 | + g = m.groups() |
| 56 | + print(g) |
| 57 | + if g[4]: |
| 58 | + end = g[4] |
| 59 | + else: |
| 60 | + end ='' |
| 61 | + if g[1]: |
| 62 | + return ''.join(g[:3])+"in'" + end |
| 63 | + |
| 64 | + return word |
| 65 | + |
| 66 | +def test_fry(): |
| 67 | + assert fry('you') == "y'all" |
| 68 | + assert fry('You') == "Y'all" |
| 69 | + assert fry('fishing') == "fishin'" |
| 70 | + assert fry('Aching') == "Achin'" |
| 71 | + assert fry('swing') == "swing" |
| 72 | +# -------------------------------------------------- |
| 73 | +def main(): |
| 74 | + """Make a jazz noise here""" |
| 75 | + |
| 76 | + args = get_args() |
| 77 | + text = args.text |
| 78 | + |
| 79 | + for line in args.text.splitlines(): |
| 80 | + print(' '.join([fry(w) for w in line.split()])) |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | + # print(fry(text)) |
| 86 | + |
| 87 | +# -------------------------------------------------- |
| 88 | +if __name__ == '__main__': |
| 89 | + main() |
0 commit comments