-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
36 lines (29 loc) · 936 Bytes
/
app.py
File metadata and controls
36 lines (29 loc) · 936 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
32
33
34
35
36
from flask import Flask,render_template, jsonify,request
app = Flask(__name__)
@app.route('/')
def hello_world():
return render_template('test.html')
@app.route('/jsonRequest', methods=['POST'])
def requestJson():
data=request.json;
try:
fp=open(data['path'],'r')
data=fp.read()
fp.close()
if(len(data)==0):
return jsonify({"success":False,"msg":"Json file length is zero!" })
return jsonify({"success":True,"data":data})
except:
return jsonify({"success":False,"msg":"Failed to open json file!"})
@app.route('/jsonCover', methods=['POST'])
def coverJsonFile():
data=request.json;
try:
fp=open(data['path'],'w')
fp.write(data['data'])
fp.close()
return jsonify({"msg":"Success to compact json file!"})
except:
return jsonify({"msg":"Fail to open json file!"})
if __name__ == '__main__':
app.run()