Skip to content
This repository was archived by the owner on Jun 29, 2023. It is now read-only.

Commit ee9a0a4

Browse files
committed
get_route now supports coordinats as start and end
1 parent acdd84d commit ee9a0a4

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010

1111
print(get_nearby_stations(48.0933264, 11.537161699999999))
1212

13-
print(get_route(1, 2, max_time_to_dest=12, max_time_to_start=15))
13+
print(get_route((48.1267, 11.62009), 2, max_walk_time_to_dest=12, max_walk_time_to_start=15))

mvg/__init__.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,32 +67,40 @@ def get_stations(station):
6767
stations.append(result)
6868
return stations
6969

70-
def get_route(from_station_id, to_station_id, time=None, arrival_time=False, max_time_to_start=None, max_time_to_dest=None):
70+
def get_route(start, dest, time=None, arrival_time=False, max_walk_time_to_start=None, max_walk_time_to_dest=None):
7171
"""
7272
returns connectionList = [] of possible routes.
7373
Adds departure_datetime and arrival_datetime to array as datetime objects.
7474
"""
7575
url = routing_url
7676
options = []
77-
if from_station_id:
78-
options.append("fromStation=" + str(from_station_id))
77+
78+
if isinstance(start, int):
79+
options.append("fromStation=" + str(start))
80+
elif isinstance(start, tuple) and len(start) == 2:
81+
options.append("fromLatitude=" + str(start[0]))
82+
options.append("fromLongitude=" + str(start[1]))
7983
else:
80-
raise ValueError("A starting station must be given")
81-
if to_station_id:
82-
options.append("toStation=" + str(to_station_id))
84+
raise ValueError("A start must be given; either int station id or tuple latitude longitude")
85+
86+
if isinstance(dest, int):
87+
options.append("toStation=" + str(dest))
88+
elif isinstance(dest, tuple) and len(dest) == 2:
89+
options.append("toLatitude=" + str(dest[0]))
90+
options.append("toLongitude=" + str(dest[1]))
8391
else:
84-
raise ValueError("An ending station must be given")
92+
raise ValueError("A destination must be given; either int station id or tuple latitude longitude")
8593

8694
if time:
8795
if isinstance(time, datetime.datetime):
8896
time = _convert_time(time)
8997
options.append("time=" + str(time))
9098
if arrival_time:
9199
options.append("arrival=true")
92-
if max_time_to_start:
93-
options.append("maxTravelTimeFootwayToStation=" + str(max_time_to_start))
94-
if max_time_to_dest:
95-
options.append("maxTravelTimeFootwayToDestination=" + str(max_time_to_dest))
100+
if max_walk_time_to_start:
101+
options.append("maxTravelTimeFootwayToStation=" + str(max_walk_time_to_start))
102+
if max_walk_time_to_dest:
103+
options.append("maxTravelTimeFootwayToDestination=" + str(max_walk_time_to_dest))
96104

97105
options_url = "&".join(options)
98106
url = routing_url + options_url

0 commit comments

Comments
 (0)