-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
55 lines (35 loc) · 1016 Bytes
/
server.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
from flask import Flask, request
import json
from database import OprateSql as ops
ops.createTable()
ops.creatJson()
app = Flask(__name__)
@app.route('/ranking')
def ranking():
rank_json = ops.showRank()
return rank_json
@app.route('/total')
def total():
total_score = ops.showTotal()
return total_score
@app.route('/entry_player', methods=["POST"])
def entry_player():
ops.createTable()
result_json = request.get_data()
result_dict = json.loads(result_json)
player_name = result_dict['name']
pref = result_dict['pref']
player_id = ops.addUser(player_name, pref)
return str(player_id)
@app.route('/result', methods=["POST"])
def result():
ops.creatJson()
result_json = request.get_data()
result_dict = json.loads(result_json)
player_id = result_dict['id']
score = result_dict['score']
ops.addResult(player_id, score)
return 'OK'
if __name__ == '__main__':
# app.run(debug=True, host='127.0.0.2')
app.run(debug=True)