Football Data
Football Data
App Script 👇
from flask import Flask, request, render_template_string
import random
app = Flask(__name__)
app.secret_key = 'football_secret'
# Simulated player data (replace with real data later)
PLAYERS = {
"John Doe": {
"team": "Alabama",
"stats": [
{"year": 2020, "passing_yards": 2500, "rushing_yards": 300, "touchdowns": 20},
{"year": 2021, "passing_yards": 2800, "rushing_yards": 400, "touchdowns": 25},
{"year": 2022, "passing_yards": 3000, "rushing_yards": 350, "touchdowns": 28}
]
},
"JJ Mccarthy": {
"team": "Michigan",
"stats": [
{"year": 2019, "passing_yards": 2200, "rushing_yards": 200, "touchdowns": 18},
{"year": 2020, "passing_yards": 2400, "rushing_yards": 250, "touchdowns": 20},
{"year": 2021, "passing_yards": 2600, "rushing_yards": 300, "touchdowns": 22}
]
}
}
@app.route('/', methods=['GET', 'POST'])
def stats_explorer():
search_results = None
chart_data = None
if request.method == 'POST':
player_name = request.form.get('player_name', '').strip().lower()
team = request.form.get('team', '').strip().lower()
year = request.form.get('year', '').strip()
# Filter players
for name, data in PLAYERS.items():
if (player_name in name.lower() and
(not team or team in data['team'].lower()) and
(not year or any(str(year) == str(stat['year']) for stat in data['stats']))):
search_results = {"name": name, "team": data['team'], "stats": data['stats']}
# Prepare chart data
chart_data = {
"labels": [str(stat['year']) for stat in data['stats']],
"passing_yards": [stat['passing_yards'] for stat in data['stats']],
"rushing_yards": [stat['rushing_yards'] for stat in data['stats']]
}
break
template = '''
<!DOCTYPE html>
<html>
<head>
<title>College Football Stats Explorer</title>
<style>
body { background: linear-gradient(135deg, #1a1a2e, #16213e); color: #e0e1dd;
font-family: Arial, sans-serif; display: flex; flex-direction: column;
align-items: center; min-height: 100vh; margin: 0; }
.container { text-align: center; margin-top: 50px; width: 80%; max-width: 800px; }
.form { background: #0d1b2a; padding: 20px; border-radius: 10px;
box-shadow: 0 0 20px #778da9; margin-bottom: 20px; }
input[type="text"] { padding: 10px; width: 200px; margin: 5px; border: none;
border-radius: 5px; font-size: 16px; }
button { padding: 10px 20px; background: #e07a5f; color: #fff; border: none;
border-radius: 5px; cursor: pointer; transition: all 0.2s; }
button:hover { background: #f4a261; }
.results { background: #1b263b; padding: 20px; border-radius: 10px;
box-shadow: 0 0 20px #778da9; }
table { width: 100%; border-collapse: collapse; margin: 20px 0; }
th, td { padding: 10px; border: 1px solid #778da9; text-align: center; }
th { background: #415a77; }
canvas { margin-top: 20px; max-width: 100%; }
</style>
</head>
<body>
<div class="container">
<h1>College Football Stats Explorer</h1>
<div class="form">
<form method="post">
<input type="text" name="player_name" placeholder="Player Name" value="{{ request.form.get('player_name', '') }}">
<input type="text" name="team" placeholder="Team" value="{{ request.form.get('team', '') }}">
<input type="text" name="year" placeholder="Year" value="{{ request.form.get('year', '') }}">
<button type="submit">Search</button>
</form>
</div>
{% if search_results %}
<div class="results">
<h2>{{ search_results.name }} ({{ search_results.team }})</h2>
<table>
<tr>
<th>Year</th>
<th>Passing Yards</th>
<th>Rushing Yards</th>
<th>Touchdowns</th>
</tr>
{% for stat in search_results.stats %}
<tr>
<td>{{ stat.year }}</td>
<td>{{ stat.passing_yards }}</td>
<td>{{ stat.rushing_yards }}</td>
<td>{{ stat.touchdowns }}</td>
</tr>
{% endfor %}
</table>
<canvas id="statsChart"></canvas>
</div>
{% endif %}
</div>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
{% if chart_data %}
const ctx = document.getElementById('statsChart').getContext('2d');
new Chart(ctx, {
type: 'bar',
data: {
labels: {{ chart_data.labels|tojson }},
datasets: [
{
label: 'Passing Yards',
data: {{ chart_data.passing_yards|tojson }},
backgroundColor: '#e07a5f',
borderColor: '#e07a5f',
borderWidth: 1
},
{
label: 'Rushing Yards',
data: {{ chart_data.rushing_yards|tojson }},
backgroundColor: '#3d405b',
borderColor: '#3d405b',
borderWidth: 1
}
]
},
options: {
scales: { y: { beginAtZero: true } },
plugins: { legend: { labels: { color: '#e0e1dd' } } }
}
});
{% endif %}
</script>
</body>
</html>
'''
return render_template_string(template, search_results=search_results, chart_data=chart_data)
if __name__ == '__main__':
app.run(debug=True)