Skip to content

Commit b67ef0a

Browse files
committed
enh: latest_season should ret current season #127
1 parent 7adced4 commit b67ef0a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

statsapi/__init__.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,8 +1195,20 @@ def latest_season(sportId=1):
11951195
"seasonId": "all",
11961196
}
11971197
all_seasons = get("season", params)
1198-
1199-
return all_seasons.get("seasons")[-1]
1198+
return next(
1199+
(
1200+
x
1201+
for x in all_seasons.get("seasons", [])
1202+
if x.get("seasonStartDate")
1203+
and x.get("seasonEndDate")
1204+
and (
1205+
x["seasonStartDate"]
1206+
< datetime.today().strftime("%Y-%m-%d")
1207+
< x["seasonEndDate"]
1208+
)
1209+
),
1210+
all_seasons["seasons"][-1],
1211+
)
12001212

12011213

12021214
def lookup_player(lookup_value, gameType=None, season=None, sportId=1):

0 commit comments

Comments
 (0)