mondbaron / mvg

An unofficial interface to timetable information of the Münchner Verkehrsgesellschaft (MVG).
https://pypi.org/project/mvg
MIT License
21 stars 8 forks source link

Trying to get the stations from outside München returns "Invalid station" #1

Closed danielbacara closed 1 year ago

danielbacara commented 1 year ago

Hi,

I am trying to get this package working for my station, e.g. in Ebersberg and get always Invalid Station.

Either, there is a wrong usage from my side, MVG updated their interfaces or something else is wrong.

Below is a reproducible code, which I hope it can help investigating this issue:

The response from MvgApi.stations() for Ebersberg looks as follows

{'name': 'Ebersberg', 'place': 'Ebersberg (Obb.)', 'id': 'de:09175:4070', 'divaId': 4070, 'abbreviation': None, 'tariffZones': '3|4', 'products': ['BUS', 'SBAHN', 'BAHN'], 'latitude': 48.0752, 'longitude': 11.97006}

Then using this information in the example from the README I get Invalid station

from mvg import MvgApi

station = MvgApi.station('Ebersberg, Ebersberg (Obb.)')
if station:
    mvgapi = MvgApi(station['id'])
    departures = mvgapi.departures()
    print(station, departures)

I also tried with the station ID and got the same error.

Any thoughts?

jannikobenhoff commented 1 year ago

Try to use the async functionality. Works for me. For example:

async def demo() -> None:
  station = await MvgApi.station_async('Ebersberg, Ebersberg (Obb.)')
  if station:
      departures = MvgApi.departures_async(station['id'],
                                           transport_types=[TransportType.SBAHN])
      print(station, await departures)
loop = asyncio.get_event_loop()
loop.run_until_complete(demo())
danielbacara commented 1 year ago

Thanks @jannikobenhoff for your reply. Indeed with async this works. However for smaller villages where only bus stations exist, e.g. Egmating, Schule I don't get any departure,

The station is correctly identified because it returns the right station ID: {'id': 'de:09175:4212', 'name': 'Egmating, Schule', 'place': 'Egmating'}, but there is no departure.

The return of the demo above is: {'id': 'de:09175:4212', 'name': 'Egmating, Schule', 'place': 'Egmating'} [] where the departure list is empty

Any ideas?

danielbacara commented 1 year ago

OK, I have some more info. It seems as an issue with the v2 API of the MVG.

In order to get the departures of the Regional Buses, the transport type TransportType.REGIONAL_BUS] must be explicitly set. The demo above works now. (Using async approach of course)

mondbaron commented 1 year ago

@danielbacara: I was able to reproduce the Invalid station of "Ebersberg, Ebersberg (Obb.)". The station is not listed in https://www.mvg.de/.rest/zdm/mvgStationGlobalIds which I used for validation - so I consider this list useless and will skip the validation with commit d228e42, which will be available in the next release.

mondbaron commented 1 year ago

@danielbacara: I was able to reproduce the empty result of departures() for "Egmating, Schule". As you said the MVG endpoint requires to explicitly pass the transport type REGIONAL_BUS. So in commit 0d79bfe I changed the code to pass all transport types if none is provided. Will be part of the next release, too.