35 lines
804 B
Python
35 lines
804 B
Python
import json
|
|
|
|
from flask import Flask, jsonify, request, render_template
|
|
|
|
app = Flask(__name__)
|
|
with open("data.json") as f:
|
|
data = json.load(f)
|
|
|
|
@app.route("/all/")
|
|
def get_all():
|
|
return jsonify(data)
|
|
|
|
|
|
@app.route("/data/<data_id>", methods=["POST"])
|
|
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})
|
|
|
|
@app.route("/data/<key>")
|
|
def get_data_point(key):
|
|
if key not in data:
|
|
return jsonify({"success": False}), 404
|
|
return jsonify({"success": True, "value": data[key]})
|
|
|
|
@app.route("/admin/")
|
|
def admin():
|
|
return render_template("admin.html", data=data)
|