@@ -1167,14 +1167,37 @@ def player_stat_data(
1167
1167
return player
1168
1168
1169
1169
1170
- 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 ):
1171
1182
"""Get data about players based on first, last, or full name."""
1172
1183
params = {
1173
- "gameType" : gameType ,
1174
- "season" : season ,
1175
1184
"sportId" : sportId ,
1176
1185
"fields" : "people,id,fullName,firstName,lastName,primaryNumber,currentTeam,id,primaryPosition,code,abbreviation,useName,boxscoreName,nickName,mlbDebutDate,nameFirstLast,firstLastName,lastFirstName,lastInitName,initLastName,fullFMLName,fullLFMName" ,
1177
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
+ )
1178
1201
r = get ("sports_players" , params )
1179
1202
1180
1203
players = []
@@ -1187,14 +1210,21 @@ def lookup_player(lookup_value, gameType="R", season=datetime.now().year, sportI
1187
1210
return players
1188
1211
1189
1212
1190
- 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 ):
1191
1214
"""Get a info about a team or teams based on the team name, city, abbreviation, or file code."""
1192
1215
params = {
1193
1216
"activeStatus" : activeStatus ,
1194
- "season" : season ,
1195
1217
"sportIds" : sportIds ,
1196
1218
"fields" : "teams,id,name,teamCode,fileCode,teamName,locationName,shortName" ,
1197
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
+ )
1198
1228
r = get ("teams" , params )
1199
1229
1200
1230
teams = []
0 commit comments