Routing: Move origin/destination type default into module
authorThomas Perl <m@thp.io>
Thu, 29 Sep 2011 12:07:44 +0000 (14:07 +0200)
committerThomas Perl <m@thp.io>
Thu, 29 Sep 2011 12:07:44 +0000 (14:07 +0200)
gotovienna/routing.py
scotty

index 66a8e0f..7cd9a71 100644 (file)
@@ -34,8 +34,15 @@ def search(origin_tuple, destination_tuple, dtime=None):
 
     origin, origin_type = origin_tuple
     destination, destination_type = destination_tuple
-    if not origin_type in POSITION_TYPES or\
-        not destination_type in POSITION_TYPES:
+
+    if origin_type is None:
+        origin_type = 'stop'
+
+    if destination_type is None:
+        destination_type = 'stop'
+
+    if (origin_type not in POSITION_TYPES or
+            destination_type not in POSITION_TYPES):
         raise ParserError('Invalid position type')
 
     post = defaults.search_post
diff --git a/scotty b/scotty
index 32eb1bc..9a6ecbe 100755 (executable)
--- a/scotty
+++ b/scotty
@@ -8,8 +8,8 @@ from gotovienna.utils import *
 from gotovienna.routing import *
 
 parser = argparse.ArgumentParser(description='Get public transport route for Vienna')
-parser.add_argument('-ot', metavar='type', type=str, help='origin type: %s' % ' | '.join(POSITION_TYPES), default='stop', choices=POSITION_TYPES)
-parser.add_argument('-dt', metavar='type', type=str, help='destination type: %s' % ' | '.join(POSITION_TYPES), default='stop', choices=POSITION_TYPES)
+parser.add_argument('-ot', metavar='type', type=str, help='origin type: %s' % ' | '.join(POSITION_TYPES), default=None, choices=POSITION_TYPES)
+parser.add_argument('-dt', metavar='type', type=str, help='destination type: %s' % ' | '.join(POSITION_TYPES), default=None, choices=POSITION_TYPES)
 parser.add_argument('origin', nargs='?', help='origin station name')
 parser.add_argument('destination', nargs='?', help='destination station name')