commit 89a5e754117a593e4d66db5a958a1a41cf8edd36
parent 1e163c3cf60a035f0243a8e75ef326ea490dd3f9
Author: Friedel Schön <[email protected]>
Date: Fri, 17 Jun 2022 02:34:12 +0200
adding test rest-server
Diffstat:
1 file changed, 36 insertions(+), 0 deletions(-)
diff --git a/test-server.py b/test-server.py
@@ -0,0 +1,36 @@
+from typing import cast
+from flask import Flask, request, jsonify
+
+app = Flask(__name__)
+
+latitude = 0
+longitude = 0
+accuracy = 0
+battery = 0
+temperature = 0
+
+
[email protected]("/api/update", methods=['POST'])
+def update():
+ global latitude, longitude, accuracy, battery, temperature
+
+ if request.is_json:
+ req = cast(dict, request.get_json())
+ latitude = req['latitude']
+ longitude = req['longitude']
+ accuracy = req['accuracy']
+ battery = req['battery']
+ temperature = req['temperature']
+ return {}
+
+ return {"error": "request must be json"}, 415
+
[email protected]("/")
+def index():
+ return f'''
+ <p>latitude: {latitude}</p>
+ <p>longitude: {longitude}</p>
+ <p>accuracy: {accuracy}</p>
+ <p>battery: {battery}</p>
+ <p>temperature: {temperature}</p>
+ '''