Remove debug harness

This commit is contained in:
Marty Oehme 2025-08-11 23:25:15 +02:00
parent f14e28eeab
commit b8947e4679
Signed by: Marty
GPG key ID: 4E535BC19C61886E
2 changed files with 36 additions and 7907 deletions

File diff suppressed because it is too large Load diff

82
main.py
View file

@ -18,18 +18,15 @@ def dprint(txt) -> None:
def request_init_token(endpoint: str = "/nj-booking-ocp/init/start") -> str: def request_init_token(endpoint: str = "/nj-booking-ocp/init/start") -> str:
DEBUG_TOKEN = "eyJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3NTU1NDMyMjMsInB1YmxpY0lkIjoiYmU2N2ZlNDNjY2Y3NDI3Yjk0MjY3NmI0MjJmZmIzOWYifQ.Hvo7Ljm9iFof_w7RrQkVVACOX8wgY2qAzTKAYDm5QC4" headers = {
token = DEBUG_TOKEN "Referer": "https://www.nightjet.com",
"Content-Type": "application/json",
# headers = { }
# "Referer": "https://www.nightjet.com", body = {"lang": "en"}
# "Content-Type": "application/json" resp_json = requests.post(
# } f"{BASE_URL}{endpoint}", data=json.dumps(body), headers=headers
# body = { ).json()
# "lang": "en" token = resp_json["token"]
# }
# resp_json = requests.post(f"{BASE_URL}{endpoint}", data=json.dumps(body), headers=headers).json()
# token = resp_json["token"]
dprint(f"Received init token: {token}") dprint(f"Received init token: {token}")
return token return token
@ -43,24 +40,19 @@ TRAVEL_DATE = "2025-10-14"
def request_connections( def request_connections(
token: str, endpoint: str = "/nj-booking-ocp/connection" token: str, endpoint: str = "/nj-booking-ocp/connection"
) -> list[Any]: ) -> list[Any]:
DEBUG_CONNECTIONS = json.loads( uri = f"{BASE_URL}{endpoint}/{START_STATION}/{END_STATION}/{TRAVEL_DATE}"
'{ "connections": [ { "from": { "name": "Berlin Hbf", "number": "8011160" }, "to": { "name": "Paris Est", "number": "8700011" }, "trains": [ { "train": "NJ 40424", "departure": { "utc": 1760461680000, "local": "2025-10-14T19:08:00" }, "arrival": { "utc": 1760513880000, "local": "2025-10-15T09:38:00" }, "trainType": "regular", "seatAsIC": false } ] }, { "from": { "name": "Berlin Hbf", "number": "8011160" }, "to": { "name": "Paris Est", "number": "8700011" }, "trains": [ { "train": "NJ 40424", "departure": { "utc": 1760634480000, "local": "2025-10-16T19:08:00" }, "arrival": { "utc": 1760686680000, "local": "2025-10-17T09:38:00" }, "trainType": "regular", "seatAsIC": false } ] }, { "from": { "name": "Berlin Hbf", "number": "8011160" }, "to": { "name": "Paris Est", "number": "8700011" }, "trains": [ { "train": "NJ 40424", "departure": { "utc": 1760893680000, "local": "2025-10-19T19:08:00" }, "arrival": { "utc": 1760945880000, "local": "2025-10-20T09:38:00" }, "trainType": "regular", "seatAsIC": false } ] } ] }' headers = {
) "Accept": "application/json",
resp_json = DEBUG_CONNECTIONS "Accept-Language": "en-US,en;q=0.5",
"Referer": "https://www.nightjet.com/en/ticket-buchen/",
"x-token": token,
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:139.0) Gecko/20100101 Firefox/139.0",
}
# uri = f"{BASE_URL}{endpoint}/{START_STATION}/{END_STATION}/{TRAVEL_DATE}" resp_json = requests.get(
# headers = { uri,
# "Accept": "application/json", headers=headers,
# "Accept-Language": "en-US,en;q=0.5", ).json()
# "Referer": "https://www.nightjet.com/en/ticket-buchen/",
# "x-token": token,
# "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:139.0) Gecko/20100101 Firefox/139.0",
# }
#
# resp_json = requests.get(
# uri,
# headers=headers,
# ).json()
return resp_json["connections"] return resp_json["connections"]
@ -98,23 +90,21 @@ def connection_data_to_booking_requests(connections) -> list[dict[str, Any]]:
def request_bookings( def request_bookings(
token: str, booking_req: dict[str, Any], endpoint: str = "/nj-booking-ocp/offer/get" token: str, booking_req: dict[str, Any], endpoint: str = "/nj-booking-ocp/offer/get"
) -> dict[Any, Any]: ) -> dict[Any, Any]:
with open("bookings.json") as f: headers = {
DEBUG_BOOKINGS = json.load(f)[0] "Accept": "application/json",
resp_json = DEBUG_BOOKINGS "Accept-Language": "en-US,en;q=0.5",
"Content-Type": "application/json",
# headers = { "Referer": "https://www.nightjet.com/en/ticket-buchen/",
# "Accept": "application/json", "Origin": "https://www.nightjet.com",
# "Accept-Language": "en-US,en;q=0.5", "x-token": token,
# "Content-Type": "application/json", "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:139.0) Gecko/20100101 Firefox/139.0",
# "Referer": "https://www.nightjet.com/en/ticket-buchen/", }
# "Origin": "https://www.nightjet.com", resp_json = requests.post(
# "x-token": token, f"{BASE_URL}{endpoint}", headers=headers, data=json.dumps(booking_req)
# "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:139.0) Gecko/20100101 Firefox/139.0", ).json()
# } dprint(
# resp_json = requests.post( f"Requested prices ({booking_req['njFrom']} -> {booking_req['njTo']} at {booking_req['njDep']})."
# f"{BASE_URL}{endpoint}", headers=headers, data=json.dumps(booking_req) )
# ).json()
# dprint(f"Requested prices ({booking_req["njFrom"]} -> {booking_req["njTo"]} at {booking_req["njDep"]}).")
return resp_json return resp_json