mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 21:03:01 +00:00
Add MLB support to CacheManager
This commit is contained in:
@@ -195,6 +195,8 @@ class CacheManager:
|
|||||||
return self._has_news_changed(cached_data, new_data)
|
return self._has_news_changed(cached_data, new_data)
|
||||||
elif data_type == 'nhl':
|
elif data_type == 'nhl':
|
||||||
return self._has_nhl_changed(cached_data, new_data)
|
return self._has_nhl_changed(cached_data, new_data)
|
||||||
|
elif data_type == 'mlb':
|
||||||
|
return self._has_mlb_changed(cached_data, new_data)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -234,6 +236,37 @@ class CacheManager:
|
|||||||
return (cached.get('game_status') != new.get('game_status') or
|
return (cached.get('game_status') != new.get('game_status') or
|
||||||
cached.get('score') != new.get('score'))
|
cached.get('score') != new.get('score'))
|
||||||
|
|
||||||
|
def _has_mlb_changed(self, cached: Dict[str, Any], new: Dict[str, Any]) -> bool:
|
||||||
|
"""Check if MLB game data has changed."""
|
||||||
|
if not cached or not new:
|
||||||
|
return True
|
||||||
|
|
||||||
|
# Check if any games have changed status or score
|
||||||
|
for game_id, new_game in new.items():
|
||||||
|
cached_game = cached.get(game_id)
|
||||||
|
if not cached_game:
|
||||||
|
return True
|
||||||
|
|
||||||
|
# Check for score changes
|
||||||
|
if (new_game['away_score'] != cached_game['away_score'] or
|
||||||
|
new_game['home_score'] != cached_game['home_score']):
|
||||||
|
return True
|
||||||
|
|
||||||
|
# Check for status changes
|
||||||
|
if new_game['status'] != cached_game['status']:
|
||||||
|
return True
|
||||||
|
|
||||||
|
# For live games, check inning and count
|
||||||
|
if new_game['status'] == 'in':
|
||||||
|
if (new_game['inning'] != cached_game['inning'] or
|
||||||
|
new_game['inning_half'] != cached_game['inning_half'] or
|
||||||
|
new_game['balls'] != cached_game['balls'] or
|
||||||
|
new_game['strikes'] != cached_game['strikes'] or
|
||||||
|
new_game['bases_occupied'] != cached_game['bases_occupied']):
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
def _is_market_open(self) -> bool:
|
def _is_market_open(self) -> bool:
|
||||||
"""Check if the US stock market is currently open."""
|
"""Check if the US stock market is currently open."""
|
||||||
et_tz = pytz.timezone('America/New_York')
|
et_tz = pytz.timezone('America/New_York')
|
||||||
|
|||||||
Reference in New Issue
Block a user