annotate a8e.py @ 1:dd3f3918cb88 default tip

give a version
author Jeff Hammel <k0scist@gmail.com>
date Thu, 14 Jul 2016 12:32:36 -0700
parents 6670fe246450
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
6670fe246450 initial commit
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
6670fe246450 initial commit
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2
6670fe246450 initial commit
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3 import sys
6670fe246450 initial commit
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 import urllib2
6670fe246450 initial commit
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5
6670fe246450 initial commit
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6 def a8e(text):
6670fe246450 initial commit
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7 text = text.split()
6670fe246450 initial commit
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 retval = []
6670fe246450 initial commit
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9 for word in text:
6670fe246450 initial commit
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10 if len(word) < 4:
6670fe246450 initial commit
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11 retval.append(word)
6670fe246450 initial commit
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12 else:
6670fe246450 initial commit
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13 retval.append(word[0] + '%d' % (len(word) - 2) + word[-1])
6670fe246450 initial commit
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14 return ' '.join(retval)
6670fe246450 initial commit
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15
6670fe246450 initial commit
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16 def main(args=sys.argv[1:]):
6670fe246450 initial commit
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17 if len(args) == 1 and (args[0].startswith('http://')
6670fe246450 initial commit
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
18 or args[0].startswith('https://')):
6670fe246450 initial commit
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19 text = urllib2.urlopen(args[0]).read()
6670fe246450 initial commit
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
20 else:
6670fe246450 initial commit
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
21 text = ' '.join(args)
6670fe246450 initial commit
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
22 # TODO: read from stdin if no args
6670fe246450 initial commit
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
23 print a8e(text)
6670fe246450 initial commit
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
24
6670fe246450 initial commit
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
25 if __name__ == '__main__':
6670fe246450 initial commit
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
26 main()
6670fe246450 initial commit
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
27