@@ -15,7 +15,7 @@ url_i = "/interfaces/ura/instant_V1"
1515filter = "?ReturnList=StopPointName,StopID,StopPointState,StopPointIndicator,Latitude,Longitude,VisitNumber,TripID,VehicleID,LineID,LineName,DirectionID,DestinationName,DestinationText,EstimatedTime,BaseVersion"
1616filter_s = "&StopID={}"
1717filter_l = "&LineID={}"
18- usage = 'Usage: {} [StopID ] [BusIDs]'
18+ usage = 'Usage: {} [Stop ] [BusIDs]'
1919infotext = "Haltestelle: {}\n HaltestellenID: {}\n Linienfilter: {}"
2020empty = "Das Problem an dem System, ja, ist das System, ja!"
2121
@@ -40,7 +40,7 @@ def file2dict(fn): #file(name) to dict
4040 with open (fn , 'r' ) as fh :
4141 for line in fh :
4242 (number , name ) = line .split (' ' , 1 )
43- rtn [int (number )] = name
43+ rtn [int (number )] = name . strip ()
4444 return rtn
4545
4646def debug (text ):
@@ -49,6 +49,26 @@ def debug(text):
4949
5050stops = file2dict (stopfile )
5151
52+ def lookup_stop_by_name (name ):
53+ found = []
54+ for elem in stops .items ():
55+ if DEBUG :
56+ print (elem )
57+ if name in elem [1 ]:
58+ found .append (elem )
59+ if DEBUG :
60+ print (found )
61+ if len (found ) == 1 :
62+ return found [0 ][0 ]
63+ elif len (found ) == 0 :
64+ print ("{} is not a valid stop name" .format (name ))
65+ exit (3 )
66+ else :
67+ print ("Found more than one match:" )
68+ for i in found :
69+ print ("{}" .format (i [1 ]))
70+ exit (4 )
71+
5272def parseargv (): #parses argv, returns StopID and LineID
5373 query_stop = defaultstop
5474 query_ids = []
@@ -59,11 +79,13 @@ def parseargv(): #parses argv, returns StopID and LineID
5979 continue
6080 if (len (elem ) == 6 and elem .isdigit ()):
6181 query_stop = int (elem )
62- elif (1 <= len (elem ) <= 3 and elem .isdigit ()):
63- query_ids .append (elem )
6482 elif elem == 'debug' :
6583 global DEBUG
6684 DEBUG = True
85+ elif elem .isprintable ():
86+ query_stop = lookup_stop_by_name (elem )
87+ elif (1 <= len (elem ) <= 3 and elem .isdigit ()):
88+ query_ids .append (elem )
6789 else :
6890 print ("Unknown parameter {!r}" .format (elem ))
6991 query_ids .sort (key = int )
0 commit comments