Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB: support "best price search" #291

Open
derhuerst opened this issue May 8, 2023 · 10 comments · May be fixed by #314
Open

DB: support "best price search" #291

derhuerst opened this issue May 8, 2023 · 10 comments · May be fixed by #314

Comments

@derhuerst
Copy link
Member

derhuerst commented May 8, 2023

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 juliuste/db-prices#33 (comment) . 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:

  • 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.

pyhafas equivalent Issue: FahrplanDatenGarten/pyhafas#26

@derhuerst
Copy link
Member Author

@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
Copy link

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

@TheRealMurmel
Copy link

@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
Copy link
Member Author

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
Copy link

I'll give it a try!

@derhuerst
Copy link
Member Author

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

@bergmannjg
Copy link
Contributor

@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
Copy link
Contributor

@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

  • there is a new bestPrices method, which is only valid for the db profile
  • the parsed value of the res.outDaySegL array is the result of bestPrices
  • a first unit test is in db-bestprice.js

@thigg
Copy link

thigg commented Mar 12, 2024

Is this planned to be merged? / worked on?

Here is my (not yet complete) implementation

@thigg
Copy link

thigg commented Mar 20, 2024

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

@derhuerst derhuerst linked a pull request Mar 20, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

4 participants