annotate python/a8e.py @ 557:d0a479cba82b

adding vpn
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 26 Nov 2013 13:41:40 -0800
parents a7857000e206
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
81
51a6ec0433f7 adding abbreviation program
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 #!/usr/bin/env python
51a6ec0433f7 adding abbreviation program
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2
51a6ec0433f7 adding abbreviation program
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 import sys
51a6ec0433f7 adding abbreviation program
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 import urllib2
51a6ec0433f7 adding abbreviation program
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5
51a6ec0433f7 adding abbreviation program
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6 def a8e(text):
51a6ec0433f7 adding abbreviation program
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7 text = text.split()
51a6ec0433f7 adding abbreviation program
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8 retval = []
51a6ec0433f7 adding abbreviation program
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 for word in text:
51a6ec0433f7 adding abbreviation program
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10 if len(word) < 4:
51a6ec0433f7 adding abbreviation program
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 retval.append(word)
51a6ec0433f7 adding abbreviation program
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12 else:
82
Jeff Hammel <jhammel@mozilla.com>
parents: 81
diff changeset
13 retval.append(word[0] + '%d' % (len(word) - 2) + word[-1])
81
51a6ec0433f7 adding abbreviation program
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14 return ' '.join(retval)
51a6ec0433f7 adding abbreviation program
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15
51a6ec0433f7 adding abbreviation program
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16 def main(args=sys.argv[1:]):
51a6ec0433f7 adding abbreviation program
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17 if len(args) == 1 and (args[0].startswith('http://')
51a6ec0433f7 adding abbreviation program
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18 or args[0].startswith('https://')):
51a6ec0433f7 adding abbreviation program
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19 text = urllib2.urlopen(args[0]).read()
51a6ec0433f7 adding abbreviation program
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20 else:
51a6ec0433f7 adding abbreviation program
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21 text = ' '.join(args)
51a6ec0433f7 adding abbreviation program
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
22 # TODO: read from stdin if no args
51a6ec0433f7 adding abbreviation program
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23 print a8e(text)
51a6ec0433f7 adding abbreviation program
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
24
51a6ec0433f7 adding abbreviation program
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
25 if __name__ == '__main__':
51a6ec0433f7 adding abbreviation program
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
26 main()
51a6ec0433f7 adding abbreviation program
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
27