databaseInterface.py 648 B

12345678910111213141516171819202122232425262728
  1. from flask import Flask, request
  2. from flask_cors import CORS
  3. import json
  4. app = Flask(__name__)
  5. CORS(app)
  6. @app.route("/get-path", methods=["GET"])
  7. def get_path():
  8. with open("path.json", "r") as pathFile:
  9. path = pathFile.read()
  10. return path
  11. @app.route("/set-path", methods=["POST"])
  12. def set_path():
  13. path = request.json.get("path")
  14. with open("path.json", "r") as pathFile:
  15. pathDict = json.load(pathFile)
  16. pathDict[path.get("name")] = path.get("coords")
  17. with open("path.json", "w") as pathFile:
  18. json.dump(pathDict, pathFile)
  19. return "ok", 200
  20. if __name__=="__main__":
  21. app.run(host='0.0.0.0')