comparison textshaper/url2txt.py @ 38:56fa70e2e239

STUB: textshaper/url2txt.py
author Jeff Hammel <k0scist@gmail.com>
date Thu, 03 Jul 2014 13:23:19 -0700
parents e6f680d25d63
children 986f8a20c234
comparison
equal deleted inserted replaced
37:8cf9a26b9aaa 38:56fa70e2e239
4 get the human-form of the name of the final path segment in a url: 4 get the human-form of the name of the final path segment in a url:
5 5
6 xclip -o | sed 's/_//' | sed 's/.html//' 6 xclip -o | sed 's/_//' | sed 's/.html//'
7 """ 7 """
8 8
9 import argparse
9 import sys 10 import sys
10 11
11 def url2txt(url): 12 def url2txt(url):
12 """gets the text equivalent of a URL""" 13 """gets the text equivalent of a URL"""
13 url = url.rstrip('/') 14 url = url.rstrip('/')
19 return url 20 return url
20 21
21 22
22 def main(args=sys.argv[1:]): 23 def main(args=sys.argv[1:]):
23 """CLI""" 24 """CLI"""
24 for arg in args: 25
25 print url2txt(arg) 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))
26 35
27 36
28 if __name__ == '__main__': 37 if __name__ == '__main__':
29 main() 38 main()