-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
31 lines (24 loc) · 752 Bytes
/
server.py
File metadata and controls
31 lines (24 loc) · 752 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from flask import Flask, request, jsonify, render_template
import json
app = Flask(__name__)
DATA_FILE = "data.json"
app.config['JSON_SORT_KEYS'] = False
@app.route('/')
def home():
return render_template('index.html')
def load_data():
with open(DATA_FILE, "r", encoding="utf-8") as f:
return json.load(f)
def save_data(data):
with open(DATA_FILE, "w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=4)
@app.route("/get_data", methods=["GET"])
def get_data():
return jsonify(load_data())
@app.route("/update_data", methods=["POST"])
def update_data():
save_data(request.json)
return jsonify({"status": "success"})
if __name__ == "__main__":
# app.run()
app.run(debug=True)