OlMi1

Flightguy Server

Aug 13th, 2022
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. from sanic import Sanic
  2. from sanic import response
  3. import json
  4.  
  5. settingsfile: str = "flightguy-settings.json"
  6.  
  7. app = Sanic("flightguy-server")
  8.  
  9. @app.route('/getsettings')
  10. async def getSettings(request):
  11. try:
  12. with open(settingsfile, "r") as f:
  13. return response.json(json.loads(f.read()))
  14. except:
  15. return response.json({"error": "Could not load settings"}, status=401)
  16.  
  17. @app.route("/setsettings", methods=["POST"])
  18. async def setSettings(request):
  19. try:
  20. with open(settingsfile, "w") as f:
  21. f.write(json.dumps(request.json))
  22. return response.json({"success": "Settings saved"})
  23. except:
  24. return response.json({"error": "Could not save settings"}, status=500)
  25.  
  26. app.run(host="0.0.0.0", port=1903)
Advertisement
Add Comment
Please, Sign In to add comment