diff --git a/statsapi/__init__.py b/statsapi/__init__.py index 01725ab..8a74478 100644 --- a/statsapi/__init__.py +++ b/statsapi/__init__.py @@ -1195,8 +1195,20 @@ def latest_season(sportId=1): "seasonId": "all", } all_seasons = get("season", params) - - return all_seasons.get("seasons")[-1] + return next( + ( + x + for x in all_seasons.get("seasons", []) + if x.get("seasonStartDate") + and x.get("seasonEndDate") + and ( + x["seasonStartDate"] + < datetime.today().strftime("%Y-%m-%d") + < x["seasonEndDate"] + ) + ), + all_seasons["seasons"][-1], + ) def lookup_player(lookup_value, gameType=None, season=None, sportId=1): @@ -1679,7 +1691,10 @@ def get(endpoint, params, force=False): % (param, ep["path_params"][param]["default"]) ) url = url.replace( - "{" + param + "}", ep["path_params"][param]["default"] + "{" + param + "}", + ("/" if ep["path_params"][param]["leading_slash"] else "") + + ep["path_params"][param]["default"] + + ("/" if ep["path_params"][param]["trailing_slash"] else ""), ) else: if force: diff --git a/statsapi/endpoints.py b/statsapi/endpoints.py index 45c741c..a994ef7 100644 --- a/statsapi/endpoints.py +++ b/statsapi/endpoints.py @@ -106,10 +106,10 @@ }, "year": { "type": "str", - "default": "2019", # TODO: current year or most recent draft year + "default": "", "leading_slash": True, "trailing_slash": False, - "required": True, + "required": False, }, "latest": { "type": "bool", diff --git a/statsapi/version.py b/statsapi/version.py index 2559ca2..8aadcb9 100644 --- a/statsapi/version.py +++ b/statsapi/version.py @@ -1,3 +1,3 @@ #!/usr/bin/env python -VERSION = "1.6.2" +VERSION = "1.7"