update UTC timezone logic to check config settings for all managers

This commit is contained in:
ChuckBuilds
2025-09-04 22:18:01 -04:00
parent 92071237c1
commit 8a0fdb005d
21 changed files with 1037 additions and 8 deletions

85
test/debug_espn_api.py Normal file
View File

@@ -0,0 +1,85 @@
#!/usr/bin/env python3
"""
Debug script to examine ESPN API response structure
"""
import requests
import json
def debug_espn_api():
"""Debug ESPN API responses."""
# Test different endpoints
test_endpoints = [
{
'name': 'NFL Standings',
'url': 'https://site.api.espn.com/apis/site/v2/sports/football/nfl/standings'
},
{
'name': 'NFL Teams',
'url': 'https://site.api.espn.com/apis/site/v2/sports/football/nfl/teams'
},
{
'name': 'NFL Scoreboard',
'url': 'https://site.api.espn.com/apis/site/v2/sports/football/nfl/scoreboard'
},
{
'name': 'NBA Teams',
'url': 'https://site.api.espn.com/apis/site/v2/sports/basketball/nba/teams'
},
{
'name': 'MLB Teams',
'url': 'https://site.api.espn.com/apis/site/v2/sports/baseball/mlb/teams'
}
]
for endpoint in test_endpoints:
print(f"\n{'='*50}")
print(f"Testing {endpoint['name']}")
print(f"URL: {endpoint['url']}")
print('='*50)
try:
response = requests.get(endpoint['url'], timeout=30)
response.raise_for_status()
data = response.json()
print(f"Response status: {response.status_code}")
print(f"Response keys: {list(data.keys())}")
# Print a sample of the response
if 'sports' in data:
sports = data['sports']
print(f"Sports found: {len(sports)}")
if sports:
leagues = sports[0].get('leagues', [])
print(f"Leagues found: {len(leagues)}")
if leagues:
teams = leagues[0].get('teams', [])
print(f"Teams found: {len(teams)}")
if teams:
print("Sample team data:")
sample_team = teams[0]
print(f" Team: {sample_team.get('team', {}).get('name', 'Unknown')}")
print(f" Abbreviation: {sample_team.get('team', {}).get('abbreviation', 'Unknown')}")
stats = sample_team.get('stats', [])
print(f" Stats found: {len(stats)}")
for stat in stats[:3]: # Show first 3 stats
print(f" {stat.get('name', 'Unknown')}: {stat.get('value', 'Unknown')}")
elif 'groups' in data:
groups = data['groups']
print(f"Groups found: {len(groups)}")
if groups:
print("Sample group data:")
print(json.dumps(groups[0], indent=2)[:500] + "...")
else:
print("Sample response data:")
print(json.dumps(data, indent=2)[:500] + "...")
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
debug_espn_api()

99
test/test_leaderboard.py Normal file
View File

@@ -0,0 +1,99 @@
#!/usr/bin/env python3
"""
Test script for the LeaderboardManager
"""
import sys
import os
import json
import logging
# Add the src directory to the path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src'))
from leaderboard_manager import LeaderboardManager
from display_manager import DisplayManager
from config_manager import ConfigManager
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s'
)
def test_leaderboard_manager():
"""Test the leaderboard manager functionality."""
# Load configuration
config_manager = ConfigManager()
config = config_manager.load_config()
# Enable leaderboard and some sports for testing
config['leaderboard'] = {
'enabled': True,
'enabled_sports': {
'nfl': {
'enabled': True,
'top_teams': 5
},
'nba': {
'enabled': True,
'top_teams': 5
},
'mlb': {
'enabled': True,
'top_teams': 5
}
},
'update_interval': 3600,
'scroll_speed': 2,
'scroll_delay': 0.05,
'display_duration': 60,
'loop': True,
'request_timeout': 30,
'dynamic_duration': True,
'min_duration': 30,
'max_duration': 300,
'duration_buffer': 0.1
}
# Initialize display manager (this will be a mock for testing)
display_manager = DisplayManager(config)
# Initialize leaderboard manager
leaderboard_manager = LeaderboardManager(config, display_manager)
print("Testing LeaderboardManager...")
print(f"Enabled: {leaderboard_manager.is_enabled}")
print(f"Enabled sports: {[k for k, v in leaderboard_manager.league_configs.items() if v['enabled']]}")
# Test fetching standings
print("\nFetching standings...")
leaderboard_manager.update()
print(f"Number of leagues with data: {len(leaderboard_manager.leaderboard_data)}")
for league_data in leaderboard_manager.leaderboard_data:
league = league_data['league']
teams = league_data['teams']
print(f"\n{league.upper()}:")
for i, team in enumerate(teams[:5]): # Show top 5
record = f"{team['wins']}-{team['losses']}"
if 'ties' in team:
record += f"-{team['ties']}"
print(f" {i+1}. {team['abbreviation']} {record}")
# Test image creation
print("\nCreating leaderboard image...")
if leaderboard_manager.leaderboard_data:
leaderboard_manager._create_leaderboard_image()
if leaderboard_manager.leaderboard_image:
print(f"Image created successfully: {leaderboard_manager.leaderboard_image.size}")
print(f"Dynamic duration: {leaderboard_manager.dynamic_duration:.1f}s")
else:
print("Failed to create image")
else:
print("No data available to create image")
if __name__ == "__main__":
test_leaderboard_manager()

View File

@@ -0,0 +1,205 @@
#!/usr/bin/env python3
"""
Simple test script for the LeaderboardManager (without display dependencies)
"""
import sys
import os
import json
import logging
import requests
from typing import Dict, Any, List, Optional
from datetime import datetime, timedelta, timezone
from PIL import Image, ImageDraw, ImageFont
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
def test_espn_api():
"""Test ESPN API endpoints for standings."""
# Test different league endpoints
test_leagues = [
{
'name': 'NFL',
'url': 'https://site.api.espn.com/apis/site/v2/sports/football/nfl/standings'
},
{
'name': 'NBA',
'url': 'https://site.api.espn.com/apis/site/v2/sports/basketball/nba/standings'
},
{
'name': 'MLB',
'url': 'https://site.api.espn.com/apis/site/v2/sports/baseball/mlb/standings'
}
]
for league in test_leagues:
print(f"\nTesting {league['name']} API...")
try:
response = requests.get(league['url'], timeout=30)
response.raise_for_status()
data = response.json()
print(f"{league['name']} API response successful")
# Check if we have groups data
groups = data.get('groups', [])
print(f" Groups found: {len(groups)}")
# Try to extract some team data
total_teams = 0
for group in groups:
if 'standings' in group:
total_teams += len(group['standings'])
elif 'groups' in group:
# Handle nested groups (like NFL conferences/divisions)
for sub_group in group['groups']:
if 'standings' in sub_group:
total_teams += len(sub_group['standings'])
elif 'groups' in sub_group:
for sub_sub_group in sub_group['groups']:
if 'standings' in sub_sub_group:
total_teams += len(sub_sub_group['standings'])
print(f" Total teams found: {total_teams}")
except Exception as e:
print(f"{league['name']} API failed: {e}")
def test_standings_parsing():
"""Test parsing standings data."""
# Test NFL standings parsing using teams endpoint
print("\nTesting NFL standings parsing...")
try:
# First get all teams
teams_url = 'https://site.api.espn.com/apis/site/v2/sports/football/nfl/teams'
response = requests.get(teams_url, timeout=30)
response.raise_for_status()
data = response.json()
sports = data.get('sports', [])
if not sports:
print("✗ No sports data found")
return
leagues = sports[0].get('leagues', [])
if not leagues:
print("✗ No leagues data found")
return
teams = leagues[0].get('teams', [])
if not teams:
print("✗ No teams data found")
return
print(f"Found {len(teams)} NFL teams")
# Test fetching individual team records
standings = []
test_teams = teams[:5] # Test first 5 teams to avoid too many API calls
for team_data in test_teams:
team = team_data.get('team', {})
team_abbr = team.get('abbreviation')
team_name = team.get('name', 'Unknown')
if not team_abbr:
continue
print(f" Fetching record for {team_abbr}...")
# Fetch individual team record
team_url = f"https://site.api.espn.com/apis/site/v2/sports/football/nfl/teams/{team_abbr}"
team_response = requests.get(team_url, timeout=30)
team_response.raise_for_status()
team_data = team_response.json()
team_info = team_data.get('team', {})
stats = team_info.get('stats', [])
# Find wins and losses
wins = 0
losses = 0
ties = 0
for stat in stats:
if stat.get('name') == 'wins':
wins = stat.get('value', 0)
elif stat.get('name') == 'losses':
losses = stat.get('value', 0)
elif stat.get('name') == 'ties':
ties = stat.get('value', 0)
# Calculate win percentage
total_games = wins + losses + ties
win_percentage = wins / total_games if total_games > 0 else 0
standings.append({
'name': team_name,
'abbreviation': team_abbr,
'wins': wins,
'losses': losses,
'ties': ties,
'win_percentage': win_percentage
})
# Sort by win percentage and show results
standings.sort(key=lambda x: x['win_percentage'], reverse=True)
print("NFL team records:")
for i, team in enumerate(standings):
record = f"{team['wins']}-{team['losses']}"
if team['ties'] > 0:
record += f"-{team['ties']}"
print(f" {i+1}. {team['abbreviation']} {record} ({team['win_percentage']:.3f})")
except Exception as e:
print(f"✗ NFL standings parsing failed: {e}")
def test_logo_loading():
"""Test logo loading functionality."""
print("\nTesting logo loading...")
# Test team logo loading
logo_dir = "assets/sports/nfl_logos"
test_teams = ["TB", "DAL", "NE"]
for team in test_teams:
logo_path = os.path.join(logo_dir, f"{team}.png")
if os.path.exists(logo_path):
print(f"{team} logo found: {logo_path}")
else:
print(f"{team} logo not found: {logo_path}")
# Test league logo loading
league_logos = [
"assets/sports/nfl_logos/nfl.png",
"assets/sports/nba_logos/nba.png",
"assets/sports/mlb_logos/mlb.png",
"assets/sports/nhl_logos/nhl.png",
"assets/sports/ncaa_fbs_logos/ncaa_fb.png",
"assets/sports/ncaa_fbs_logos/ncaam.png"
]
for logo_path in league_logos:
if os.path.exists(logo_path):
print(f"✓ League logo found: {logo_path}")
else:
print(f"✗ League logo not found: {logo_path}")
if __name__ == "__main__":
print("Testing LeaderboardManager components...")
test_espn_api()
test_standings_parsing()
test_logo_loading()
print("\nTest completed!")