-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.py
executable file
·132 lines (109 loc) · 3.92 KB
/
application.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
import os
from flask import Flask, render_template, request, redirect, jsonify, url_for
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session
from werkzeug import secure_filename
from rankdbsetup import Base, Rankings
from csvsql import genInsert
import sqlite3
application = Flask(__name__)
engine = create_engine('sqlite:///datasetfull.db')
Base.metadata.bind = engine
session = scoped_session(sessionmaker(bind=engine))
@application.teardown_request
def remove_session(ex=None):
session.remove()
@application.route('/')
@application.route('/index')
@application.route('/top100')
def top200():
try:
ranks = session.query(Rankings).filter(Rankings.ranking, Rankings.ranking <= 100).order_by(Rankings.ranking).all()
except ValueError:
print "Oops! Database Error. Try again..."
return render_template('teams.html', ranks = ranks, team_name='Top 100', team_abbrev='nba')
@application.route('/all')
def allrank():
try:
ranks = session.query(Rankings).order_by(Rankings.ranking).all()
except ValueError:
print "Oops! Database Error. Try again..."
return render_template('teams.html', ranks = ranks, team_name='Top 100', team_abbrev='nba')
@application.route('/<string:team_id>/')
def teams(team_id):
try:
ranks = session.query(Rankings).filter_by(team_id=team_id).order_by(Rankings.ranking).all()
except ValueError:
print "Oops! Database Error. Try again..."
return render_template('teams.html', ranks = ranks, team_name=teamabbrev[team_id], team_abbrev=team_id)
@application.route('/player/<string:asset_id>/')
def player(asset_id):
try:
player = session.query(Rankings).filter_by(asset_id=asset_id).order_by(Rankings.ranking).all()
team_id = player[0].team_id
except ValueError:
print "Oops! Database Error. Try again..."
return render_template('player.html', player = player, team_name=teamabbrev[team_id], team_abbrev=team_id)
@application.route('/about')
def about():
return render_template('about.html')
@application.route('/upload')
def upload():
return render_template('upload.html')
@application.route('/uploadsuccess')
def uploadsuccess():
return render_template('uploadsuccess.html')
@application.route('/uploaderror')
def uploaderror():
return render_template('uploaderror.html')
@application.route('/uploader', methods = ['GET', 'POST'])
def upload_file():
if request.method == 'POST':
f = request.files['file']
f.save(secure_filename(f.filename))
filename = str(f.filename)
try:
genInsert(filename)
except:
return redirect(url_for('uploaderror'))
return redirect(url_for('uploadsuccess'))
@application.route('/snek')
def snek():
return render_template('snek.html')
teamabbrev = {
'DAL': 'Dallas Mavericks',
'HOU': 'Houston Rockets',
'MEM': 'Memphis Grizzlies',
'NOP' : 'New Orleans Pelicans',
'SAS': 'San Antonio Spurs',
'GSW': 'Golden State Warriors',
'LAL': 'Los Angeles Lakers',
'LAC': 'Los Angeles Clippers',
'PHX': 'Phoenix Suns',
'SAC': 'Sacramento Kings',
'DEN': 'Denver Nuggets',
'MIN': 'Minnesota Timberwolves',
'OKC': 'Oklahoma City Thunder',
'POR': 'Portland Trailblazers',
'UTH': 'Utah Jazz',
'BOS': 'Boston Celtics',
'BRK': 'Brooklyn Nets',
'NYK': 'New York Knicks',
'PHL': 'Philadelphia 76ers',
'TOR': 'Toronto Raptors',
'CHI': 'Chicago Bulls',
'CLE': 'Cleveland Cavaliers',
'DET': 'Detroit Pistons',
'IND': 'Indiana Pacers',
'MIL': 'Milwaukee Bucks',
'ATL': 'Atlanta Hawks',
'CHA': 'Charlotte Hornets',
'MIA': 'Miami Heat',
'ORL': 'Orlando Magic',
'WAS': 'Washington Wizards'
}
if __name__ == "__main__":
# Setting debug to True enables debug output. This line should be
# removed before deploying a production application.
application.debug = False
application.run()