Fix NBA leaderboard team ID field for logo fetching (#116)

* Fix NBA leaderboard team ID field for logo fetching

- Add missing 'id' field to NBA team standings data structure
- Enables proper logo fetching from assets/sports/nba_logos/
- Fixes 'id' KeyError when creating NBA leaderboard images
- Includes diagnostic and test scripts for verification

* Add NBA logo downloader script and documentation

- download_nba_logos.py: Script to download all 30 NBA team logos from ESPN API
- README_NBA_LOGOS.md: Comprehensive documentation for the logo downloader
- Supports force re-download and quiet modes
- Downloads to assets/sports/nba_logos/ for leaderboard integration

* replace NBA Logos

* return NBA logo
This commit is contained in:
Chuck
2025-10-10 18:27:36 -04:00
committed by GitHub
parent 584a4f258e
commit 98d3ed7d91
39 changed files with 1181 additions and 0 deletions

107
scripts/README_NBA_LOGOS.md Normal file
View File

@@ -0,0 +1,107 @@
# NBA Logo Downloader
This script downloads all NBA team logos from the ESPN API and saves them in the `assets/sports/nba_logos/` directory for use with the NBA leaderboard.
## Usage
### Basic Usage
```bash
python download_nba_logos.py
```
### Force Re-download
If you want to re-download all logos (even if they already exist):
```bash
python download_nba_logos.py --force
```
### Quiet Mode
Reduce logging output:
```bash
python download_nba_logos.py --quiet
```
### Combined Options
```bash
python download_nba_logos.py --force --quiet
```
## What It Does
1. **Fetches NBA Team Data**: Gets the complete list of NBA teams from ESPN API
2. **Downloads Logos**: Downloads each team's logo from ESPN's servers
3. **Saves Locally**: Saves logos as `{team_abbr}.png` in `assets/sports/nba_logos/`
4. **Skips Existing**: By default, skips teams that already have logos
5. **Rate Limiting**: Includes small delays between downloads to be respectful to the API
## Expected Output
```
🏀 Starting NBA logo download...
Target directory: assets/sports/nba_logos/
Force download: False
✅ NBA logo download complete!
📊 Summary: 30 downloaded, 0 failed
🎉 NBA logos are now ready for use in the leaderboard!
```
## File Structure
After running the script, you'll have:
```
assets/sports/nba_logos/
├── ATL.png # Atlanta Hawks
├── BOS.png # Boston Celtics
├── BKN.png # Brooklyn Nets
├── CHA.png # Charlotte Hornets
├── CHI.png # Chicago Bulls
├── CLE.png # Cleveland Cavaliers
├── DAL.png # Dallas Mavericks
├── DEN.png # Denver Nuggets
├── DET.png # Detroit Pistons
├── GSW.png # Golden State Warriors
├── HOU.png # Houston Rockets
├── IND.png # Indiana Pacers
├── LAC.png # LA Clippers
├── LAL.png # Los Angeles Lakers
├── MEM.png # Memphis Grizzlies
├── MIA.png # Miami Heat
├── MIL.png # Milwaukee Bucks
├── MIN.png # Minnesota Timberwolves
├── NOP.png # New Orleans Pelicans
├── NYK.png # New York Knicks
├── OKC.png # Oklahoma City Thunder
├── ORL.png # Orlando Magic
├── PHI.png # Philadelphia 76ers
├── PHX.png # Phoenix Suns
├── POR.png # Portland Trail Blazers
├── SAC.png # Sacramento Kings
├── SAS.png # San Antonio Spurs
├── TOR.png # Toronto Raptors
├── UTA.png # Utah Jazz
└── WAS.png # Washington Wizards
```
## Integration with NBA Leaderboard
Once the logos are downloaded, the NBA leaderboard will:
- ✅ Use local logos instantly (no download delays)
- ✅ Display team logos in the scrolling leaderboard
- ✅ Show proper team branding for all 30 NBA teams
## Troubleshooting
### "Import error: No module named 'requests'"
Make sure you're running this from the LEDMatrix project directory where all dependencies are installed.
### "Permission denied" errors
Make sure the script has write permissions to the `assets/sports/nba_logos/` directory.
### Some logos fail to download
This is normal - some teams might have temporary API issues or the ESPN API might be rate-limiting. The script will continue with the successful downloads.
## Requirements
- Python 3.7+
- `requests` library (should be installed with the project)
- Write access to `assets/sports/nba_logos/` directory

View File

@@ -0,0 +1,98 @@
#!/usr/bin/env python3
"""
Script to download all NBA team logos from ESPN API and save them in assets/sports/nba_logos/
"""
import sys
import os
import logging
from typing import Tuple
# Add the src directory to Python path so we can import the logo downloader
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
# Set up logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
def download_nba_logos(force_download: bool = False) -> Tuple[int, int]:
"""
Download all NBA team logos from ESPN API.
Args:
force_download: Whether to re-download existing logos
Returns:
Tuple of (downloaded_count, failed_count)
"""
try:
from logo_downloader import download_all_logos_for_league
logger.info("🏀 Starting NBA logo download...")
logger.info(f"Target directory: assets/sports/nba_logos/")
logger.info(f"Force download: {force_download}")
# Use the existing function to download all NBA logos
downloaded_count, failed_count = download_all_logos_for_league('nba', force_download)
logger.info("✅ NBA logo download complete!")
logger.info(f"📊 Summary: {downloaded_count} downloaded, {failed_count} failed")
if downloaded_count > 0:
logger.info("🎉 NBA logos are now ready for use in the leaderboard!")
else:
logger.info(" All NBA logos were already present or download failed for all teams")
return downloaded_count, failed_count
except ImportError as e:
logger.error(f"❌ Import error: {e}")
logger.info("💡 Make sure you're running this from the LEDMatrix project directory")
return 0, 0
except Exception as e:
logger.error(f"❌ Unexpected error: {e}")
return 0, 0
def main():
"""Main function with command line argument parsing."""
import argparse
parser = argparse.ArgumentParser(description='Download all NBA team logos from ESPN API')
parser.add_argument(
'--force',
action='store_true',
help='Force re-download of existing logos'
)
parser.add_argument(
'--quiet',
action='store_true',
help='Reduce logging output'
)
args = parser.parse_args()
# Set logging level based on quiet flag
if args.quiet:
logging.getLogger().setLevel(logging.WARNING)
logger.info("🚀 NBA Logo Downloader")
logger.info("=" * 50)
# Download the logos
downloaded, failed = download_nba_logos(args.force)
# Exit with appropriate code
if failed > 0 and downloaded == 0:
logger.error("❌ All downloads failed!")
sys.exit(1)
elif failed > 0:
logger.warning(f"⚠️ {failed} downloads failed, but {downloaded} succeeded")
sys.exit(0) # Partial success is still success
else:
logger.info("🎉 All NBA logos downloaded successfully!")
sys.exit(0)
if __name__ == "__main__":
main()