@@ -77,7 +77,7 @@ def schedule(
77
77
params .update (
78
78
{
79
79
"sportId" : str (sportId ),
80
- "hydrate" : "decisions,probablePitcher(note),linescore" ,
80
+ "hydrate" : "decisions,probablePitcher(note),linescore,broadcasts,game(content(media(epg))) " ,
81
81
}
82
82
)
83
83
@@ -121,7 +121,16 @@ def schedule(
121
121
"inning_state" : game .get ("linescore" , {}).get ("inningState" , "" ),
122
122
"venue_id" : game .get ("venue" , {}).get ("id" ),
123
123
"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
+ ),
124
131
}
132
+ if game ["content" ].get ("media" , {}).get ("freeGame" , False ):
133
+ game_info ["national_broadcasts" ].append ("MLB.tv Free Game" )
125
134
if game_info ["status" ] in ["Final" , "Game Over" ]:
126
135
if game .get ("isTie" ):
127
136
game_info .update ({"winning_team" : "Tie" , "losing_Team" : "Tie" })
@@ -1111,11 +1120,19 @@ def player_stats(personId, group="[hitting,pitching,fielding]", type="season"):
1111
1120
return stats
1112
1121
1113
1122
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
+ ):
1115
1126
"""Returns a list of current season or career stat data for a given player."""
1116
1127
params = {
1117
1128
"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" ,
1119
1136
}
1120
1137
r = get ("person" , params )
1121
1138
@@ -1150,14 +1167,37 @@ def player_stat_data(personId, group="[hitting,pitching,fielding]", type="season
1150
1167
return player
1151
1168
1152
1169
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 ):
1154
1182
"""Get data about players based on first, last, or full name."""
1155
1183
params = {
1156
- "gameType" : gameType ,
1157
- "season" : season ,
1158
1184
"sportId" : sportId ,
1159
1185
"fields" : "people,id,fullName,firstName,lastName,primaryNumber,currentTeam,id,primaryPosition,code,abbreviation,useName,boxscoreName,nickName,mlbDebutDate,nameFirstLast,firstLastName,lastFirstName,lastInitName,initLastName,fullFMLName,fullLFMName" ,
1160
1186
}
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
+ )
1161
1201
r = get ("sports_players" , params )
1162
1202
1163
1203
players = []
@@ -1170,14 +1210,21 @@ def lookup_player(lookup_value, gameType="R", season=datetime.now().year, sportI
1170
1210
return players
1171
1211
1172
1212
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 ):
1174
1214
"""Get a info about a team or teams based on the team name, city, abbreviation, or file code."""
1175
1215
params = {
1176
1216
"activeStatus" : activeStatus ,
1177
- "season" : season ,
1178
1217
"sportIds" : sportIds ,
1179
1218
"fields" : "teams,id,name,teamCode,fileCode,teamName,locationName,shortName" ,
1180
1219
}
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
+ )
1181
1228
r = get ("teams" , params )
1182
1229
1183
1230
teams = []
0 commit comments