-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathrunserver.py
45 lines (33 loc) · 1.08 KB
/
runserver.py
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
37
38
39
40
41
42
43
44
45
import json
from flask import Flask, request, render_template, jsonify
from src.jsonselector import codify_json
from src.flaskhelpers import extract_post_data
app = Flask(__name__)
@app.route('/', methods=['GET'])
def home():
return render_template("home.html")
@app.route('/privacy', methods=['GET'])
def privacy():
return render_template("privacy.html")
@app.route('/process', methods=['POST'])
def process():
required_fields = ('rawjson',)
post,errors = extract_post_data(request, required_fields)
if errors:
return jsonify(errors=errors)
try:
data = json.loads(post['rawjson'])
except ValueError:
return "Invalid JSON"
try:
codified_json = codify_json(json.dumps(data))
except ValueError, e:
print(str(e))
return "Error"
return render_template("codify_json.html", codified_json=codified_json)
@app.route('/sampledata', methods=['GET'])
def sample_data():
rawjson=render_template("examplejson.json")
return jsonify(rawjson=rawjson)
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)