Files
LEDMatrix/scripts/download_nba_logos.py
T
Claude ab087cf600 fix(scripts): repair broken sys.path setup in utility scripts
clear_cache.py and download_nba_logos.py pointed sys.path at a 'src'
directory relative to the script's own folder (scripts/utils/src and
scripts/src — neither exists), so both crashed on import; they now insert
the project root and import via the src package like the other scripts.
debug_web_manual.py resolved 'project root' to scripts/debug/ instead of
two levels up. fix_nhl_cache.sh is removed: it used Python docstring
syntax in a bash script and invoked clear_nhl_cache.py, which does not
exist anywhere in the repo — it cannot ever have worked in its current
location.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SXb4mKcAkVaxkeTb3YnAdr
2026-08-05 23:55:17 +00:00

99 lines
3.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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 project root to Python path so we can import the logo downloader
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# 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 src.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()