itip, scotty: Add help texts for arguments
[pywienerlinien] / scotty
diff --git a/scotty b/scotty
index 6ea3ae3..8ad87be 100755 (executable)
--- a/scotty
+++ b/scotty
@@ -1,26 +1,28 @@
 #!/usr/bin/env python
 # -*- coding: UTF-8 -*-
 
-from BeautifulSoup import BeautifulSoup, NavigableString
-from urllib2 import urlopen
-from urllib import urlencode
-import settings
-from datetime import datetime, time
-from textwrap import wrap
 import argparse
 import sys
-import os.path
 
 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('origin')
-parser.add_argument('destination')
+parser.add_argument('origin', nargs='?', help='origin station name')
+parser.add_argument('destination', nargs='?', help='destination station name')
 
 args = parser.parse_args()
+
+if not args.origin:
+    args.origin = raw_input('Origin: ')
+
+if not args.destination:
+    args.destination = raw_input('Destination: ')
+
+print >>sys.stderr, 'Searching...',
 html = search((args.origin, args.ot), (args.destination, args.dt)).read()
+print >>sys.stderr, 'done.'
 
 parser = sParser(html)
 state = parser.check_page()
@@ -38,9 +40,9 @@ if state == PageType.CORRECTION:
                     print '%d. %s' % (i, c)
                     i += 1
                 lo = sys.stdin.readline().strip()
-            
+
             args.origin = cor[0][int(lo) - 1]
-            
+
         if cor[1]:
             print
             print '* Destination ambiguous:'
@@ -51,17 +53,17 @@ if state == PageType.CORRECTION:
                     print '%d. %s' % (j, c)
                     j += 1
                 ld = sys.stdin.readline().strip()
-                
+
             args.destination = cor[1][int(ld) - 1]
-        
+
         html = search((args.origin.encode('UTF-8'), args.ot), (args.destination.encode('UTF-8'), args.dt)).read()
 
         parser = sParser(html)
         state = parser.check_page()
-        
+
     except ParserError:
         print 'PANIC at correction page'
-        
+
 if state == PageType.RESULT:
     parser = rParser(html)
     try:
@@ -83,7 +85,7 @@ if state == PageType.RESULT:
             l = sys.stdin.readline().strip()
             print
             print '~' * 100
-            
+
             if l.isdigit() and int(l) <= len(details):
                 for detail in details[int(l) - 1]:
                     if detail['time'] and detail['station']:
@@ -93,9 +95,9 @@ if state == PageType.RESULT:
                         print '\n'.join(detail['info'])
                     print '-' * 100
             print
-            
+
     except ParserError:
         print 'parsererror'
-        
+
 elif state == PageType.UNKNOWN:
     print 'PANIC unknown result'