diff --git a/statsapi/__init__.py b/statsapi/__init__.py index 0ce66d8..7ddc31b 100644 --- a/statsapi/__init__.py +++ b/statsapi/__init__.py @@ -74,10 +74,20 @@ def schedule( if game_id: params.update({"gamePks": game_id}) + hydrate = ( + "decisions,probablePitcher(note),linescore,broadcasts,game(content(media(epg)))" + ) + if date == "2014-03-11" or (str(start_date) <= "2014-03-11" <= str(end_date)): + # For some reason the seriesStatus hydration throws a server error on 2014-03-11 only (checked back to 2000) + logger.warning( + "Excluding seriesStatus hydration because the MLB API throws an error for 2014-03-11 which is included in the requested date range." + ) + else: + hydrate += ",seriesStatus" params.update( { "sportId": str(sportId), - "hydrate": "decisions,probablePitcher(note),linescore,broadcasts,game(content(media(epg)))", + "hydrate": hydrate, } ) @@ -95,8 +105,8 @@ def schedule( "game_date": date["date"], "game_type": game["gameType"], "status": game["status"]["detailedState"], - "away_name": game["teams"]["away"]["team"]["name"], - "home_name": game["teams"]["home"]["team"]["name"], + "away_name": game["teams"]["away"]["team"].get("name", "???"), + "home_name": game["teams"]["home"]["team"].get("name", "???"), "away_id": game["teams"]["away"]["team"]["id"], "home_id": game["teams"]["home"]["team"]["id"], "doubleheader": game["doubleHeader"], @@ -128,6 +138,7 @@ def schedule( if broadcast.get("isNational", False) ) ), + "series_status": game.get("seriesStatus", {}).get("result"), } if game["content"].get("media", {}).get("freeGame", False): game_info["national_broadcasts"].append("MLB.tv Free Game") @@ -137,12 +148,16 @@ def schedule( else: game_info.update( { - "winning_team": game["teams"]["away"]["team"]["name"] + "winning_team": game["teams"]["away"]["team"].get( + "name", "???" + ) if game["teams"]["away"].get("isWinner") - else game["teams"]["home"]["team"]["name"], - "losing_team": game["teams"]["home"]["team"]["name"] + else game["teams"]["home"]["team"].get("name", "???"), + "losing_team": game["teams"]["home"]["team"].get( + "name", "???" + ) if game["teams"]["away"].get("isWinner") - else game["teams"]["away"]["team"]["name"], + else game["teams"]["away"]["team"].get("name", "???"), "winning_pitcher": game.get("decisions", {}) .get("winner", {}) .get("fullName", ""), @@ -157,13 +172,13 @@ def schedule( summary = ( date["date"] + " - " - + game["teams"]["away"]["team"]["name"] + + game["teams"]["away"]["team"].get("name", "???") + " (" - + str(game["teams"]["away"]["score"]) + + str(game["teams"]["away"].get("score", "")) + ") @ " - + game["teams"]["home"]["team"]["name"] + + game["teams"]["home"]["team"].get("name", "???") + " (" - + str(game["teams"]["home"]["score"]) + + str(game["teams"]["home"].get("score", "")) + ") (" + game["status"]["detailedState"] + ")" @@ -176,11 +191,11 @@ def schedule( + " - " + game["teams"]["away"]["team"]["name"] + " (" - + str(game["teams"]["away"]["score"]) + + str(game["teams"]["away"].get("score", "0")) + ") @ " + game["teams"]["home"]["team"]["name"] + " (" - + str(game["teams"]["home"]["score"]) + + str(game["teams"]["home"].get("score", "0")) + ") (" + game["linescore"]["inningState"] + " of the " diff --git a/statsapi/version.py b/statsapi/version.py index 6be5123..f5c56a6 100644 --- a/statsapi/version.py +++ b/statsapi/version.py @@ -1,3 +1,3 @@ #!/usr/bin/env python -VERSION = "1.5.1" +VERSION = "1.6"