changeset 8:44950f376e98

add FedEx tracking number handler
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 08 Apr 2010 14:37:48 -0700
parents d5343f681ef9
children 4dd12cf64c0e
files setup.py smartopen/handlers.py
diffstat 2 files changed, 21 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('README.txt').read()
 except:
     description = ''
 
-version = '0.1.3'
+version = '0.1.4'
 
 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',
@@ -31,10 +31,11 @@ setup(name='smartopen',
 
       [smartopen.locations]
       URL = smartopen.handlers:URL
       GoogleMaps = smartopen.handlers:GoogleMaps
       Wikipedia = smartopen.handlers:Wikipedia
       Google = smartopen.handlers:Google
       Trac = smartopen.handlers:Trac
       Bugzilla = smartopen.handlers:Bugzilla
+      FedEx = smartopen.handlers:FedEx
       """,
       )
--- a/smartopen/handlers.py
+++ b/smartopen/handlers.py
@@ -114,8 +114,27 @@ class Bugzilla(Location):
 class Google(Location):
     def __init__(self):        
         googleurl = 'http://www.google.com/search?hl=en&q='
         Location.__init__(self, googleurl)
         
     def process(self, query):
         return urllib.quote_plus(query)
 
+class FedEx(Location):
+    def __init__(self):
+        baseurl = 'http://www.fedex.com/Tracking?cntry_code=us&language=english&tracknumber_list='
+        Location.__init__(self, baseurl)
+
+    def process(self, query):
+        if query.count(' ') == 2:
+            query = ''.join(query.split(' '))        
+        return query
+
+    def test(self, query):
+        query = self.process(query)
+        if len(query) != 12:
+            return False
+        try:
+            int(query)
+        except ValueError:
+            return False
+        return True