public-transport / hafas-client

JavaScript client for HAFAS public transport APIs.
ISC License
277 stars 53 forks source link

DB: support "best price search" #291

Open derhuerst opened 1 year ago

derhuerst commented 1 year ago

Both the Deutsche Bahn (DB) website as well as their app have a feature called "best price search" or "Bestpreissuche", which works just like the regular journeys() (TripSearch in HAFAS), except that it returns the lowest-price journeys for each time bracket.

The details of this BestPriceSearch call are documented at https://github.com/juliuste/db-prices/issues/33#issuecomment-1538776446 . It's response data looks like the one of a TripSearch call, but it also has a field res.outDaySegL that groups the journeys in res.outConL[] into time brackets.

Not sure how this functionality should be exposed:


pyhafas equivalent Issue: https://github.com/FahrplanDatenGarten/pyhafas/issues/26

derhuerst commented 1 year ago

@TheRealMurmel FYI: Implementing the "best price search" feature here in hafas-client, as described above, would be quite straightforward, as most of the response structure is already supported.

TheRealMurmel commented 1 year ago

@derhuerst I would really like to provide more help, but I'm note quite sure when I will have time to contribute here.

TheRealMurmel commented 1 year ago

@derhuerst I built a small Python-based project to replay the relevant API requests, this might help someone else to re-implement the requests into hafas-client:

https://github.com/TheRealMurmel/py-bahn-api

derhuerst commented 1 year ago

BTW, if you're more comfortable tinkering with Python instead of JS, adding support for "best price search" to pyhafas would also be an option! We can then port the code over to hafas-client.

TheRealMurmel commented 1 year ago

I'll give it a try!

derhuerst commented 1 year ago

@bergmannjg has built an "MVP" implementation of this.

bergmannjg commented 1 year ago

@bergmannjg has built an "MVP" implementation of this.

It's nothing more than replacing

meth: "TripSearch"

with

meth: "BestPriceSearch"

in the corresponding HAFAS request.

It works.

bergmannjg commented 1 year ago

@derhuerst said

Not sure how this functionality should be exposed:

  • We could let journeys() always parse & expose a grouping/bracketing of journeys as soon as the HAFAS response contains it. A DB-specific opt.bestPriceSearch option would use BestPriceSearch and outTime: "000000".
  • Within the DB profile, we could implement it as an entirely separate hafas-client method. It would have to share much of the logic with journeys(). Currently, we don't have a mechanism to let profiles add methods though.

I would propose to add an new method to the hafas-client API because the bestprice search options are only a subset of the journey search options and the results are different.

Here is my (not yet complete) implementation

thigg commented 8 months ago

Is this planned to be merged? / worked on?

Here is my (not yet complete) implementation

thigg commented 8 months ago

I am running this for a few days already without problems, just added the date as a parameter.