-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
72 lines (57 loc) · 1.96 KB
/
app.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
# -- coding: utf-8 --
from flask import Flask, render_template, request, redirect, make_response
import json
app = Flask(__name__)
inputData = dict()
personData = dict()
resultData = dict()
answer = [
('male', 20),
('female', 19),
('male', 19),
('male', 19),
('male', 19),
]
@app.route('/')
def index():
return render_template('index.html')
@app.route('/game', methods=['GET'])
def game():
nickname = request.args.get('nickname')
gender = request.args.get('gender')
if not nickname in personData.keys():
inputData[nickname] = []
personData[nickname] = 0
resultData[nickname] = 0
if not gender == None:
age = int(request.args.get('age'))
sequence = personData[nickname]
genderResult = (gender == answer[sequence][0])
ageResult = (age == answer[sequence][1] - 1) or (age == answer[sequence][1]) or (age == answer[sequence][1] + 1)
if genderResult and ageResult:
inputData[nickname].append('O')
resultData[nickname] += 1
else:
inputData[nickname].append('X')
personData[nickname] += 1
if personData[nickname] > 5:
return redirect('/result/' + nickname)
return redirect('/game?nickname=' + nickname)
src = "img/face" + str(personData[nickname] + 1) + ".jpeg"
return render_template('game.html', image_file=src)
@app.route('/result/<nickname>')
def result(nickname):
return render_template('result.html', cnt=resultData[nickname])
@app.route('/result')
def resultAll():
json_data = json.dumps(resultData, ensure_ascii=False)
response = make_response(json_data)
response.headers['Content-Type'] = 'application/json'
return response
@app.route('/result_detail')
def result_detail():
json_data = json.dumps(inputData, ensure_ascii=False)
response = make_response(json_data)
response.headers['Content-Type'] = 'application/json'
return response
app.run("0.0.0.0", 80)