diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-02-05 18:09:36 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-02-05 18:09:36 +0100 |
commit | 945385ddfbdfe791f2f02f3fe3d0b0a3f81d4bb8 (patch) | |
tree | db060bc73e4dadbd0e222ea3664ea2f1b47d979f | |
parent | 5e660cce38c02d29c7d5cb850bb8ec9633e7a0f8 (diff) |
ns website update patch
-rw-r--r-- | .gitignore | 1 | ||||
-rwxr-xr-x | autoplanner.py | 5 | ||||
-rw-r--r-- | shared.py | 6 | ||||
-rwxr-xr-x | storingen.py | 4 |
4 files changed, 12 insertions, 4 deletions
@@ -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): @@ -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)): |