Mercurial > hg > config
annotate python/url2txt.py @ 623:69babe3ef8a7
STUB: .bashrc
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Wed, 05 Feb 2014 13:38:00 -0800 |
parents | 38dd72d72086 |
children |
rev | line source |
---|---|
361
5e0b4ec36013
add another textshaper thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
5e0b4ec36013
add another textshaper thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
2 |
406 | 3 # TODO: add url2txt as pluggable thingy for smartopen |
4 | |
361
5e0b4ec36013
add another textshaper thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
5 # xclip -o | sed 's/_//' | sed 's/.html//' |
5e0b4ec36013
add another textshaper thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
6 |
5e0b4ec36013
add another textshaper thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
7 def url2txt(url): |
5e0b4ec36013
add another textshaper thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
8 """gets the text equivalent of a URL""" |
5e0b4ec36013
add another textshaper thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
9 url = url.rstrip('/') |
5e0b4ec36013
add another textshaper thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
10 if '/' in url: |
5e0b4ec36013
add another textshaper thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
11 url = url.rsplit('/')[-1] |
5e0b4ec36013
add another textshaper thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
12 if '.' in url: |
5e0b4ec36013
add another textshaper thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
13 url = url.split('.', 1)[0] |
5e0b4ec36013
add another textshaper thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
14 url = url.replace('_', ' ') |
5e0b4ec36013
add another textshaper thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
15 return url |
5e0b4ec36013
add another textshaper thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
16 |
5e0b4ec36013
add another textshaper thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
17 if __name__ == '__main__': |
5e0b4ec36013
add another textshaper thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
18 import sys |
5e0b4ec36013
add another textshaper thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
19 print url2txt(' '.join(sys.argv[1:])) |