Skip to content

Commit 431cf89

Browse files
committed
find stops by name
1 parent a36da67 commit 431cf89

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

main

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ url_i = "/interfaces/ura/instant_V1"
1515
filter = "?ReturnList=StopPointName,StopID,StopPointState,StopPointIndicator,Latitude,Longitude,VisitNumber,TripID,VehicleID,LineID,LineName,DirectionID,DestinationName,DestinationText,EstimatedTime,BaseVersion"
1616
filter_s = "&StopID={}"
1717
filter_l = "&LineID={}"
18-
usage = 'Usage: {} [StopID] [BusIDs]'
18+
usage = 'Usage: {} [Stop] [BusIDs]'
1919
infotext = "Haltestelle: {}\nHaltestellenID: {}\nLinienfilter: {}"
2020
empty = "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

4646
def debug(text):
@@ -49,6 +49,26 @@ def debug(text):
4949

5050
stops = 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+
5272
def 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

Comments
 (0)