from flask import Flask, request from flask_cors import CORS from pathlib import Path import json import os app = Flask(__name__) CORS(app) DIRECTORY = os.path.dirname(os.path.realpath(__file__)) @app.route("/get-path", methods=["GET"]) def get_path(): with open(Path(DIRECTORY, "path.json"), "r") as pathFile: path = pathFile.read() return path @app.route("/set-path", methods=["POST"]) def set_path(): path = request.json.get("path") filePath = Path(DIRECTORY, "path.json") with open(filePath, "r") as pathFile: pathDict = json.load(pathFile) pathDict[path.get("name")] = path.get("coords") with open(filePath, "w") as pathFile: json.dump(pathDict, pathFile, indent=2) return "ok", 200 @app.route("/set-time", methods=["POST"]) def set_time(): data = request.json filePath = Path(DIRECTORY, "time.json") with open(filePath, "r") as timeFile: timeList = json.load(timeFile) timeList.append(data) with open(filePath, "w") as timeFile: json.dump(timeList, timeFile, indent=2) return "ok", 200 if __name__=="__main__": app.run(host='0.0.0.0')