Mapping file to match ESPN to Sleeper names.
This commit is contained in:
parent
337d4b04ed
commit
7ba32dc98b
4 changed files with 75 additions and 4 deletions
5
app.py
5
app.py
|
|
@ -63,6 +63,11 @@ def get_league_color(league_index):
|
||||||
colors = app.config['LEAGUE_COLORS']
|
colors = app.config['LEAGUE_COLORS']
|
||||||
return colors[league_index % len(colors)] # Cycle through colors
|
return colors[league_index % len(colors)] # Cycle through colors
|
||||||
|
|
||||||
|
def normalize_team_abbreviation(espn_team):
|
||||||
|
"""Convert ESPN team abbreviation to Sleeper format"""
|
||||||
|
team_map = app.config['TEAM_ABBREVIATION_MAP']
|
||||||
|
return team_map.get(espn_team, espn_team)
|
||||||
|
|
||||||
@app.context_processor
|
@app.context_processor
|
||||||
def inject_apis():
|
def inject_apis():
|
||||||
"""Make API and version available to all templates"""
|
"""Make API and version available to all templates"""
|
||||||
|
|
|
||||||
|
|
@ -14,3 +14,12 @@ class Config:
|
||||||
LEAGUE_COLORS = [
|
LEAGUE_COLORS = [
|
||||||
'#003594', '#ffa300', '#8a2be2', '#ff69b4', '#40e0d0', '#dda0dd'
|
'#003594', '#ffa300', '#8a2be2', '#ff69b4', '#40e0d0', '#dda0dd'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Team abbreviation mapping - ESPN to Sleeper
|
||||||
|
# Some teams have different abbreviations between APIs
|
||||||
|
TEAM_ABBREVIATION_MAP = {
|
||||||
|
'WSH': 'WAS', # Washington
|
||||||
|
'LV': 'LV', # Las Vegas (same)
|
||||||
|
'LAR': 'LAR', # Los Angeles Rams (same)
|
||||||
|
'LAC': 'LAC', # Los Angeles Chargers (same)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,64 @@ import zoneinfo
|
||||||
class ESPNAPI:
|
class ESPNAPI:
|
||||||
BASE_URL = 'https://site.api.espn.com/apis/site/v2/sports/football/nfl'
|
BASE_URL = 'https://site.api.espn.com/apis/site/v2/sports/football/nfl'
|
||||||
|
|
||||||
|
# Team abbreviation mapping - ESPN to Sleeper format
|
||||||
|
TEAM_MAP = {
|
||||||
|
# AFC East
|
||||||
|
'BUF': 'BUF', # Buffalo Bills
|
||||||
|
'MIA': 'MIA', # Miami Dolphins
|
||||||
|
'NE': 'NE', # New England Patriots
|
||||||
|
'NYJ': 'NYJ', # New York Jets
|
||||||
|
|
||||||
|
# AFC North
|
||||||
|
'BAL': 'BAL', # Baltimore Ravens
|
||||||
|
'CIN': 'CIN', # Cincinnati Bengals
|
||||||
|
'CLE': 'CLE', # Cleveland Browns
|
||||||
|
'PIT': 'PIT', # Pittsburgh Steelers
|
||||||
|
|
||||||
|
# AFC South
|
||||||
|
'HOU': 'HOU', # Houston Texans
|
||||||
|
'IND': 'IND', # Indianapolis Colts
|
||||||
|
'JAX': 'JAX', # Jacksonville Jaguars
|
||||||
|
'TEN': 'TEN', # Tennessee Titans
|
||||||
|
|
||||||
|
# AFC West
|
||||||
|
'DEN': 'DEN', # Denver Broncos
|
||||||
|
'KC': 'KC', # Kansas City Chiefs
|
||||||
|
'LV': 'LV', # Las Vegas Raiders
|
||||||
|
'LAC': 'LAC', # Los Angeles Chargers
|
||||||
|
|
||||||
|
# NFC East
|
||||||
|
'DAL': 'DAL', # Dallas Cowboys
|
||||||
|
'NYG': 'NYG', # New York Giants
|
||||||
|
'PHI': 'PHI', # Philadelphia Eagles
|
||||||
|
'WSH': 'WAS', # Washington Commanders (ESPN uses WSH, Sleeper uses WAS)
|
||||||
|
|
||||||
|
# NFC North
|
||||||
|
'CHI': 'CHI', # Chicago Bears
|
||||||
|
'DET': 'DET', # Detroit Lions
|
||||||
|
'GB': 'GB', # Green Bay Packers
|
||||||
|
'MIN': 'MIN', # Minnesota Vikings
|
||||||
|
|
||||||
|
# NFC South
|
||||||
|
'ATL': 'ATL', # Atlanta Falcons
|
||||||
|
'CAR': 'CAR', # Carolina Panthers
|
||||||
|
'NO': 'NO', # New Orleans Saints
|
||||||
|
'TB': 'TB', # Tampa Bay Buccaneers
|
||||||
|
|
||||||
|
# NFC West
|
||||||
|
'ARI': 'ARI', # Arizona Cardinals
|
||||||
|
'LAR': 'LAR', # Los Angeles Rams
|
||||||
|
'SF': 'SF', # San Francisco 49ers
|
||||||
|
'SEA': 'SEA', # Seattle Seahawks
|
||||||
|
}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.session = requests.Session()
|
self.session = requests.Session()
|
||||||
|
|
||||||
|
def normalize_team_abbreviation(self, espn_team):
|
||||||
|
"""Convert ESPN team abbreviation to Sleeper format"""
|
||||||
|
return self.TEAM_MAP.get(espn_team, espn_team)
|
||||||
|
|
||||||
def get_player_injury_status(self, player_name):
|
def get_player_injury_status(self, player_name):
|
||||||
"""Get injury status for a specific player from ESPN"""
|
"""Get injury status for a specific player from ESPN"""
|
||||||
try:
|
try:
|
||||||
|
|
@ -97,10 +152,12 @@ class ESPNAPI:
|
||||||
# Identify home and away teams
|
# Identify home and away teams
|
||||||
for comp in competitors:
|
for comp in competitors:
|
||||||
team_abbrev = comp['team']['abbreviation']
|
team_abbrev = comp['team']['abbreviation']
|
||||||
|
# Normalize team abbreviation to match Sleeper format
|
||||||
|
normalized_team = self.normalize_team_abbreviation(team_abbrev)
|
||||||
if comp['homeAway'] == 'home':
|
if comp['homeAway'] == 'home':
|
||||||
home_team = team_abbrev
|
home_team = normalized_team
|
||||||
else:
|
else:
|
||||||
away_team = team_abbrev
|
away_team = normalized_team
|
||||||
|
|
||||||
print(f"ESPN API: {away_team} @ {home_team} at {game_date_local.strftime('%I:%M %p')} {tz_abbr}", flush=True)
|
print(f"ESPN API: {away_team} @ {home_team} at {game_date_local.strftime('%I:%M %p')} {tz_abbr}", flush=True)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -168,7 +168,7 @@
|
||||||
{% for player in starters %}
|
{% for player in starters %}
|
||||||
<a href="https://sleeper.app/leagues/{{ league_info.league.league_id }}" target="_blank" class="player-pill-link">
|
<a href="https://sleeper.app/leagues/{{ league_info.league.league_id }}" target="_blank" class="player-pill-link">
|
||||||
<div class="player-pill starter {{ player.fantasy_positions[0]|lower if player.fantasy_positions else 'flex' }}">
|
<div class="player-pill starter {{ player.fantasy_positions[0]|lower if player.fantasy_positions else 'flex' }}">
|
||||||
<span class="pos">{{ player.fantasy_positions[0] if player.fantasy_positions else 'FLEX' }}</span>
|
<span class="pos">{{ player.fantasy_positions[0] if player.fantasy_positions else 'FLEX' }}-{{ player.team if player.team else 'FA' }}</span>
|
||||||
<span class="name">{{ player.last_name }}
|
<span class="name">{{ player.last_name }}
|
||||||
{% if player.injury_status %}
|
{% if player.injury_status %}
|
||||||
<span class="injury-status">{{ player.injury_status }}</span>
|
<span class="injury-status">{{ player.injury_status }}</span>
|
||||||
|
|
@ -187,7 +187,7 @@
|
||||||
{% for player in bench_players %}
|
{% for player in bench_players %}
|
||||||
<a href="https://sleeper.app/leagues/{{ league_info.league.league_id }}" target="_blank" class="player-pill-link">
|
<a href="https://sleeper.app/leagues/{{ league_info.league.league_id }}" target="_blank" class="player-pill-link">
|
||||||
<div class="player-pill bench {{ player.fantasy_positions[0]|lower if player.fantasy_positions else 'flex' }}">
|
<div class="player-pill bench {{ player.fantasy_positions[0]|lower if player.fantasy_positions else 'flex' }}">
|
||||||
<span class="pos">{{ player.fantasy_positions[0] if player.fantasy_positions else 'FLEX' }}</span>
|
<span class="pos">{{ player.fantasy_positions[0] if player.fantasy_positions else 'FLEX' }}-{{ player.team if player.team else 'FA' }}</span>
|
||||||
<span class="name">{{ player.last_name }}
|
<span class="name">{{ player.last_name }}
|
||||||
{% if player.injury_status %}
|
{% if player.injury_status %}
|
||||||
<span class="injury-status">{{ player.injury_status }}</span>
|
<span class="injury-status">{{ player.injury_status }}</span>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue