@@ -77,7 +77,7 @@ def schedule(
7777 params .update (
7878 {
7979 "sportId" : str (sportId ),
80- "hydrate" : "decisions,probablePitcher(note),linescore" ,
80+ "hydrate" : "decisions,probablePitcher(note),linescore,broadcasts,game(content(media(epg))) " ,
8181 }
8282 )
8383
@@ -121,7 +121,16 @@ def schedule(
121121 "inning_state" : game .get ("linescore" , {}).get ("inningState" , "" ),
122122 "venue_id" : game .get ("venue" , {}).get ("id" ),
123123 "venue_name" : game .get ("venue" , {}).get ("name" ),
124+ "national_broadcasts" : list (
125+ set (
126+ broadcast ["name" ]
127+ for broadcast in game .get ("broadcasts" , [])
128+ if broadcast .get ("isNational" , False )
129+ )
130+ ),
124131 }
132+ if game ["content" ].get ("media" , {}).get ("freeGame" , False ):
133+ game_info ["national_broadcasts" ].append ("MLB.tv Free Game" )
125134 if game_info ["status" ] in ["Final" , "Game Over" ]:
126135 if game .get ("isTie" ):
127136 game_info .update ({"winning_team" : "Tie" , "losing_Team" : "Tie" })
@@ -1111,11 +1120,19 @@ def player_stats(personId, group="[hitting,pitching,fielding]", type="season"):
11111120 return stats
11121121
11131122
1114- def player_stat_data (personId , group = "[hitting,pitching,fielding]" , type = "season" ):
1123+ def player_stat_data (
1124+ personId , group = "[hitting,pitching,fielding]" , type = "season" , sportId = 1
1125+ ):
11151126 """Returns a list of current season or career stat data for a given player."""
11161127 params = {
11171128 "personId" : personId ,
1118- "hydrate" : "stats(group=" + group + ",type=" + type + "),currentTeam" ,
1129+ "hydrate" : "stats(group="
1130+ + group
1131+ + ",type="
1132+ + type
1133+ + ",sportId="
1134+ + str (sportId )
1135+ + "),currentTeam" ,
11191136 }
11201137 r = get ("person" , params )
11211138
@@ -1150,14 +1167,37 @@ def player_stat_data(personId, group="[hitting,pitching,fielding]", type="season
11501167 return player
11511168
11521169
1153- def lookup_player (lookup_value , gameType = "R" , season = datetime .now ().year , sportId = 1 ):
1170+ def latest_season (sportId = 1 ):
1171+ """Get the latest season for a given sportId. Returns a dict containing seasonId and various dates."""
1172+ params = {
1173+ "sportId" : sportId ,
1174+ "seasonId" : "all" ,
1175+ }
1176+ all_seasons = get ("season" , params )
1177+
1178+ return all_seasons .get ("seasons" )[- 1 ]
1179+
1180+
1181+ def lookup_player (lookup_value , gameType = None , season = None , sportId = 1 ):
11541182 """Get data about players based on first, last, or full name."""
11551183 params = {
1156- "gameType" : gameType ,
1157- "season" : season ,
11581184 "sportId" : sportId ,
11591185 "fields" : "people,id,fullName,firstName,lastName,primaryNumber,currentTeam,id,primaryPosition,code,abbreviation,useName,boxscoreName,nickName,mlbDebutDate,nameFirstLast,firstLastName,lastFirstName,lastInitName,initLastName,fullFMLName,fullLFMName" ,
11601186 }
1187+ if gameType :
1188+ params .update (
1189+ {
1190+ "gameType" : gameType ,
1191+ }
1192+ )
1193+ if not season :
1194+ season_data = latest_season (sportId = sportId )
1195+ season = season_data .get ("seasonId" , datetime .now ().year )
1196+ params .update (
1197+ {
1198+ "season" : season ,
1199+ }
1200+ )
11611201 r = get ("sports_players" , params )
11621202
11631203 players = []
@@ -1170,14 +1210,21 @@ def lookup_player(lookup_value, gameType="R", season=datetime.now().year, sportI
11701210 return players
11711211
11721212
1173- def lookup_team (lookup_value , activeStatus = "Y" , season = datetime . now (). year , sportIds = 1 ):
1213+ def lookup_team (lookup_value , activeStatus = "Y" , season = None , sportIds = 1 ):
11741214 """Get a info about a team or teams based on the team name, city, abbreviation, or file code."""
11751215 params = {
11761216 "activeStatus" : activeStatus ,
1177- "season" : season ,
11781217 "sportIds" : sportIds ,
11791218 "fields" : "teams,id,name,teamCode,fileCode,teamName,locationName,shortName" ,
11801219 }
1220+ if not season :
1221+ season_data = latest_season (sportId = sportIds .split ("," )[0 ])
1222+ season = season_data .get ("seasonId" , datetime .now ().year )
1223+ params .update (
1224+ {
1225+ "season" : season ,
1226+ }
1227+ )
11811228 r = get ("teams" , params )
11821229
11831230 teams = []
0 commit comments