-
Notifications
You must be signed in to change notification settings - Fork 6
/
cyatp.py
137 lines (116 loc) · 4.09 KB
/
cyatp.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
from flask import Flask, request, jsonify, url_for, render_template
from neo_db.query_graph import query
from scripts.show_profile import get_keyword_profile
from scripts.get_5_data import get_all_question
from scripts.get_cross import get_crossword
from scripts.save_feedback import save, save_survey
import json
app = Flask(__name__)
# homepage
@app.route('/', methods=['GET', 'POST'])
@app.route('/index', methods=['GET', 'POST'])
def index():
return render_template('index.html')
@app.errorhandler(404)
def page_not_found(e):
return render_template('404_page.html'), 404
# concept map page
@app.route('/map', methods=['GET', 'POST'])
def map():
return render_template('map.html')
# learn page
@app.route('/learn', methods=['GET', 'POST'])
def learn():
return render_template('learn.html')
# search keyword information for learn page
@app.route('/search_name', methods=['GET', 'POST'])
def search_name():
name = request.args.get('name')
json_data = query(str(name))
# print(json_data)
return jsonify(json_data)
# get keyword's text for learn page
@app.route('/get_profile', methods=['GET', 'POST'])
def get_profile():
name = request.args.get('name')
json_data = get_keyword_profile(name)
#print(json_data)
#print(jsonify(json_data))
return jsonify(json_data)
# quiz page
@app.route('/game/quiz', methods=['GET', 'POST'])
def quiz():
return render_template('quiz.html')
# get questions for quiz page
@app.route('/get_question', methods=['GET', 'POST'])
def get_question():
with app.app_context():
All_question = get_all_question()
return jsonify(All_question)
# quiz feedback
@app.route('/game/feedback', methods=['GET', 'POST'])
def game_feedback():
temp_value = request.form.to_dict()
final = []
result = []
for key in temp_value:
if(key=='record'):
temp_num = temp_value[key].split(',')
for i in range(len(temp_num)):
result.append(temp_num[i])
else:
temp_dic = {}
temp_text = temp_value[key]
temp_split = temp_text.split(',answer,')
temp_dic.update({'Question': temp_split[0]})
temp_dic.update({'Answer': temp_split[1]})
final.append(temp_dic)
for index, q_dic in enumerate(final):
q_dic.update({'Record': result[index]})
return render_template('quiz_feedback.html', data = final)
# crossword puzzle page
@app.route('/game/puzzle', methods=['GET', 'POST'])
def puzzle():
return render_template('puzzle.html')
# get puzzle for crossword puzzle page
@app.route('/get_cross', methods=['GET', 'POST'])
def get_cross():
puzzleData = get_crossword()
return jsonify(puzzleData)
# survey page
survey_data = []
@app.route('/survey', methods=['GET', 'POST'])
def survey():
if request.method == 'GET':
return render_template('survey.html')
if request.method == 'POST':
survey_feedback = json.loads(request.get_data())
# print(survey_feedback)
# add feedback to survey_data, and save it
survey_data.append(survey_feedback)
save_survey(survey_data)
return render_template('survey.html')
data_list = []
@app.route('/back', methods=['GET', 'POST'])
def back():
if request.method == 'POST':
# get feedback user information
info_ip = request.remote_addr
info_platform = request.user_agent.platform
info_brower = request.user_agent.browser
info_bv = request.user_agent.version
info_all = info_ip + ' ' + info_platform + ' ' + info_brower + ' ' + info_bv
data = json.loads(request.get_data())
data.update({'info': info_all})
data_list.append(data)
statues_data = save(data_list)
return render_template('back.html', data_ = data_list)
if request.method == 'GET':
return render_template('back.html', data_=data_list)
if __name__ == '__main__':
app.config['JSON_AS_ASCII'] = False
app.config['JSON_SORT_KEYS'] = False
app.config['JSONIFY_MIMETYPE'] = "application/json;charset=utf-8"
# app.debug = True
app.debug = False
app.run(host='0.0.0.0')