|
12 | 12 | nearby_url = "https://www.mvg.de/api/fahrinfo/location/nearby?latitude={lat}&longitude={lon}" |
13 | 13 | routing_url = "https://www.mvg.de/api/fahrinfo/routing/?" |
14 | 14 | interruptions_url = "https://www.mvg.de/.rest/betriebsaenderungen/api/interruptions" |
| 15 | +id_prefix = "de:09162:" |
| 16 | + |
| 17 | +def _convert_id(old_id: int) -> str: |
| 18 | + return id_prefix + str(old_id) |
15 | 19 |
|
16 | 20 | def _station_sanity_check(id:str): |
17 | 21 | """ |
@@ -206,16 +210,21 @@ def get_route(start, dest, |
206 | 210 | if isinstance(start, tuple) and len(start) == 2: |
207 | 211 | options.append("fromLatitude=" + str(start[0])) |
208 | 212 | options.append("fromLongitude=" + str(start[1])) |
| 213 | + elif isinstance(start, int): |
| 214 | + options.append("fromStation=" + _convert_id(start)) |
209 | 215 | elif _station_sanity_check(start): |
210 | 216 | options.append("fromStation=" + start) |
211 | 217 | else: |
212 | 218 | raise ValueError("A start must be given;\ |
213 | | - either int station id or tuple latitude longitude") |
| 219 | + either int station id, 'new style' string ids \ |
| 220 | + or a tuple with latitude and longitude") |
214 | 221 |
|
215 | 222 |
|
216 | 223 | if isinstance(dest, tuple) and len(dest) == 2: |
217 | 224 | options.append("toLatitude=" + str(dest[0])) |
218 | 225 | options.append("toLongitude=" + str(dest[1])) |
| 226 | + elif isinstance(dest, int): |
| 227 | + options.append("toStation=" + _convert_id(dest)) |
219 | 228 | elif _station_sanity_check(dest): |
220 | 229 | options.append("toStation=" + dest) |
221 | 230 | else: |
@@ -274,7 +283,9 @@ def get_departures(station_id): |
274 | 283 | `departureTimeMinutes`, the time left to the departure in minutes, |
275 | 284 | is added to the response from the api for your convenience. |
276 | 285 | """ |
277 | | - if not _station_sanity_check(station_id): |
| 286 | + if isinstance(station_id, int): |
| 287 | + station_id = _convert_id(station_id) |
| 288 | + elif not _station_sanity_check(station_id): |
278 | 289 | raise TypeError("Please give the int station_id of the station.\ |
279 | 290 | You can find it out by running \ |
280 | 291 | get_id_for_station('Station name')") |
|
0 commit comments