From 0ffe2d19a953a0f935dce80dee91ee8faac3dabe Mon Sep 17 00:00:00 2001 From: lonkaars Date: Tue, 22 Nov 2022 11:29:50 +0100 Subject: initial commit --- trein.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 trein.py (limited to 'trein.py') 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()) -- cgit v1.2.3