-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.py
70 lines (56 loc) · 1.7 KB
/
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from flask import Flask, current_app, render_template
import os
from nba import NBA, Player
from grapher import Grapher
# setting where to look at html template
templateDirectory = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'template')
app = Flask(
__name__,
template_folder = templateDirectory
)
@app.route('/')
def main():
return render_template('index.html')
@app.route('/team/<teamID>')
def team(teamID):
nba = NBA(teamID=teamID)
# team = nba.getTeam()
roster = nba.getRoster()
for player in roster:
if player[11] == None:
player[11] = 'None'
# return current_app.send_static_file('index.html', result=result)
return render_template('team.html', roster=roster, team=nba.team, teamName=nba.getTeam())
# where the actual shot chart will be
@app.route('/player/<playerID>')
def player(playerID):
player = Player(playerID)
shotChart = player.getShotData()
headers = shotChart['resultSets'][0]['headers']
shots = shotChart['resultSets'][0]['rowSet']
# print(shots)
# print('---')
grapher = Grapher(shots)
x,y,shotStatus = grapher.getShotCoordinates()
# split shot coordinates into made and miss
madeX = []
madeY = []
missedX = []
missedY = []
for i in range(len(x)):
if shotStatus[i] == 'Made Shot':
madeX.append(x[i])
madeY.append(y[i])
else:
missedX.append(x[i])
missedY.append(y[i])
file = grapher.makeGraph(x,y, madeX, madeY, missedX, missedY)
return render_template('player.html', playerID=playerID, shotChart=file)
@app.after_request
def addHeader(response):
response.headers['Cache-Control'] = 'public, max-age=0'
return response
if __name__ == "__main__":
port = int(os.environ.get("PORT", 33507))
app.run(host='0.0.0.0', port=port)
# app.run()