From 6b6696cc89aa6a209c6e5ce5ac4cfcce6fa09e7a Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Wed, 3 Aug 2022 22:01:10 -0400 Subject: [PATCH 1/2] Add national broadcast data to schedule --- statsapi/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/statsapi/__init__.py b/statsapi/__init__.py index f79e6ec..8cbdcc9 100644 --- a/statsapi/__init__.py +++ b/statsapi/__init__.py @@ -77,7 +77,7 @@ def schedule( params.update( { "sportId": str(sportId), - "hydrate": "decisions,probablePitcher(note),linescore", + "hydrate": "decisions,probablePitcher(note),linescore,broadcasts", } ) @@ -121,6 +121,13 @@ def schedule( "inning_state": game.get("linescore", {}).get("inningState", ""), "venue_id": game.get("venue", {}).get("id"), "venue_name": game.get("venue", {}).get("name"), + "national_broadcasts": list( + set( + broadcast["name"] + for broadcast in game.get("broadcasts", []) + if broadcast.get("isNational", False) + ) + ), } if game_info["status"] in ["Final", "Game Over"]: if game.get("isTie"): From d543008b829711913604711b4ad95442aff1a721 Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Wed, 3 Aug 2022 22:58:53 -0400 Subject: [PATCH 2/2] Also pick up MLB.tv free games --- statsapi/__init__.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/statsapi/__init__.py b/statsapi/__init__.py index 8cbdcc9..cd809d9 100644 --- a/statsapi/__init__.py +++ b/statsapi/__init__.py @@ -77,7 +77,7 @@ def schedule( params.update( { "sportId": str(sportId), - "hydrate": "decisions,probablePitcher(note),linescore,broadcasts", + "hydrate": "decisions,probablePitcher(note),linescore,broadcasts,game(content(media(epg)))", } ) @@ -129,6 +129,8 @@ def schedule( ) ), } + if game["content"].get("media", {}).get("freeGame", False): + game_info["national_broadcasts"].append("MLB.tv Free Game") if game_info["status"] in ["Final", "Game Over"]: if game.get("isTie"): game_info.update({"winning_team": "Tie", "losing_Team": "Tie"}) @@ -1346,20 +1348,8 @@ def standings( for div in divisions.values(): standings += div["div_name"] + "\n" if include_wildcard: - standings += ( - "{:^4} {:<21} {:^3} {:^3} {:^4} {:^4} {:^7} {:^5} {:^4}\n".format( - *[ - "Rank", - "Team", - "W", - "L", - "GB", - "(E#)", - "WC Rank", - "WC GB", - "(E#)", - ] - ) + standings += "{:^4} {:<21} {:^3} {:^3} {:^4} {:^4} {:^7} {:^5} {:^4}\n".format( + *["Rank", "Team", "W", "L", "GB", "(E#)", "WC Rank", "WC GB", "(E#)",] ) for t in div["teams"]: standings += "{div_rank:^4} {name:<21} {w:^3} {l:^3} {gb:^4} {elim_num:^4} {wc_rank:^7} {wc_gb:^5} {wc_elim_num:^4}\n".format(