From 180602265730e638ba42d73b7327d366f69a7143 Mon Sep 17 00:00:00 2001 From: Chuck <33324927+ChuckBuilds@users.noreply.github.com> Date: Sun, 20 Jul 2025 17:49:27 -0500 Subject: [PATCH] improve odds format for ticker --- config/config.json | 2 +- src/odds_manager.py | 4 +++- src/odds_ticker_manager.py | 12 +++++++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/config/config.json b/config/config.json index 6a54ae35..acadcb95 100644 --- a/config/config.json +++ b/config/config.json @@ -109,7 +109,7 @@ }, "odds_ticker": { "enabled": true, - "show_favorite_teams_only": false, + "show_favorite_teams_only": true, "enabled_leagues": ["mlb"], "update_interval": 3600, "scroll_speed": 2, diff --git a/src/odds_manager.py b/src/odds_manager.py index 4458bf70..0867b6ef 100644 --- a/src/odds_manager.py +++ b/src/odds_manager.py @@ -28,7 +28,7 @@ class OddsManager: try: url = f"{self.base_url}/{sport}/leagues/{league}/events/{event_id}/competitions/{event_id}/odds" self.logger.info(f"Requesting odds from URL: {url}") - response = requests.get(url) + response = requests.get(url, timeout=10) response.raise_for_status() raw_data = response.json() self.logger.debug(f"Received raw odds data from ESPN: {json.dumps(raw_data, indent=2)}") @@ -41,6 +41,8 @@ class OddsManager: self.logger.info(f"Saved odds data to cache for {cache_key}") else: self.logger.warning(f"No odds data extracted for {cache_key}") + # Cache the fact that no odds are available to avoid repeated API calls + self.cache_manager.save_cache(cache_key, {"no_odds": True}) return odds_data diff --git a/src/odds_ticker_manager.py b/src/odds_ticker_manager.py index 159aa922..a3708ff7 100644 --- a/src/odds_ticker_manager.py +++ b/src/odds_ticker_manager.py @@ -207,9 +207,15 @@ class OddsTickerManager: odds_data = self.odds_manager.get_odds( sport=sport, league=league, - event_id=game_id + event_id=game_id, + update_interval_seconds=7200 # Cache for 2 hours instead of 1 hour ) + # Include games even without odds data (but log it) + if odds_data and odds_data.get('no_odds'): + logger.debug(f"Game {game_id} has no odds data, but including in display") + odds_data = None # Set to None so display shows just game info + game_data = { 'id': game_id, 'league': league_config['league'], @@ -321,12 +327,12 @@ class OddsTickerManager: if away_logo: away_logo.thumbnail((logo_size, logo_size), Image.Resampling.LANCZOS) - away_x = text_x - logo_size - 5 + away_x = int(text_x - logo_size - 5) image.paste(away_logo, (away_x, logo_y), away_logo) if home_logo: home_logo.thumbnail((logo_size, logo_size), Image.Resampling.LANCZOS) - home_x = text_x + text_width + 5 + home_x = int(text_x + text_width + 5) image.paste(home_logo, (home_x, logo_y), home_logo) return image