# HG changeset patch # User Jeff Hammel # Date 1277915686 25200 # Node ID 51a6ec0433f72a21fdf5e41c52afe161f36f50f9 # Parent 413945f4c18b3a62d374f7660163766f342465e7 adding abbreviation program diff -r 413945f4c18b -r 51a6ec0433f7 python/a8e.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/a8e.py Wed Jun 30 09:34:46 2010 -0700 @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +import sys +import urllib2 + +def a8e(text): + text = text.split() + retval = [] + for word in text: + if len(word) < 4: + retval.append(word) + else: + retval.append(word[0] + '%d' % (len(word) - 2) + word[1]) + return ' '.join(retval) + +def main(args=sys.argv[1:]): + if len(args) == 1 and (args[0].startswith('http://') + or args[0].startswith('https://')): + text = urllib2.urlopen(args[0]).read() + else: + text = ' '.join(args) + # TODO: read from stdin if no args + print a8e(text) + +if __name__ == '__main__': + main() +