Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sanic import Sanic
- from sanic import response
- import json
- settingsfile: str = "flightguy-settings.json"
- app = Sanic("flightguy-server")
- @app.route('/getsettings')
- async def getSettings(request):
- try:
- with open(settingsfile, "r") as f:
- return response.json(json.loads(f.read()))
- except:
- return response.json({"error": "Could not load settings"}, status=401)
- @app.route("/setsettings", methods=["POST"])
- async def setSettings(request):
- try:
- with open(settingsfile, "w") as f:
- f.write(json.dumps(request.json))
- return response.json({"success": "Settings saved"})
- except:
- return response.json({"error": "Could not save settings"}, status=500)
- app.run(host="0.0.0.0", port=1903)
Advertisement
Add Comment
Please, Sign In to add comment