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

doesn't work #33

Open
gagni opened this issue Jan 20, 2023 · 15 comments · May be fixed by public-transport/hafas-client#314
Open

doesn't work #33

gagni opened this issue Jan 20, 2023 · 15 comments · May be fixed by public-transport/hafas-client#314
Labels

Comments

@gagni
Copy link

gagni commented Jan 20, 2023

Hello,

I tried but it doesn't work, is this normal? I see that the repo is from 2019

@juliuste
Copy link
Owner

Hey, the API this repo uses seems to be unavailable since 2-3 days. I'm currently looking for a workaround, but that might take a few days/weeks. Will update this repo once I found a replacement.

@shameetbadarla
Copy link

Hey, i have the same issue. Is there tentative timeframe when this will be solved?
Thanks!

@gagni
Copy link
Author

gagni commented Feb 24, 2023

do you have any news ?

@TheRealMurmel
Copy link

TheRealMurmel commented May 7, 2023

I had a look at the network traffic.

App

The app displays the following connections and their prices:

DB_Bahn_Verbindungen.png

Request

In order to obtain the prices, the app does the following request:

POST /bin/mgate.exe?checksum=bac6e939533c25bb9d19781735fb165d HTTP/1.1
User-Agent: Dalvik/2.1.0 (Linux; U; Android 9; unknown Build/PI)
Content-Type: application/json;charset=UTF-8
Host: reiseauskunft.bahn.de
Connection: close
Accept-Encoding: gzip, deflate
Content-Length: 629

{
  "auth": {
    "aid": "n91dB8Z77MLdoR0K",
    "type": "AID"
  },
  "client": {
    "id": "DB",
    "name": "DB Navigator",
    "os": "Android 9",
    "res": "1080x2028",
    "type": "AND",
    "ua": "Dalvik/2.1.0 (Linux; U; Android 9; unknown Build/PI)",
    "v": 22080000
  },
  "ext": "DB.R22.04.a",
  "formatted": false,
  "lang": "eng",
  "svcReqL": [
    {
      "cfg": {
        "polyEnc": "GPA"
      },
      "meth": "Reconstruction",
      "req": {
        "getPasslist": true,
        "getPolyline": true,
        "outReconL": [
          {
            "ctx": "T$A=1@O=Frankfurt(Main)Hbf@L=8000105@a=128@$A=1@O=Köln Hbf@L=8000207@a=128@$202305251828$202305251931$ICE   10$$1$$$$$$"
          }
        ],
        "trfReq": {
          "cType": "PK",
          "directESuiteCall": true,
          "jnyCl": 2,
          "rType": "DB-PE",
          "tvlrProf": [
            {
              "type": "E"
            }
          ]
        }
      }
    }
  ],
  "ver": "1.15"
}

as curl:

curl -X $'POST' \
    -H $'User-Agent: Dalvik/2.1.0 (Linux; U; Android 9; unknown Build/PI)' \
    -H $'Content-Type: application/json;charset=UTF-8' \
    -H $'Host: reiseauskunft.bahn.de' \
    -H $'Accept-Encoding: deflate' \
    --data-binary $'{\"auth\":{\"aid\":\"n91dB8Z77MLdoR0K\",\"type\":\"AID\"},\"client\":{\"id\":\"DB\",\"name\":\"DB Navigator\",\"os\":\"Android 9\",\"res\":\"1080x2028\",\"type\":\"AND\",\"ua\":\"Dalvik/2.1.0 (Linux; U; Android 9; unknown Build/PI)\",\"v\":22080000},\"ext\":\"DB.R22.04.a\",\"formatted\":false,\"lang\":\"eng\",\"svcReqL\":[{\"cfg\":{\"polyEnc\":\"GPA\"},\"meth\":\"Reconstruction\",\"req\":{\"getPasslist\":true,\"getPolyline\":true,\"outReconL\":[{\"ctx\":\"T$A=1@O=Frankfurt(Main)Hbf@L=8000105@a=128@$A=1@O=K\xc3\xb6ln Hbf@L=8000207@a=128@$202305251828$202305251931$ICE   10$$1$$$$$$\"}],\"trfReq\":{\"cType\":\"PK\",\"directESuiteCall\":true,\"jnyCl\":2,\"rType\":\"DB-PE\",\"tvlrProf\":[{\"type\":\"E\"}]}}}],\"ver\":\"1.15\"}' \
    $'https://reiseauskunft.bahn.de/bin/mgate.exe?checksum=bac6e939533c25bb9d19781735fb165d'

Response

This is the reponse (I removed some parts in order to make it easier to crasp the relevant section):

{
  "ver": "1.15",
  "ext": "DB.R22.04.a",
  "lang": "eng",
  "id": "w2ki6j4mg44xx28x",
  "cInfo": ...,
  "svcResL": [
    {
      "meth": "Reconstruction",
      "err": "OK",
      "res": {
        "common": ...,
        "outConL": [
          {
            "cid": "DirectConReq-0",
            "date": "20230525",
            "dur": "010300",
            "chg": 0,
            "sDays": ...,
            "dep": ...
            "arr": ...,
            "secL": ...,
            "ctxRecon": "T$A=1@O=Frankfurt(Main)Hbf@L=8000105@a=128@$A=1@O=Köln Hbf@L=8000207@a=128@$202305251828$202305251931$ICE   10$$1$$$$$$",
            "trfRes": {
              "fareSetL": [
                {
                  "fareL": ...,
                  "addData": "...",
                  "prc": 5590
                },
                ...
         ],
              ...
            },
            ...
          }
        ],
        ...
      }
    }
  ]
}

So the price is located at svcResL[0].res.outConL[0].trfRes.fareSetL[0].prc

@TheRealMurmel
Copy link

I updated my previous comment in order to provide the curl command for the request, the response and a screenshot of the app

@derhuerst
Copy link
Collaborator

I had a look at the network traffic.
[…]
The app displays the following connections and their prices:

The problem is that this request

  • doesn't provide the cheapest connections at that day (the "Show our best prices" toggle would have to be turned on, which I assume would result in a flag being set in the API), and
  • that it doesn't work across multiple days (which is how the old Sparpreise API worked AFAIK).

@TheRealMurmel
Copy link

With respect to your first comment, the best price option triggers the following request:

curl -X $'POST' \
    -H $'User-Agent: Dalvik/2.1.0 (Linux; U; Android 9; Pixel 3 Build/PI)' \
    -H $'Content-Type: application/json;charset=UTF-8' \
    -H $'Host: reiseauskunft.bahn.de'  \
    -H $'Accept-Encoding: deflate' \
    --data-binary $'{\"auth\":{\"aid\":\"n91dB8Z77MLdoR0K\",\"type\":\"AID\"},\"client\":{\"id\":\"DB\",\"name\":\"DB Navigator\",\"os\":\"Android 9\",\"res\":\"1080x2028\",\"type\":\"AND\",\"ua\":\"Dalvik/2.1.0 (Linux; U; Android 9; Pixel 3 Build/PI)\",\"v\":22080000},\"ext\":\"DB.R22.04.a\",\"formatted\":false,\"lang\":\"eng\",\"svcReqL\":[{\"cfg\":{\"polyEnc\":\"GPA\",\"rtMode\":\"HYBRID\"},\"meth\":\"BestPriceSearch\",\"req\":{\"outDate\":\"20230525\",\"outTime\":\"183000\",\"arrLocL\":[{\"crd\":{\"x\":6959197,\"y\":50942823},\"extId\":\"8000207\",\"lid\":\"A=1@O=K\xc3\xb6ln Hbf@X=6958730@Y=50943029@U=80@L=8000207@B=1@p=1678909069@\",\"name\":\"K\xc3\xb6ln Hbf\",\"type\":\"S\"}],\"depLocL\":[{\"crd\":{\"x\":8663003,\"y\":50106817},\"extId\":\"8000105\",\"lid\":\"A=1@O=Frankfurt(Main)Hbf@X=8663785@Y=50107149@U=80@L=8000105@B=1@p=1678909069@\",\"name\":\"Frankfurt(Main)Hbf\",\"type\":\"S\"}],\"getPasslist\":true,\"getPolyline\":true,\"jnyFltrL\":[{\"mode\":\"BIT\",\"type\":\"PROD\",\"value\":\"11111111111111\"}],\"trfReq\":{\"cType\":\"PK\",\"jnyCl\":2,\"tvlrProf\":[{\"type\":\"E\"}]}}}],\"ver\":\"1.15\"}' \
    $'https://reiseauskunft.bahn.de/bin/mgate.exe?checksum=b7fbc668cec93b4a6d3a24a12d9339cc'

The output is quite large, I will try to prepare a suitable snippet if I have more time.

@TheRealMurmel
Copy link

App

DB_Bahn_BestPrices.png

Response

My first guess, the svcResL[0].res.outConL array contains every connection. Every element of this list is identified by the cid key which is structured as AX-z for X € {0,5}, so X most likely correspondents to the 6 time spans from the screenshot. FOr readability reasons, the following excerpt only contains the first array element. The price can be found at svcResL[0].res.outConL[0].trfRes.fareSetL[0].fareL[0].prc for this element.

{
  "ver": "1.15",
  "ext": "DB.R22.04.a",
  "lang": "eng",
  "id": "namwkn2u2wcwggwg",
  "cInfo": ...,
  "svcResL": [
    {
      "meth": "BestPriceSearch",
      "err": "OK",
      "res": {
        "common": ...,
        "outConL": [
          {
            "cid": "A0-0",
            "date": "20230525",
            "dur": "023500",
            "chg": 0,
            "dep": ...,
            "arr": ...,
            "secL": ...,
            "ctxRecon": "T$A=1@O=Frankfurt(Main)Hbf@L=8000105@a=0@$A=1@O=Köln Hbf@L=8000207@a=0@$202305250322$202305250557$IC 60402$$1$$$$$$",
            "trfRes": {
              "statusCode": "OK",
              "fareSetL": [
                {
                  "fareL": [
                    {
                      "prc": 1790,
                      "isFromPrice": true,
                      "isPartPrice": false,
                      "isBookable": true,
                      "isUpsell": false,
                      "targetCtx": "D",
                      "buttonText": "To offer selection",
                      "retPriceIsCompletePrice": false,
                      "retPrice": -1,
                      "fahrrad": false
                    }
                  ]
                }
              ]
            },
            "conSubscr": "U",
            "resState": "N",
            "resRecommendation": "N",
            "recState": "U",
            "sotRating": 0,
            "isSotCon": false,
            "showARSLink": false,
            "cksum": "cf66b09d_3",
            "dTrnCmpSX": ...
          },
          ...A0-X - A5-Y...
        ],
        "fpB": "20221211",
        "fpE": "20231209",
        "bfATS": -1,
        "bfIOSTS": -1,
        "planrtTS": "1683557525",
        "outDaySegL": ...,
        "outTbpState": 0
      }
    }
  ]
}

@derhuerst
Copy link
Collaborator

My first guess, the svcResL[0].res.outConL array contains every connection.

Correct.

Every element of this list is identified by the cid key which is structured as AX-z for X € {0,5}, so X most likely correspondents to the 6 time spans from the screenshot.

While the cid could be used to deduce the grouping/bracketing of connections into time spans, there is explicit data expressing it in the response: For each group/bracket, the respective item in res.outDaySegL[] contains the indices of the connections.

// outDaySegL
[
	{
		"conRefL": [
			4,
			1,
			2,
			3,
			0
		],
		"id": "0",
		"fromDate": "20230509",
		"fromTime": "000000",
		"toDate": "20230509",
		"toTime": "070000",
		"bestPrice": {
			"amount": 9590
		},
		"segmentHeightIndicator": 76,
		"isCompletePrice": false,
		"tbpState": 0
	},
	// …
]

@thigg
Copy link

thigg commented Jun 22, 2023

What is the way forward here? can we help somehow? What can we do to get a working client again?

@derhuerst
Copy link
Collaborator

Given that it seems like the old standalone "Bestpreissuche" API doesn't exist/work anymore, I think it would be best to at least implement the current functionality of the DB Navigator (finding the best prices for one day). This should be done in hafas-client, and is being tracked in public-transport/hafas-client#291 .

Once the new intra-day "Bestpreissuche" API is implemented in hafas-client, we can make db-prices use it and try to transform the data into a as-backwards-compatible-as-possible data format, so that db-prices works again as it used to, more or less.

@zaunerp
Copy link

zaunerp commented Feb 2, 2024

Are there any updates on this?

@thigg
Copy link

thigg commented Mar 20, 2024

I used the bestPrice api in the hafas-client branch with success in https://github.com/thigg/fahrpreis-plotter. Seems to work without problems.

@zaunerp
Copy link

zaunerp commented Mar 20, 2024

@thigg I did not find a bestPrices Funciton in https://github.com/public-transport/hafas-client. I also checked every available branch and not one createClient-Function does have a bestPrices Function. Can you help me with that?

@thigg
Copy link

thigg commented Mar 20, 2024 via email

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

Successfully merging a pull request may close this issue.

7 participants