changeset 18:122b9dcffdaa 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
+++ b/setup.py
@@ -1,17 +1,17 @@
 from setuptools import setup, find_packages
 import sys, os
 
 try:
     description = file(os.path.join(os.path.dirname(__file__), 'README.txt')).read()
 except:
     description = ''
 
-version = '0.2'
+version = '0.2.1'
 
 setup(name='smartopen',
       version=version,
       description="open text in a browser contextually",
       long_description=description,
       classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
       keywords='',
       author='Jeff Hammel',
@@ -23,16 +23,17 @@ setup(name='smartopen',
       zip_safe=False,
       install_requires=[
           # -*- Extra requirements: -*-
       ],
       entry_points="""
       # -*- Entry points: -*-
       [console_scripts]
       smartopen = smartopen.smartopen:main
+      url2txt = smartopen.url2txt:main
 
       [smartopen.locations]
       URL = smartopen.handlers:URL
       GoogleMaps = smartopen.handlers:GoogleMaps
       Wikipedia = smartopen.handlers:Wikipedia
       Wiktionary = smartopen.handlers:Wiktionary
       Google = smartopen.handlers:Google
       Trac = smartopen.handlers:Trac
new file mode 100755
--- /dev/null
+++ b/smartopen/url2txt.py
@@ -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()