-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
133 lines (124 loc) · 4.24 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
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
import glob
from os import stat
from re import match, template
from subprocess import Popen
from threading import Timer
from time import time
from typing import Match
from flask import Flask, jsonify, request, render_template
from flask_cors import CORS, core, cross_origin
from flask_socketio import SocketIO, emit
from numpy import mat, short
from markupsafe import escape
import websocket
import requests
import time
import constants
import socketio
app = Flask(__name__)
app.secret_key = '&(*(**((*@@@#$333(*(*221'
socket_io = SocketIO(app, cors_allowed_origins="*")
app.config.update(SESSION_COOKIE_SAMESITE="None", SESSION_COOKIE_SECURE=True)
socket_io.emit('kill_self', {'data': 'Sleep'})
cors = CORS(app)
global match_details
match_details = constants.MATCH_DETAILS_TEMPLATE
global match_row_details
match_row_details = constants.ROW_MATCH_DETAILS_TEMPLATE
global team_details
team_details = [
{
'short_name':'TT1',
'full_name':'TestTeam1',
'logo':'default.png'
},
{
'short_name':'TT2',
'full_name':'TestTeam2',
'logo':'default.png'
}
]
global state
state = 'MENU'
@app.route('/api/v1/get_team_details', methods=['GET'])
@cross_origin(allow_headers=['*'])
def get_team_details():
global team_details
return jsonify({"response": team_details})
@app.route('/api/v1/post_team_details', methods=['POST'])
@cross_origin(allow_headers=['*'])
def post_team_details():
global team_details
try:
team_details = request.get_json()
return jsonify({"response": "Success"}), 200
except Exception as exception:
print(exception)
return jsonify({"response": "Error"}), 500
@app.route('/api/v1/get_match_details', methods=['GET', 'POST'])
@cross_origin(allow_headers=['*'])
def get_match_details():
global match_details
# for testing:
# testing_details = constants.corematch_example
# return jsonify({"response": testing_details})
# print("returning",match_details)
return jsonify({"response": match_details})
@app.route('/get_row_match_details', methods=['GET', 'POST'])
@cross_origin(allow_headers=['*'])
def get_row_match_details():
global match_row_details
global state
# for testing:
# testing_details = constants.corematch_example
# return jsonify({"response": testing_details})
# print("returning",match_details)
return jsonify({"data": match_row_details, 'state':state})
@app.route('/api/v1/get-name/<puuid>', methods=['GET', 'POST'])
@cross_origin(allow_headers=['*'])
def getname(puuid):
try:
name = requests.get(f'https://api.henrikdev.xyz/valorant/v1/by-puuid/mmr/eu/{puuid}')
name = f'{name["data"]["name"]}#{name["data"]["tag"]}'
# for testing:
# testing_details = constants.corematch_example
# return jsonify({"response": testing_details})
# print("returning",match_details)
return jsonify({'GameName':name, 'name': name["data"]["name"], 'tag': name["data"]["tag"]})
except Exception as exception:
print(exception)
return jsonify({"response": "Error"}), 500
@socket_io.on('connect')
def test_connect():
global match_details
print("1 machine connected")
emit('after connect', {'data': 'Woke up'})
#updatestate = match_utils.statecheck(state)
#print(updatestate)
@socket_io.on('hallo')
def hallo():
print('hallo')
@socket_io.on('after connect')
@cross_origin(allow_headers=['*'])
def after_connect():
print("After machine- connected")
#global state
#state = updatestate
@socket_io.on('update_details')
def update_details(data):
print("Sending new match_details")
global match_details
match_details = data['match_details']
global state
state = data['game_state']
emit('receive_details', {'match_details': data['match_details'], 'live_details': data['live_details'], 'team_details': team_details}, broadcast=True, include_self=False)
@app.route('/edit_team_details')
@cross_origin(allow_headers=['*'])
def edit_team_details():
template = render_template('editteams.html')
return template
pass
if __name__ == "__main__":
# socketio.run(app, port=4445, host = socket.gethostbyname(socket.gethostname()),debug='true')
socket_io.run(app, host='0.0.0.0', debug='true')
# app.run(host='0.0.0.0', port=4445, debug='true')