Open Cediddi opened 3 years ago
- Select a station and get details (name='Berlin, Mollstr./Otto-Braun-Str.' id='900000100040')
You're fetching https://v5.vbb.transport.rest/stops/900000100040?linesOfStops=true
I assume?
- Select a line from the station (name=M8 id='17463_900')
An M8
line with an id
of 17463_900
doesn't exist for me:
curl 'https://v5.vbb.transport.rest/stops/900000100040?linesOfStops=true' -s | jq
{
"type": "stop",
"id": "900000100040",
"name": "Mollstr./Otto-Braun-Str.",
"location": {
"type": "location",
"id": "900100040",
"latitude": 52.525185,
"longitude": 13.419942
},
"products": {
"suburban": false,
"subway": false,
"tram": true,
"bus": true,
"ferry": false,
"express": false,
"regional": false
},
"lines": [
{
"type": "line",
"id": "12",
"fahrtNr": null,
"name": "12",
"public": true,
"mode": "train",
"product": "tram",
"symbol": null,
"nr": 12,
"metro": false,
"express": false,
"night": false,
"color": {
"fg": "#fff",
"bg": "#6c5b98"
}
},
{
"type": "line",
"id": "50",
"fahrtNr": null,
"name": "50",
"public": true,
"mode": "train",
"product": "tram",
"symbol": null,
"nr": 50,
"metro": false,
"express": false,
"night": false,
"color": {
"fg": "#fff",
"bg": "#16a696"
}
},
{
"type": "line",
"id": "m1",
"fahrtNr": null,
"name": "M1",
"public": true,
"mode": "train",
"product": "tram",
"symbol": "M",
"nr": 1,
"metro": true,
"express": false,
"night": false,
"color": {
"fg": "#fff",
"bg": "#ed9222"
}
},
{
"type": "line",
"id": "m2",
"fahrtNr": null,
"name": "M2",
"public": true,
"mode": "train",
"product": "tram",
"symbol": "M",
"nr": 2,
"metro": true,
"express": false,
"night": false,
"color": {
"fg": "#fff",
"bg": "#7eb43d"
}
},
{
"type": "line",
"id": "m4",
"fahrtNr": null,
"name": "M4",
"public": true,
"mode": "train",
"product": "tram",
"symbol": "M",
"nr": 4,
"metro": true,
"express": false,
"night": false,
"color": {
"fg": "#fff",
"bg": "#d01c22"
}
},
{
"type": "line",
"id": "m5",
"fahrtNr": null,
"name": "M5",
"public": true,
"mode": "train",
"product": "tram",
"symbol": "M",
"nr": 5,
"metro": true,
"express": false,
"night": false,
"color": {
"fg": "#fff",
"bg": "#c48946"
}
},
{
"type": "line",
"id": "m6",
"fahrtNr": null,
"name": "M6",
"public": true,
"mode": "train",
"product": "tram",
"symbol": "M",
"nr": 6,
"metro": true,
"express": false,
"night": false,
"color": {
"fg": "#fff",
"bg": "#01609c"
}
},
{
"type": "line",
"id": "m8",
"fahrtNr": null,
"name": "M8",
"public": true,
"mode": "train",
"product": "tram",
"symbol": "M",
"nr": 8,
"metro": true,
"express": false,
"night": false,
"color": {
"fg": "#fff",
"bg": "#f47922"
}
},
{
"type": "line",
"id": "142",
"fahrtNr": null,
"name": "142",
"public": true,
"mode": "bus",
"product": "bus",
"symbol": null,
"nr": 142,
"metro": false,
"express": false,
"night": false
},
{
"type": "line",
"id": "200",
"fahrtNr": null,
"name": "200",
"public": true,
"mode": "bus",
"product": "bus",
"symbol": null,
"nr": 200,
"metro": false,
"express": false,
"night": false
}
]
}
- Select the variant with most trips (the one with 371 trips)
How do you do that? Where do you get the number of trips from?
I can provide a pseudo code.
response = GET https://v5.vbb.transport.rest/stations?query=mollstr
station = select first from request where name = 'Berlin, Mollstr./Otto-Braun-Str.'
response = GET https://v5.vbb.transport.rest/stations/{station['id']}
line = select first from response['lines'] where name = 'M8'
response = GET https://v5.vbb.transport.rest/lines/{line['id']}
variant = select first from response['variants'] order by trips descending
first_stop = select first from variant['stops']
response = GET https://v5.vbb.transport.rest/stops/{first_stop}
// response is 502
I'm using python, you can check the script that I'm writing. Problematic part is line 186
https://gist.github.com/Cediddi/cfcf84aa3541a46beeee4064e3e33e40#file-allons_y-py-L186
Ah, now I understand the problem!
These routes just return GTFS data:
/stations?…
/stations/{id}
/lines/{id}
The other routes (including /stops/{id}
) query VBB's HAFAS API.
Unfortunately, the GTFS stop/station IDs & line IDs don't always match the HAFAS stop/station IDs & line IDs. Most of the times they work with HAFAS, but "haltepunkt"-like stop IDs (e.g. those of individual tram tracks at a station) apparently don't.
Sorry, this is really not documented at all. 😔
Can you tell me what you would like to build? Maybe I can tell you how to solve this with the v5.vbb.transport.rest
API.
It is a coding challenge for a job application, thus I cannot share the question.
I think this API needs an open api documentation, other than that I think it's a great api and really easy to use and understand.
Completely agree, I've been planning to add an Open API spec for a while, just haven't found the time & motivation to do it yet.
[...] I think it's a great api and really easy to use and understand.
Well, I disagree in regards to the opaque HAFAS/GTFS distinction.
Hi, I'm trying to use this library and I'm following a workflow like this:
Last step throws an error like this:
The query I'm running looks like this
https://v5.vbb.transport.rest/stops/070301009267
I think my workflow is correct and this is a bug. Can you confirm?