soccer game extraction improvement

This commit is contained in:
Chuck
2025-08-09 14:09:05 -05:00
parent fd68777484
commit 708e993f41

View File

@@ -333,6 +333,7 @@ class BaseSoccerManager:
try: try:
if not os.path.exists(logo_path): if not os.path.exists(logo_path):
self.logger.info(f"Creating placeholder logo for {team_abbrev}") self.logger.info(f"Creating placeholder logo for {team_abbrev}")
try:
os.makedirs(os.path.dirname(logo_path), exist_ok=True) os.makedirs(os.path.dirname(logo_path), exist_ok=True)
logo = Image.new('RGBA', (36, 36), (random.randint(50, 200), random.randint(50, 200), random.randint(50, 200), 255)) logo = Image.new('RGBA', (36, 36), (random.randint(50, 200), random.randint(50, 200), random.randint(50, 200), 255))
draw = ImageDraw.Draw(logo) draw = ImageDraw.Draw(logo)
@@ -347,7 +348,14 @@ class BaseSoccerManager:
pass # Font not found, skip text pass # Font not found, skip text
logo.save(logo_path) logo.save(logo_path)
self.logger.info(f"Created placeholder logo at {logo_path}") self.logger.info(f"Created placeholder logo at {logo_path}")
except PermissionError as pe:
self.logger.warning(f"Permission denied creating placeholder logo for {team_abbrev}: {pe}")
# Return a simple in-memory placeholder instead
logo = Image.new('RGBA', (36, 36), (random.randint(50, 200), random.randint(50, 200), random.randint(50, 200), 255))
self._logo_cache[team_abbrev] = logo
return logo
try:
logo = Image.open(logo_path) logo = Image.open(logo_path)
if logo.mode != 'RGBA': if logo.mode != 'RGBA':
logo = logo.convert('RGBA') logo = logo.convert('RGBA')
@@ -360,10 +368,19 @@ class BaseSoccerManager:
self._logo_cache[team_abbrev] = logo self._logo_cache[team_abbrev] = logo
return logo return logo
except PermissionError as pe:
self.logger.warning(f"Permission denied accessing logo for {team_abbrev}: {pe}")
# Return a simple in-memory placeholder instead
logo = Image.new('RGBA', (36, 36), (random.randint(50, 200), random.randint(50, 200), random.randint(50, 200), 255))
self._logo_cache[team_abbrev] = logo
return logo
except Exception as e: except Exception as e:
self.logger.error(f"Error loading logo for {team_abbrev}: {e}", exc_info=True) self.logger.error(f"Error loading logo for {team_abbrev}: {e}", exc_info=True)
return None # Return a simple in-memory placeholder as fallback
logo = Image.new('RGBA', (36, 36), (random.randint(50, 200), random.randint(50, 200), random.randint(50, 200), 255))
self._logo_cache[team_abbrev] = logo
return logo
def _format_game_time(self, status: Dict) -> str: def _format_game_time(self, status: Dict) -> str:
"""Format game time display for soccer (e.g., HT, FT, 45', 90+2').""" """Format game time display for soccer (e.g., HT, FT, 45', 90+2')."""
@@ -447,6 +464,13 @@ class BaseSoccerManager:
is_upcoming = status_type == "STATUS_SCHEDULED" is_upcoming = status_type == "STATUS_SCHEDULED"
is_halftime = status_type == "STATUS_HALFTIME" is_halftime = status_type == "STATUS_HALFTIME"
# Calculate if game is within recent window
is_within_window = False
if start_time_utc:
cutoff_time = datetime.now(self._get_timezone()) - timedelta(hours=self.recent_hours)
is_within_window = start_time_utc > cutoff_time
self.logger.debug(f"[Soccer] Game time: {start_time_utc}, Cutoff time: {cutoff_time}, Within window: {is_within_window}")
details = { details = {
"id": game_event["id"], "id": game_event["id"],
"start_time_utc": start_time_utc, "start_time_utc": start_time_utc,
@@ -456,6 +480,7 @@ class BaseSoccerManager:
"is_live": is_live or is_halftime, # Treat halftime as live for display purposes "is_live": is_live or is_halftime, # Treat halftime as live for display purposes
"is_final": is_final, "is_final": is_final,
"is_upcoming": is_upcoming, "is_upcoming": is_upcoming,
"is_within_window": is_within_window,
"home_abbr": home_team["team"]["abbreviation"], "home_abbr": home_team["team"]["abbreviation"],
"home_score": home_team.get("score", "0"), "home_score": home_team.get("score", "0"),
"home_record": home_record, "home_record": home_record,