Skip to content

Commit

Permalink
Merge pull request #97 from toddrob99/develop
Browse files Browse the repository at this point in the history
v1.6
  • Loading branch information
toddrob99 authored Nov 12, 2022
2 parents e0612f0 + dc7a94c commit ecf58c8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
41 changes: 28 additions & 13 deletions statsapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
)

Expand All @@ -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"],
Expand Down Expand Up @@ -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")
Expand All @@ -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", ""),
Expand All @@ -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"]
+ ")"
Expand All @@ -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 "
Expand Down
2 changes: 1 addition & 1 deletion statsapi/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env python

VERSION = "1.5.1"
VERSION = "1.6"

0 comments on commit ecf58c8

Please sign in to comment.