21
|
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
|
38
|
9 import argparse
|
21
|
10 import sys
|
|
11
|
|
12 def url2txt(url):
|
|
13 """gets the text equivalent of a URL"""
|
|
14 url = url.rstrip('/')
|
|
15 if '/' in url:
|
|
16 url = url.rsplit('/')[-1]
|
|
17 if '.' in url:
|
|
18 url = url.split('.', 1)[0]
|
|
19 url = url.replace('_', ' ')
|
|
20 return url
|
|
21
|
|
22
|
|
23 def main(args=sys.argv[1:]):
|
|
24 """CLI"""
|
38
|
25
|
|
26 # parse command line
|
|
27 parser = argparse.ArgumentParser(description=__doc__)
|
|
28 parser.add_option('urls', metavar='url', nargs='+',
|
|
29 help="URLs to convert")
|
|
30 options = parser.parse_args(args)
|
|
31
|
|
32 # convert urls
|
|
33 for url in options.urls:
|
|
34 print (url2txt(url))
|
21
|
35
|
|
36
|
|
37 if __name__ == '__main__':
|
|
38 main()
|