Nervengift / kvvliveapi

KVV live API bindings
63 stars 14 forks source link

API gone? #19

Open harbaum opened 2 years ago

harbaum commented 2 years ago

It seems the KVV API this project makes use of is gone. But since a similar service still exists there may be a new API ...

$ python -m kvvliveapi search Pionierstraße
Error: 404 Client Error: 404 for url: https://live.kvv.de/webapp/stops/byname/Pionierstra%C3%9Fe?key=377d840e54b59adbe53608ba1aad70e8
harbaum commented 2 years ago

There seems to be a new API. A search request for the station name Pionierstraße works like this: https://www.kvv.de/tunnelEfaDirect.php?action=XSLT_STOPFINDER_REQUEST&coordOutputFormat=WGS84[dd.ddddd]&name_sf=pionierstraße&outputFormat=JSON&type_sf=any

Googling for XSLT_STOPFINDER_REQUEST returns links like this one.

Nervengift commented 2 years ago

oof, that looks like a bigger rewrite is needed :( I'll gladly take contributions since I no longer live in Karlsruhe. Might still have a look at it if I find the time.

harbaum commented 2 years ago

There seem to be various endpoints to access KVV information related to this API. Unfortunately some (incl. tunnelfadirect) return HTML even if JSON is requested in some cases. But the aforementioned request for pionierstraße will return stateless "7000238" which in turn can be used like this to get the next ten departures from that station in JSON format:

https://projekte.kvv-efa.de/sl3-alone/XSLT_DM_REQUEST?outputFormat=JSON&coordOutputFormat=WGS84[dd.ddddd]&depType=stopEvents&locationServerActive=1&mode=direct&name_dm=7000238&type_dm=stop&useOnlyStops=1&useRealtime=1&limit=10

The URL doesn't sound "stable" and i'd prefer to use something that sounds more promising to last a little longer ...

Also the returned JSON contains all kinds of unwanted stuff which is a burden for my little microcontroller. And finally I haven't figured out yet to specify a certain track in the request so I can e.g. request only inbound trains. I could filter them out later but that won't allow me to predict the number of departures to be displayed.

So I'd like to figure out:

harbaum commented 2 years ago

Here's a thread discussing this issue as well: https://verkehrsforum-karlsruhe.de/threads/was-ist-mit-der-kvv-live-api-passiert.280/

Spydr06 commented 10 months ago

Hey everyone, I had some time recently and worked a bit with the API, wrote a quick proof-of-concept in Rust and then went ahead and built a little departure monitor from an esp32. You can see the results and code here, but I too couldn't figure out how to filter the output. With the esp32 it works fine, since it has enough ram for the ~2kb needed per departure entry. If I have more time, maybe I can implement proper Rust bindings for the new API. (I know this is a bit off-topic, but maybe someone will find it helpful :))

Spydr06 commented 9 months ago

Had some time, here is a proper rust crate with the bindings, although untested and not feature-complete.