Mercurial > hg > a8e
comparison a8e.py @ 0:6670fe246450
initial commit
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Thu, 14 Jul 2016 12:27:21 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:6670fe246450 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 import sys | |
4 import urllib2 | |
5 | |
6 def a8e(text): | |
7 text = text.split() | |
8 retval = [] | |
9 for word in text: | |
10 if len(word) < 4: | |
11 retval.append(word) | |
12 else: | |
13 retval.append(word[0] + '%d' % (len(word) - 2) + word[-1]) | |
14 return ' '.join(retval) | |
15 | |
16 def main(args=sys.argv[1:]): | |
17 if len(args) == 1 and (args[0].startswith('http://') | |
18 or args[0].startswith('https://')): | |
19 text = urllib2.urlopen(args[0]).read() | |
20 else: | |
21 text = ' '.join(args) | |
22 # TODO: read from stdin if no args | |
23 print a8e(text) | |
24 | |
25 if __name__ == '__main__': | |
26 main() | |
27 |