annotate textshaper/url2txt.py @ 23:7ffe000f6f42

removing stub
author Jeff Hammel <k0scist@gmail.com>
date Sun, 23 Feb 2014 10:14:06 -0800
parents e6f680d25d63
children 56fa70e2e239
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3 """
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 get the human-form of the name of the final path segment in a url:
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6 xclip -o | sed 's/_//' | sed 's/.html//'
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7 """
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9 import sys
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11 def url2txt(url):
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12 """gets the text equivalent of a URL"""
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13 url = url.rstrip('/')
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14 if '/' in url:
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15 url = url.rsplit('/')[-1]
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16 if '.' in url:
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17 url = url.split('.', 1)[0]
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
18 url = url.replace('_', ' ')
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19 return url
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
20
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
21
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
22 def main(args=sys.argv[1:]):
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
23 """CLI"""
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
24 for arg in args:
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
25 print url2txt(arg)
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
26
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
27
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
28 if __name__ == '__main__':
e6f680d25d63 migrate url2txt
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
29 main()