From 6124c24c27955fba67bd792bf3a06b9c4325f14f Mon Sep 17 00:00:00 2001 From: Fbenas Date: Fri, 6 Nov 2020 00:59:32 +0000 Subject: Add from bratchbot, slightly broken from python upgrade --- initialism.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 initialism.py diff --git a/initialism.py b/initialism.py new file mode 100755 index 0000000..f94496b --- /dev/null +++ b/initialism.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python + +""" +Take a list of words as argument and return the equivalent initialism. + +Example: + $ initialism got a cup of tea + $ GACOT +""" + +import optparse +import sys + +VERSION = '1.0.0' + + +def parse_args(): + args = sys.argv[1:] + if not args: + args = sys.stdin.read().split() + + parser = optparse.OptionParser(usage='!initialism []+ [-v|--version]') + parser.add_option('-v', '--version', action='store_true') + return parser.parse_args(args) + + +def initialise( words ): + """ + Take the first grapheme from each of the words and uppercase it + returning a new unicode string created from them. + """ + return u''.join([word[0].upper() for word in words]) + + +def main(): + (options, args) = parse_args() + if options.version: + print ('!initialism {0}'.format(VERSION)) + sys.exit(0) + + words = [word.decode('utf-8') for word in args] + initialism = initialise(words) + print (initialism.encode('utf-8')) + + +if __name__ == '__main__': + main() -- cgit v1.2.3