aboutsummaryrefslogtreecommitdiff
path: root/trein.py
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-11-22 11:29:50 +0100
committerlonkaars <loek@pipeframe.xyz>2022-11-22 11:29:50 +0100
commit0ffe2d19a953a0f935dce80dee91ee8faac3dabe (patch)
treebe8215ba17e534babc20c88115b79c3a9a0f638e /trein.py
initial commit
Diffstat (limited to 'trein.py')
-rwxr-xr-xtrein.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/trein.py b/trein.py
new file mode 100755
index 0000000..2f09938
--- /dev/null
+++ b/trein.py
@@ -0,0 +1,28 @@
+#!/bin/python3
+import http.client, urllib.request, urllib.parse, urllib.error, base64
+
+def read_file(filename):
+ f = open(filename)
+ r = str(f.read())
+ f.close()
+ return r
+
+def fake_disruptions():
+ return read_file("./api_response.json")
+
+def real_disruptions():
+ key = read_file("./key").strip()
+ headers = { 'Ocp-Apim-Subscription-Key': key }
+ params = urllib.parse.urlencode({ 'isActive': 'true' })
+ conn = http.client.HTTPSConnection('gateway.apiportal.ns.nl')
+ conn.request("GET", f"/reisinformatie-api/api/v3/disruptions?{params}", "{body}", headers)
+ response = conn.getresponse()
+ data = response.read()
+ conn.close()
+ return data
+
+def get_disruptions():
+ return fake_disruptions()
+
+if __name__ == "__main__":
+ print(get_disruptions())