From 7ba32dc98b0453cc494a52c4ab7005faf008a41d Mon Sep 17 00:00:00 2001 From: Eduardo Figueroa Date: Fri, 12 Sep 2025 15:36:09 -0700 Subject: [PATCH] Mapping file to match ESPN to Sleeper names. --- app.py | 5 ++++ config.py | 9 ++++++ services/espn_api.py | 61 ++++++++++++++++++++++++++++++++++++++-- templates/dashboard.html | 4 +-- 4 files changed, 75 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index e3f253b..16159e5 100644 --- a/app.py +++ b/app.py @@ -63,6 +63,11 @@ def get_league_color(league_index): colors = app.config['LEAGUE_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 def inject_apis(): """Make API and version available to all templates""" diff --git a/config.py b/config.py index 311c23e..d2c5d6b 100644 --- a/config.py +++ b/config.py @@ -14,3 +14,12 @@ class Config: LEAGUE_COLORS = [ '#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) + } diff --git a/services/espn_api.py b/services/espn_api.py index da549ce..d3ca70e 100644 --- a/services/espn_api.py +++ b/services/espn_api.py @@ -5,9 +5,64 @@ import zoneinfo class ESPNAPI: 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): 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): """Get injury status for a specific player from ESPN""" try: @@ -97,10 +152,12 @@ class ESPNAPI: # Identify home and away teams for comp in competitors: team_abbrev = comp['team']['abbreviation'] + # Normalize team abbreviation to match Sleeper format + normalized_team = self.normalize_team_abbreviation(team_abbrev) if comp['homeAway'] == 'home': - home_team = team_abbrev + home_team = normalized_team 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) diff --git a/templates/dashboard.html b/templates/dashboard.html index d0de849..d349a92 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -168,7 +168,7 @@ {% for player in starters %}
- {{ player.fantasy_positions[0] if player.fantasy_positions else 'FLEX' }} + {{ player.fantasy_positions[0] if player.fantasy_positions else 'FLEX' }}-{{ player.team if player.team else 'FA' }} {{ player.last_name }} {% if player.injury_status %} {{ player.injury_status }} @@ -187,7 +187,7 @@ {% for player in bench_players %}
- {{ player.fantasy_positions[0] if player.fantasy_positions else 'FLEX' }} + {{ player.fantasy_positions[0] if player.fantasy_positions else 'FLEX' }}-{{ player.team if player.team else 'FA' }} {{ player.last_name }} {% if player.injury_status %} {{ player.injury_status }}