Independent project utilizing web scraping for live NFL scores, accessing an NFL API for live fantasy performance in JSON format, and a dataset from Kaggle with predictive 2024 fantasy football performance data (based on fantasy performance in the 2023 NFL season).
GitHub Repository - Fantasy Homepage Application
@app.route('/')
def
home
():
return render_template('index.html')
@app.route('/dashboard')
def
dashboard
():
return render_template('dashboard.html')
@app.route('/fantasy')
def
fantasy
():
return render_template('fantasy.html')
@app.route('/score')
def
score
():
return render_template('score.html')
@app.route('/teams')
def
teams
():
return render_template('teams.html')
@app.route('/superbowl')
def
superbowl
():
return render_template('superbowl.html')
@app.route('/rookie')
def
rookie
():
return render_template('rookie.html')
@app.route('/dst')
def
dst
():
return render_template('dst.html')
@app.route('/qb')
def qb():
return render_template('qb.html')
@app.route('/rb')
def
rb
():
return render_template('rb.html')
@app.route('/wr')
def
wr
():
return render_template('wr.html')
@app.route('/te')
def
te
():
return render_template('te.html')
# Pull in fantasy predictive data
@app.route('/get_data/<position>', methods=['GET'])
def
get_data
(position):
# Load CSV for each position
if position == 'qb':
df = pd.read_csv('data/qb_data.csv')
main_columns = QB_COLUMNS
elif position == 'wr':
df = pd.read_csv('data/wr_data.csv')
main_columns = WR_COLUMNS
elif position == 'rb':
df = pd.read_csv('data/rb_data.csv')
main_columns = RB_COLUMNS
elif position == 'te':
df = pd.read_csv('data/te_data.csv')
main_columns = TE_COLUMNS
else:
return jsonify({'error': 'Invalid position selected'}), 400
# Prepare dashboard data
main_data
= reorder_columns(df[main_columns], main_columns).to_dict(orient='records')
# Prepare popup data
popup_data
= df[POPUP_COLUMNS].to_dict(orient='records')
return jsonify({
'main_data': main_data,
'main_columns': main_columns,
'popup_data': popup_data,
'popup_columns': POPUP_COLUMNS
})
# Get weekly scoring data
@app.route('/api/scores/<int:week>', methods=['GET'])
def
get_scores
(week):
url = f"https://www.pro-football-reference.com/years/2024/week_
{week}
.htm"
try:
response = requests.get(url)
response.raise_for_status()
soup = BeautifulSoup(response.content, 'html.parser')
games = soup.select('#games tbody tr')
scores = []
for game in games:
winner = game.select_one('.winner')
loser = game.select_one('.loser')
if winner and loser:
scores.append({
'date': game.select_one('.date').text,
'winner': winner.select_one('a').text,
'winnerScore': winner.select_one('.score').text,
'loser': loser.select_one('a').text,
'loserScore': loser.select_one('.score').text
})
return jsonify(scores)
except requests.RequestException as e:
return jsonify({'error': str(e)}), 500