changeset 18:122b9dcffdaa default tip

stub url2txt
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 03 Aug 2013 23:17:04 -0700
parents a815b73c8e19
children
files setup.py smartopen/url2txt.py
diffstat 2 files changed, 28 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/setup.py	Wed May 01 22:18:51 2013 -0700
+++ b/setup.py	Sat Aug 03 23:17:04 2013 -0700
@@ -6,7 +6,7 @@
 except:
     description = ''
 
-version = '0.2'
+version = '0.2.1'
 
 setup(name='smartopen',
       version=version,
@@ -28,6 +28,7 @@
       # -*- Entry points: -*-
       [console_scripts]
       smartopen = smartopen.smartopen:main
+      url2txt = smartopen.url2txt:main
 
       [smartopen.locations]
       URL = smartopen.handlers:URL
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/smartopen/url2txt.py	Sat Aug 03 23:17:04 2013 -0700
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+
+# TODO: make url2txt a pluggable thingy
+
+import sys
+
+def url2txt(url):
+    """
+    gets the text equivalent of a URL:
+    # xclip -o | sed 's/_//' | sed 's/.html//'
+    """
+    # TODO: rename -> url2name
+    
+    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:]):
+    print url2txt(' '.join(sys.argv[1:]))
+
+if __name__ == '__main__':
+    main()