comparison textshaper/url2txt.py @ 21:e6f680d25d63

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