aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rwxr-xr-xautoplanner.py5
-rw-r--r--shared.py6
-rwxr-xr-xstoringen.py4
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)):