From 945385ddfbdfe791f2f02f3fe3d0b0a3f81d4bb8 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sun, 5 Feb 2023 18:09:36 +0100 Subject: ns website update patch --- .gitignore | 1 + autoplanner.py | 5 ++++- shared.py | 6 +++--- storingen.py | 4 ++++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 221273b..0a17bdf 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ storingen.key autoplanner.json venv/ __pycache__/ +*-api-response.json diff --git a/autoplanner.py b/autoplanner.py index 438ab7e..fe3e728 100755 --- a/autoplanner.py +++ b/autoplanner.py @@ -48,10 +48,13 @@ def get_trip(date): param_dict.update(CFG) params = urllib.parse.urlencode(param_dict) conn = http.client.HTTPSConnection('gateway.apiportal.ns.nl') - conn.request("GET", f"/rio-mlab-proxy-api/reisinfo/api/v3/trips?{params}", "", headers) + conn.request("GET", f"/reisinformatie-api/api/v3/trips?{params}", "", headers) response = conn.getresponse() data = response.read() conn.close() + f = open("./autoplanner-api-response.json", "w+") + f.write(str(data, "utf-8")) + f.close() return data def leg2desc(leg): diff --git a/shared.py b/shared.py index 71a1330..72db189 100644 --- a/shared.py +++ b/shared.py @@ -5,10 +5,10 @@ from uuid import uuid4 from bs4 import BeautifulSoup def get_public_key(): - data = urllib.request.urlopen("https://www.ns.nl/reisplanner").read() + data = urllib.request.urlopen("https://www.ns.nl/reisplanner/").read() soup = BeautifulSoup(data, features="lxml") - data = "\n".join(str(x) for x in soup.select('script:-soup-contains("mlabProductKey")')) - return re.search(r'mlabProductKey: "([0-9a-f]{32})"', data).group(1) + data = "\n".join(str(x) for x in soup.select('script:-soup-contains("nsAppProductKey")')) + return re.search(r'nsAppProductKey: "([0-9a-f]{32})"', data).group(1) def read_file(filename): f = open(filename, "r") diff --git a/storingen.py b/storingen.py index f11a1c8..5eb9af7 100755 --- a/storingen.py +++ b/storingen.py @@ -19,6 +19,9 @@ def get_disruptions(): response = conn.getresponse() data = response.read() conn.close() + f = open("./storingen-api-response.json", "w+") + f.write(str(data, "utf-8")) + f.close() return data def disruption2ical(disruption): @@ -43,6 +46,7 @@ def main(): for disruption in disruptions: relevant = False + if 'publicationSections' not in disruption: continue for section in disruption['publicationSections']: consequence_stations = list(map(lambda x: x['name'], section['consequence']['section']['stations'])) for i in range(len(relevant_stations)): -- cgit v1.2.3