From 66a97615626998bc474d020da7eb3f132165eb02 Mon Sep 17 00:00:00 2001 From: marko Date: Sat, 23 Dec 2023 14:54:48 +0100 Subject: [PATCH] develop version for new api concept --- homepage/participo/api/users.php | 40 ++++++++++++++++++++++++++++++++ homepage/participo/testApi.py | 33 ++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 homepage/participo/api/users.php create mode 100644 homepage/participo/testApi.py diff --git a/homepage/participo/api/users.php b/homepage/participo/api/users.php new file mode 100644 index 0000000..c81cb29 --- /dev/null +++ b/homepage/participo/api/users.php @@ -0,0 +1,40 @@ +isValidFor('api')) { + die(json_encode(['success' => false])); +} + +$wkSqlQuery = 'SELECT * FROM `wettkampfkalender` WHERE `Datum` >= CURDATE();'; +$wkSqlResponse = dbConnector::query($wkSqlQuery); + +header('Access-Control-Allow-Headers: *'); +header('Access-Control-Allow-Origin: *'); + +echo( + json_encode($wkSqlResponse) + // json_encode(getallheaders()) + // json_encode($_SERVER) +); diff --git a/homepage/participo/testApi.py b/homepage/participo/testApi.py new file mode 100644 index 0000000..1b37554 --- /dev/null +++ b/homepage/participo/testApi.py @@ -0,0 +1,33 @@ +from http import client +import logging +import json +import yaml + +host="cwsvjudo.bplaced.net" + +with open("testApi.config.yaml", "r") as f: + config = yaml.load(f) + +logging.basicConfig(level=logging.DEBUG) + +connection = client.HTTPConnection(host=host, port=80, timeout=1) +connection.request( + method="GET", + url="/participo/api/users", + headers={ + "Authorization": f"Basic {config['apiKey']}" + } +) +response = connection.getresponse() + +print("Status: {} and reason: {}".format(response.status, response.reason)) + +body = response.read() +try: + print(json.dumps(json.loads(body),indent=2)) +except: + print(f"failed to parse to json") + print(body + ) + +connection.close()