-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
80 lines (65 loc) · 2.63 KB
/
app.py
File metadata and controls
80 lines (65 loc) · 2.63 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
69
70
71
72
73
74
75
76
77
78
79
80
from flask import Flask, jsonify
from web_scraper_functions import *
app = Flask(__name__)
@app.route('/player/<first_name>/<last_name>/<year>/stats/season', methods=['GET'])
def get_season_stats(first_name, last_name, year):
try:
# Call the function to fetch season stats
data = get_player_season_stats(first_name, last_name, year)
if data is None:
return jsonify({'error': 'Player not found or invalid URL'}), 404
return jsonify(data)
except Exception as e:
return jsonify({'error': str(e)}), 500
@app.route('/player/<first_name>/<last_name>/stats/career', methods=['GET'])
def get_career_stats(first_name, last_name):
try:
# Call the function to fetch career stats
data = get_player_career_stats(first_name, last_name)
if data is None:
return jsonify({'error': 'Player not found or invalid URL'}), 404
return jsonify(data)
except Exception as e:
return jsonify({'error': str(e)}), 500
@app.route('/NBA/<pra>/<rs_p>/leaders/career', methods=['GET'])
def get_career_pra_leaders(pra, rs_p):
try:
# Call the function to fetch career leaders
data = get_career_leaders(pra, rs_p)
if data is None:
return jsonify({'error': 'Leaders not found or invalid URL'}), 404
return jsonify(data)
except Exception as e:
return jsonify({'error': str(e)}), 500
@app.route('/NBA/<pra>/<rs_p>/leaders/season', methods=['GET'])
def get_season_pra_leaders(pra, rs_p):
try:
# Call the function to fetch season leaders
data = get_season_leaders(pra, rs_p)
if data is None:
return jsonify({'error': 'Leaders not found or invalid URL'}), 404
return jsonify(data)
except Exception as e:
return jsonify({'error': str(e)}), 500
@app.route('/NBA/<team>/<year>/roster', methods=['GET'])
def get_team_roster(team, year):
try:
# Call the function to fetch team roster
data = get_team_roster_year(team, year)
if data is None:
return jsonify({'error': 'Team not found or invalid URL'}), 404
return jsonify(data)
except Exception as e:
return jsonify({'error': str(e)}), 500
@app.route('/NBA/<year>/draft', methods=['GET'])
def get_nba_draft(year):
try:
# Call the function to fetch NBA draft data
data = get_nba_draft_year(year)
if data is None:
return jsonify({'error': 'Draft data not found or invalid URL'}), 404
return jsonify(data)
except Exception as e:
return jsonify({'error': str(e)}), 500
if __name__ == '__main__':
app.run(debug=False)