-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
68 lines (57 loc) · 2.18 KB
/
__init__.py
File metadata and controls
68 lines (57 loc) · 2.18 KB
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
#!flask/bin/python
from flask import Flask, jsonify, abort, request, make_response, url_for
from flask_httpauth import HTTPBasicAuth
from dota2test_function import *
app = Flask(__name__, static_url_path = "")
auth = HTTPBasicAuth()
# @auth.get_password
# def get_password(username):
# if username == 'dota2':
# return 'test'
# return None
# @auth.error_handler
# def unauthorized():
# return make_response(jsonify( { 'error': 'Unauthorized access' } ), 403)
# # return 403 instead of 401 to prevent browsers from displaying the default auth dialog
@app.errorhandler(400)
def not_found(error):
return make_response(jsonify( { 'error': 'Bad request' } ), 400)
@app.errorhandler(404)
def not_found(error):
return make_response(jsonify( { 'error': 'Not found' } ), 404)
@app.errorhandler(405)
def not_found(error):
return make_response(jsonify( { 'error': 'Method Not Allowed' } ), 405)
@app.errorhandler(500)
def not_found(error):
return make_response(jsonify( { 'error': 'Internal Server Error' } ), 500)
@app.route('/dota2test/api/v0.1/rangking', methods=['POST'])
# @auth.login_required
def get_rangking():
if not request.json or not 'users' in request.json:
abort(400)
users = request.json['users']
return_data = get_return_wl_data(users)
final_data = get_final_rangking(return_data)
return jsonify({'result': final_data})
@app.route('/dota2test/api/v0.1/comparison', methods=['POST'])
# @auth.login_required
def get_comparison():
if not request.json or not 'users' in request.json or len(request.json['users']) != 2:
abort(400)
users = request.json['users']
return_data = get_return_total_data(users)
final_data = get_final_comparison(return_data)
return jsonify({'result': final_data})
@app.route('/dota2test/api/v0.1/heroforuser/<string:user_id>', methods = ['GET'])
# @auth.login_required
def get_hero_for_user(user_id):
return_data = get_heroes(user_id)
if return_data == False:
abort(404)
final_data = get_best_hero(return_data)
if final_data == False:
abort(404)
return jsonify({'result': final_data})
if __name__ == '__main__':
app.run(host='0.0.0.0',port=5001,debug = True)