From b3c3db17e2457f4a33a04d19490749326dda8bfb Mon Sep 17 00:00:00 2001 From: Alex Frantz Date: Sat, 2 May 2026 20:48:19 -0400 Subject: [PATCH] add download script --- download_logos.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 download_logos.py diff --git a/download_logos.py b/download_logos.py new file mode 100644 index 0000000..d8a0a6f --- /dev/null +++ b/download_logos.py @@ -0,0 +1,53 @@ +import os +import requests +from PIL import Image +from io import BytesIO + +LEAGUES = [ + ("hockey", "nhl"), + ("football", "nfl"), + ("basketball", "nba"), +] + +LOGO_DIR = "/home/alex/logos" +LOGO_SIZE = (16, 16) + +os.makedirs(LOGO_DIR, exist_ok=True) + +def download_logos(sport, league): + url = f"https://site.api.espn.com/apis/site/v2/sports/{sport}/{league}/teams" + resp = requests.get(url, timeout=10) + resp.raise_for_status() + teams = resp.json().get("sports", [])[0].get("leagues", [])[0].get("teams", []) + + for entry in teams: + team = entry["team"] + abbr = team["abbreviation"].upper() + logo_url = team.get("logos", [{}])[0].get("href") + + if not logo_url: + print(f"No logo for {abbr}, skipping") + continue + + try: + img_resp = requests.get(logo_url, timeout=10) + img = Image.open(BytesIO(img_resp.content)).convert("RGBA") + + # Resize to 16x16 + img = img.resize(LOGO_SIZE, Image.LANCZOS) + + # Flatten onto black background + background = Image.new("RGB", LOGO_SIZE, (0, 0, 0)) + background.paste(img, mask=img.split()[3]) + + out_path = os.path.join(LOGO_DIR, f"{league}_{abbr}.png") + background.save(out_path) + print(f"Saved {out_path}") + except Exception as e: + print(f"Error downloading {abbr}: {e}") + +for sport, league in LEAGUES: + print(f"\nDownloading {league.upper()} logos...") + download_logos(sport, league) + +print("\nDone!") \ No newline at end of file