mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 21:03:01 +00:00
milb turn off test mode....
This commit is contained in:
@@ -329,7 +329,7 @@
|
|||||||
"enabled": true,
|
"enabled": true,
|
||||||
"live_priority": true,
|
"live_priority": true,
|
||||||
"live_game_duration": 30,
|
"live_game_duration": 30,
|
||||||
"test_mode": true,
|
"test_mode": false,
|
||||||
"update_interval_seconds": 3600,
|
"update_interval_seconds": 3600,
|
||||||
"live_update_interval": 30,
|
"live_update_interval": 30,
|
||||||
"recent_update_interval": 3600,
|
"recent_update_interval": 3600,
|
||||||
|
|||||||
30
milb_diff.txt
Normal file
30
milb_diff.txt
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
diff --git a/src/milb_manager.py b/src/milb_manager.py
|
||||||
|
index 887712c..13a062a 100644
|
||||||
|
--- a/src/milb_manager.py
|
||||||
|
+++ b/src/milb_manager.py
|
||||||
|
@@ -317,7 +317,7 @@ class BaseMiLBManager:
|
||||||
|
|
||||||
|
def _fetch_milb_api_data(self, use_cache: bool = True) -> Dict[str, Any]:
|
||||||
|
"""Fetch MiLB game data from the MLB Stats API."""
|
||||||
|
- cache_key = "milb_api_data"
|
||||||
|
+ cache_key = "milb_live_api_data"
|
||||||
|
if use_cache:
|
||||||
|
cached_data = self.cache_manager.get_with_auto_strategy(cache_key)
|
||||||
|
if cached_data:
|
||||||
|
@@ -346,6 +346,16 @@ class BaseMiLBManager:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
+ # Check if we're in MiLB season (April-September)
|
||||||
|
+ now = datetime.now()
|
||||||
|
+ current_month = now.month
|
||||||
|
+ in_season = 4 <= current_month <= 9
|
||||||
|
+
|
||||||
|
+ if not in_season:
|
||||||
|
+ self.logger.info("MiLB is currently in offseason (October-March). No games expected.")
|
||||||
|
+ self.logger.info("Consider enabling test_mode for offseason testing.")
|
||||||
|
+ return {}
|
||||||
|
+
|
||||||
|
# MiLB league sport IDs (configurable)
|
||||||
|
sport_ids = self.milb_config.get('sport_ids', [10, 11, 12, 13, 14, 15]) # Mexican, AAA, AA, A+, A, Rookie
|
||||||
|
|
||||||
1230
milb_main.py
Normal file
1230
milb_main.py
Normal file
File diff suppressed because it is too large
Load Diff
@@ -510,11 +510,36 @@ class BaseMiLBManager:
|
|||||||
mapped_status = 'status_scheduled'
|
mapped_status = 'status_scheduled'
|
||||||
mapped_status_state = 'pre'
|
mapped_status_state = 'pre'
|
||||||
|
|
||||||
|
# Extract scores with fallback logic
|
||||||
|
away_score = game['away'].get('score')
|
||||||
|
home_score = game['home'].get('score')
|
||||||
|
|
||||||
|
# Debug logging for score extraction
|
||||||
|
self.logger.debug(f"Initial scores for {away_abbr} @ {home_abbr}: away={away_score}, home={home_score}")
|
||||||
|
|
||||||
|
# If scores are None or missing, try to get from linescore
|
||||||
|
if away_score is None or home_score is None:
|
||||||
|
linescore = game.get('linescore', {})
|
||||||
|
if linescore:
|
||||||
|
teams_in_linescore = linescore.get('teams', {})
|
||||||
|
if away_score is None:
|
||||||
|
away_score = teams_in_linescore.get('away', {}).get('runs', 0)
|
||||||
|
self.logger.debug(f"Got away score from linescore: {away_score}")
|
||||||
|
if home_score is None:
|
||||||
|
home_score = teams_in_linescore.get('home', {}).get('runs', 0)
|
||||||
|
self.logger.debug(f"Got home score from linescore: {home_score}")
|
||||||
|
|
||||||
|
# Final fallback to 0 if still None
|
||||||
|
away_score = away_score if away_score is not None else 0
|
||||||
|
home_score = home_score if home_score is not None else 0
|
||||||
|
|
||||||
|
self.logger.debug(f"Final scores for {away_abbr} @ {home_abbr}: away={away_score}, home={home_score}")
|
||||||
|
|
||||||
game_data = {
|
game_data = {
|
||||||
'away_team': away_abbr,
|
'away_team': away_abbr,
|
||||||
'home_team': home_abbr,
|
'home_team': home_abbr,
|
||||||
'away_score': game['away']['score'],
|
'away_score': away_score,
|
||||||
'home_score': game['home']['score'],
|
'home_score': home_score,
|
||||||
'status': mapped_status,
|
'status': mapped_status,
|
||||||
'status_state': mapped_status_state,
|
'status_state': mapped_status_state,
|
||||||
'start_time': game['date'],
|
'start_time': game['date'],
|
||||||
@@ -539,9 +564,21 @@ class BaseMiLBManager:
|
|||||||
|
|
||||||
# Overwrite score and inning data with more accurate live data from the live feed
|
# Overwrite score and inning data with more accurate live data from the live feed
|
||||||
if linescore_live:
|
if linescore_live:
|
||||||
game_data['away_score'] = linescore_live.get('teams', {}).get('away', {}).get('runs', game_data['away_score'])
|
# Extract scores from live feed with fallback
|
||||||
game_data['home_score'] = linescore_live.get('teams', {}).get('home', {}).get('runs', game_data['home_score'])
|
away_runs = linescore_live.get('teams', {}).get('away', {}).get('runs')
|
||||||
game_data['inning'] = linescore_live.get('currentInning', game_data['inning'])
|
home_runs = linescore_live.get('teams', {}).get('home', {}).get('runs')
|
||||||
|
|
||||||
|
# Only update if we got valid scores from live feed
|
||||||
|
if away_runs is not None:
|
||||||
|
game_data['away_score'] = away_runs
|
||||||
|
if home_runs is not None:
|
||||||
|
game_data['home_score'] = home_runs
|
||||||
|
|
||||||
|
# Update inning info
|
||||||
|
current_inning = linescore_live.get('currentInning')
|
||||||
|
if current_inning is not None:
|
||||||
|
game_data['inning'] = current_inning
|
||||||
|
|
||||||
inning_state_live = linescore_live.get('inningState', '').lower()
|
inning_state_live = linescore_live.get('inningState', '').lower()
|
||||||
if inning_state_live:
|
if inning_state_live:
|
||||||
game_data['inning_half'] = 'bottom' if 'bottom' in inning_state_live else 'top'
|
game_data['inning_half'] = 'bottom' if 'bottom' in inning_state_live else 'top'
|
||||||
|
|||||||
174
test/debug_milb_api_structure.py
Normal file
174
test/debug_milb_api_structure.py
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Debug script to examine the exact structure of MiLB API responses
|
||||||
|
for the specific live game that's showing N/A scores.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
def debug_live_game_structure():
|
||||||
|
"""Debug the structure of a specific live game."""
|
||||||
|
print("Debugging MiLB API Structure")
|
||||||
|
print("=" * 60)
|
||||||
|
|
||||||
|
# Test the specific live game from the output
|
||||||
|
game_pk = 785631 # Tampa Tarpons @ Lakeland Flying Tigers
|
||||||
|
|
||||||
|
print(f"Examining game: {game_pk}")
|
||||||
|
|
||||||
|
# Test 1: Get the schedule data for this game
|
||||||
|
print(f"\n1. Testing schedule API for game {game_pk}")
|
||||||
|
print("-" * 40)
|
||||||
|
|
||||||
|
# Find which date this game is on
|
||||||
|
test_dates = [
|
||||||
|
datetime.now().strftime('%Y-%m-%d'),
|
||||||
|
(datetime.now() - timedelta(days=1)).strftime('%Y-%m-%d'),
|
||||||
|
(datetime.now() + timedelta(days=1)).strftime('%Y-%m-%d'),
|
||||||
|
]
|
||||||
|
|
||||||
|
for date in test_dates:
|
||||||
|
for sport_id in [10, 11, 12, 13, 14, 15]:
|
||||||
|
url = f"http://statsapi.mlb.com/api/v1/schedule?sportId={sport_id}&date={date}"
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = requests.get(url, timeout=10)
|
||||||
|
response.raise_for_status()
|
||||||
|
data = response.json()
|
||||||
|
|
||||||
|
if data.get('dates'):
|
||||||
|
for date_data in data['dates']:
|
||||||
|
games = date_data.get('games', [])
|
||||||
|
for game in games:
|
||||||
|
if game.get('gamePk') == game_pk:
|
||||||
|
print(f"✅ Found game {game_pk} in schedule API")
|
||||||
|
print(f" Date: {date}")
|
||||||
|
print(f" Sport ID: {sport_id}")
|
||||||
|
|
||||||
|
# Examine the game structure
|
||||||
|
print(f"\n Game structure:")
|
||||||
|
print(f" - gamePk: {game.get('gamePk')}")
|
||||||
|
print(f" - status: {game.get('status')}")
|
||||||
|
|
||||||
|
# Examine teams structure
|
||||||
|
teams = game.get('teams', {})
|
||||||
|
print(f" - teams structure: {list(teams.keys())}")
|
||||||
|
|
||||||
|
if 'away' in teams:
|
||||||
|
away = teams['away']
|
||||||
|
print(f" - away team: {away.get('team', {}).get('name')}")
|
||||||
|
print(f" - away score: {away.get('score')}")
|
||||||
|
print(f" - away structure: {list(away.keys())}")
|
||||||
|
|
||||||
|
if 'home' in teams:
|
||||||
|
home = teams['home']
|
||||||
|
print(f" - home team: {home.get('team', {}).get('name')}")
|
||||||
|
print(f" - home score: {home.get('score')}")
|
||||||
|
print(f" - home structure: {list(home.keys())}")
|
||||||
|
|
||||||
|
# Examine linescore
|
||||||
|
linescore = game.get('linescore', {})
|
||||||
|
if linescore:
|
||||||
|
print(f" - linescore structure: {list(linescore.keys())}")
|
||||||
|
print(f" - currentInning: {linescore.get('currentInning')}")
|
||||||
|
print(f" - inningState: {linescore.get('inningState')}")
|
||||||
|
print(f" - balls: {linescore.get('balls')}")
|
||||||
|
print(f" - strikes: {linescore.get('strikes')}")
|
||||||
|
print(f" - outs: {linescore.get('outs')}")
|
||||||
|
|
||||||
|
return game
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
continue
|
||||||
|
|
||||||
|
print(f"❌ Could not find game {game_pk} in schedule API")
|
||||||
|
return None
|
||||||
|
|
||||||
|
def debug_live_feed_structure(game_pk):
|
||||||
|
"""Debug the live feed API structure."""
|
||||||
|
print(f"\n2. Testing live feed API for game {game_pk}")
|
||||||
|
print("-" * 40)
|
||||||
|
|
||||||
|
url = f"http://statsapi.mlb.com/api/v1.1/game/{game_pk}/feed/live"
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = requests.get(url, timeout=10)
|
||||||
|
response.raise_for_status()
|
||||||
|
data = response.json()
|
||||||
|
|
||||||
|
print(f"✅ Live feed API response received")
|
||||||
|
print(f" Response keys: {list(data.keys())}")
|
||||||
|
|
||||||
|
live_data = data.get('liveData', {})
|
||||||
|
print(f" liveData keys: {list(live_data.keys())}")
|
||||||
|
|
||||||
|
linescore = live_data.get('linescore', {})
|
||||||
|
if linescore:
|
||||||
|
print(f" linescore keys: {list(linescore.keys())}")
|
||||||
|
print(f" - currentInning: {linescore.get('currentInning')}")
|
||||||
|
print(f" - inningState: {linescore.get('inningState')}")
|
||||||
|
print(f" - balls: {linescore.get('balls')}")
|
||||||
|
print(f" - strikes: {linescore.get('strikes')}")
|
||||||
|
print(f" - outs: {linescore.get('outs')}")
|
||||||
|
|
||||||
|
# Check teams in linescore
|
||||||
|
teams = linescore.get('teams', {})
|
||||||
|
if teams:
|
||||||
|
print(f" - teams in linescore: {list(teams.keys())}")
|
||||||
|
if 'away' in teams:
|
||||||
|
away = teams['away']
|
||||||
|
print(f" - away runs: {away.get('runs')}")
|
||||||
|
print(f" - away structure: {list(away.keys())}")
|
||||||
|
if 'home' in teams:
|
||||||
|
home = teams['home']
|
||||||
|
print(f" - home runs: {home.get('runs')}")
|
||||||
|
print(f" - home structure: {list(home.keys())}")
|
||||||
|
|
||||||
|
# Check gameData
|
||||||
|
game_data = live_data.get('gameData', {})
|
||||||
|
if game_data:
|
||||||
|
print(f" gameData keys: {list(game_data.keys())}")
|
||||||
|
|
||||||
|
# Check teams in gameData
|
||||||
|
teams = game_data.get('teams', {})
|
||||||
|
if teams:
|
||||||
|
print(f" - teams in gameData: {list(teams.keys())}")
|
||||||
|
if 'away' in teams:
|
||||||
|
away = teams['away']
|
||||||
|
print(f" - away name: {away.get('name')}")
|
||||||
|
print(f" - away structure: {list(away.keys())}")
|
||||||
|
if 'home' in teams:
|
||||||
|
home = teams['home']
|
||||||
|
print(f" - home name: {home.get('name')}")
|
||||||
|
print(f" - home structure: {list(home.keys())}")
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"❌ Error fetching live feed: {e}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Run the debug tests."""
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
|
# Debug the specific live game
|
||||||
|
game = debug_live_game_structure()
|
||||||
|
|
||||||
|
if game:
|
||||||
|
game_pk = game.get('gamePk')
|
||||||
|
debug_live_feed_structure(game_pk)
|
||||||
|
|
||||||
|
print(f"\n" + "=" * 60)
|
||||||
|
print("DEBUG SUMMARY")
|
||||||
|
print("=" * 60)
|
||||||
|
print("This debug script examines:")
|
||||||
|
print("✅ The exact structure of the schedule API response")
|
||||||
|
print("✅ The exact structure of the live feed API response")
|
||||||
|
print("✅ Where scores are stored in the API responses")
|
||||||
|
print("✅ How the MiLB manager should extract score data")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user