diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/textshaper/url2txt.py	Sun Feb 23 00:45:06 2014 -0800
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+
+"""
+get the human-form of the name of the final path segment in a url:
+
+xclip -o | sed 's/_//' | sed 's/.html//'
+"""
+
+import sys
+
+def url2txt(url):
+    """gets the text equivalent of a URL"""
+    url = url.rstrip('/')
+    if '/' in url:
+        url = url.rsplit('/')[-1]
+    if '.' in url:
+        url = url.split('.', 1)[0]
+    url = url.replace('_', ' ')
+    return url
+
+
+def main(args=sys.argv[1:]):
+    """CLI"""
+    for arg in args:
+        print url2txt(arg)
+
+
+if __name__ == '__main__':
+    main()