improved game filtering milb

This commit is contained in:
Chuck
2025-08-09 11:47:20 -05:00
parent 4cc3b39ce6
commit cc652472a0

View File

@@ -803,6 +803,28 @@ class MiLBLiveManager(BaseMiLBManager):
# Only process games that are actually in progress
if game['status_state'] == 'in' and game['status'] == 'status_in_progress':
# Check if the game is from today or very recent (within last 24 hours)
game_date_str = game.get('start_time', '')
if game_date_str:
try:
# Parse the game date
game_date = datetime.fromisoformat(game_date_str.replace('Z', '+00:00'))
current_utc = datetime.now(timezone.utc)
hours_diff = (current_utc - game_date).total_seconds() / 3600
# If game is more than 24 hours old, it's probably not actually live
if hours_diff > 24:
self.logger.warning(f"[MiLB] Skipping old game marked as live: {game['away_team']} @ {game['home_team']} - game date: {game_date_str}, hours old: {hours_diff:.1f}")
continue
# If game is more than 1 hour in the future, it's not live yet
elif hours_diff < -1:
self.logger.warning(f"[MiLB] Skipping future game marked as live: {game['away_team']} @ {game['home_team']} - game date: {game_date_str}, hours until start: {abs(hours_diff):.1f}")
continue
else:
self.logger.debug(f"[MiLB] Game time check passed: {game['away_team']} @ {game['home_team']} - hours old: {hours_diff:.1f}")
except Exception as e:
self.logger.warning(f"[MiLB] Could not parse game date {game_date_str}: {e}")
# Additional check: Verify the game has actual live data (inning info)
if 'inning' not in game or game['inning'] is None:
self.logger.warning(f"[MiLB] Skipping game without inning data: {game['away_team']} @ {game['home_team']}")