Skip to content
This repository has been archived by the owner on Nov 6, 2021. It is now read-only.

Update to use new API #12

Open
pc-coholic opened this issue Oct 29, 2018 · 5 comments
Open

Update to use new API #12

pc-coholic opened this issue Oct 29, 2018 · 5 comments

Comments

@pc-coholic
Copy link
Owner

MVG has launched a new API while keeping the old one online.

Unfortunately, it seems like the data served by the old (currently used) API is staring to degrade. For example, queries for Garching-Hochbrück only return U-Bahn-trains but not any busses.

The new API lives at https://www.mvg.de/fahrinfo/api/departure/480?footway=0, where footway takes the current timeoffset parameter and 480 is the ID of the station (in this example: Garching-Hochbrück).

Querying for station-data can be done at https://www.mvg.de/fahrinfo/api/location/queryWeb?q=garching, with the q-parameter obviously being the search-string.

Queries need to be authorized by providing the "X-MVG-Authorization-Key-header. One possible value is for example 5af1beca494712ed38d313714d4caff6 (mvg.de website-key).

The new API is a lot more usable as it does not need any of that RPC-decryption that is currently used.

If anyone feels like implementing the new API - possibly while keeping compatibility to the current Syntax: please do so :-)

@mammuth
Copy link

mammuth commented Oct 8, 2019

Note for people stumbling over this via Google:

The endpoint seems to check the user agent and restricts access for eg. using request's default one.
The following works for me as of today:

station = 2  # Marienplatz
url = f'https://www.mvg.de/fahrinfo/api/departure/{station}?footway=0'
headers = {'X-MVG-Authorization-Key': '5af1beca494712ed38d313714d4caff6', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36'}

requests.get(url, headers=headers).json()

@jeff25
Copy link

jeff25 commented Jan 9, 2020

Hi,

i try to use your sample but did not work... do you have any idea why, is there any change in the MVG API?

Br,
RObert

@pc-coholic
Copy link
Owner Author

That is quite possible - they love to change things around...

A quick check on their website reveals, that there have apparently been some changes...

For example, the call for Marienplatz is now https://www.mvg.de/api/fahrinfo/departure/de:09162:2?footway=0, the one for Ostbahnhof https://www.mvg.de/api/fahrinfo/departure/de:09162:5?footway=0.

The Search-Endpoint (https://www.mvg.de/api/fahrinfo/location/queryWeb?q=ost) will provide you with the correct station id.

Furthermore, the API-token seems to be now x-api-token: Vv7L4Gbu2k.

Someone[TM] should really update this library to use the new endpoints and data ;-)

@jeff25
Copy link

jeff25 commented Jan 9, 2020

Thanks, i did nearly the same and check with chrome developer tools and now your code works with the new station ID´s :-) THanks!

@laim2003
Copy link

The api token was not required in my case

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants