2020-12-19 14:19:11 +01:00
|
|
|
import json
|
|
|
|
|
2020-12-19 14:54:35 +01:00
|
|
|
from flask import Flask, jsonify, request, render_template
|
2020-12-19 14:19:11 +01:00
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
with open("data.json") as f:
|
|
|
|
data = json.load(f)
|
|
|
|
|
2020-12-19 14:54:35 +01:00
|
|
|
@app.route("/all/")
|
2020-12-19 14:19:11 +01:00
|
|
|
def get_all():
|
|
|
|
return jsonify(data)
|
|
|
|
|
|
|
|
|
2020-12-19 14:54:35 +01:00
|
|
|
@app.route("/data/<data_id>", methods=["POST"])
|
2020-12-19 14:19:11 +01:00
|
|
|
def set_data_point(data_id):
|
|
|
|
try:
|
|
|
|
value = request.json["value"]
|
|
|
|
except KeyError:
|
|
|
|
return jsonify({"success": False}), 400
|
|
|
|
|
|
|
|
data[data_id] = value
|
|
|
|
with open("data.json", "w") as f:
|
|
|
|
json.dump(data, f)
|
|
|
|
return jsonify({"success": True})
|
2020-12-19 14:54:35 +01:00
|
|
|
|
|
|
|
@app.route("/admin/")
|
|
|
|
def admin():
|
|
|
|
return render_template("admin.html", data=data)
|