Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stats endpoint supports startDate and endDate parameters #148

Closed
vile319 opened this issue Oct 28, 2024 · 4 comments
Closed

Stats endpoint supports startDate and endDate parameters #148

vile319 opened this issue Oct 28, 2024 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@vile319
Copy link

vile319 commented Oct 28, 2024

Hi Todd,
.get does not properly apply startDate and endDate. It only does, for example, https://statsapi.mlb.com/api/v1/stats?group=hitting&season=2024&stats=byDateRange

where it should instead be doing:
https://statsapi.mlb.com/api/v1/stats?group=hitting&season=2024&stats=byDateRange&startDate=07/03/2024&endDate=07/10/2024

Let me know if you need more clarification.

Thanks!
Vile
image

@toddrob99
Copy link
Owner

toddrob99 commented Oct 28, 2024

@vile319 try enabling logging similar to this:

import logging
import statsapi
logger = logging.getLogger('statsapi')
logger.setLevel(logging.DEBUG)
rootLogger = logging.getLogger()
rootLogger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
formatter = logging.Formatter("%(asctime)s - %(levelname)8s - %(name)s(%(thread)s) - %(message)s")
ch.setFormatter(formatter)
rootLogger.addHandler(ch)

Then try again and see if it logs that it's ignoring those parameters. That's most likely what's happening, because I don't see startDate or endDate in the parameters for the stats endpoint.

If those parameters are valid, I can add them to the endpoint definition. In the meantime, you can use the force parameter to make the get command include the parameters that it thinks are extraneous/unsupported. For example: statsapi.get("stats", {"group": "hitting", "season":2024, "stats":"byDateRange", "startDate":"07/03/2024", "endDate":"07/10/2024"}, force=True).

@toddrob99 toddrob99 self-assigned this Oct 28, 2024
@vile319
Copy link
Author

vile319 commented Oct 28, 2024

@toddrob99 Hi Todd,
Thanks for the quick reply.

Without force:
image
It is indeed ignoring the parameters.

With force:
stats=statsapi.get('stats', {'group':'hitting', 'season':2024, 'stats':'byDateRange', 'startDate':'07/01/2024', 'endDate': '07/05/2024'}, force=True)

2024-10-27 21:01:04,948 - DEBUG - statsapi(24960) - URL: https://statsapi.mlb.com/api/{ver}/stats
2024-10-27 21:01:04,949 - DEBUG - statsapi(24960) - Found query param: group
2024-10-27 21:01:04,950 - DEBUG - statsapi(24960) - Found query param: season
2024-10-27 21:01:04,951 - DEBUG - statsapi(24960) - Found query param: stats
2024-10-27 21:01:04,951 - DEBUG - statsapi(24960) - Found invalid param, forcing into query parameters per force flag: startDate
2024-10-27 21:01:04,952 - DEBUG - statsapi(24960) - Found invalid param, forcing into query parameters per force flag: endDate
2024-10-27 21:01:04,952 - DEBUG - statsapi(24960) - path_params: {}
2024-10-27 21:01:04,953 - DEBUG - statsapi(24960) - query_params: {'group': 'hitting', 'season': '2024', 'stats': 'byDateRange', 'startDate': '07/01/2024', 'endDate': '07/05/2024'}
2024-10-27 21:01:04,954 - DEBUG - statsapi(24960) - Replacing {ver} with default: v1.
2024-10-27 21:01:04,954 - DEBUG - statsapi(24960) - URL: https://statsapi.mlb.com/api/v1/stats
2024-10-27 21:01:04,955 - DEBUG - statsapi(24960) - Adding query parameter group=hitting
2024-10-27 21:01:04,955 - DEBUG - statsapi(24960) - URL: https://statsapi.mlb.com/api/v1/stats?group=hitting
2024-10-27 21:01:04,956 - DEBUG - statsapi(24960) - Adding query parameter season=2024
2024-10-27 21:01:04,957 - DEBUG - statsapi(24960) - URL: https://statsapi.mlb.com/api/v1/stats?group=hitting&season=2024
2024-10-27 21:01:04,957 - DEBUG - statsapi(24960) - Adding query parameter stats=byDateRange
2024-10-27 21:01:04,958 - DEBUG - statsapi(24960) - URL: https://statsapi.mlb.com/api/v1/stats?group=hitting&season=2024&stats=byDateRange
2024-10-27 21:01:04,959 - DEBUG - statsapi(24960) - Adding query parameter startDate=07/01/2024
2024-10-27 21:01:04,959 - DEBUG - statsapi(24960) - URL: https://statsapi.mlb.com/api/v1/stats?group=hitting&season=2024&stats=byDateRange&startDate=07/01/2024
2024-10-27 21:01:04,961 - DEBUG - statsapi(24960) - Adding query parameter endDate=07/05/2024
2024-10-27 21:01:04,962 - DEBUG - statsapi(24960) - URL: https://statsapi.mlb.com/api/v1/stats?group=hitting&season=2024&stats=byDateRange&startDate=07/01/2024&endDate=07/05/2024
2024-10-27 21:01:04,963 - DEBUG - urllib3.connectionpool(24960) - Starting new HTTPS connection (1): statsapi.mlb.com:443
2024-10-27 21:01:05,721 - DEBUG - urllib3.connectionpool(24960) - https://statsapi.mlb.com:443 "GET /api/v1/stats?group=hitting&season=2024&stats=byDateRange&startDate=07/01/2024&endDate=07/05/2024 HTTP/1.1" 200 None

It does appear to be a valid parameter. Looks like force clears it up, so no worries there. Thanks Todd!

Thanks again,
Vile

@vile319
Copy link
Author

vile319 commented Oct 28, 2024

On the topic of the update for the parameters, it does appear to be valid.
For example, using 07/03/2024 to 07/04/2024 as the start date to the end date returns:
image
And using 07/03/2024 to 07/05/2024 as the start date to the end date returns:
image

@toddrob99 toddrob99 changed the title .get does not work for: statsapi.get('stats', {'group':'hitting', 'season':2024, 'startDate':'07/01/2019', 'endDate': '07/31/2019', 'stats':'byDateRange'}) Stats endpoint supports startDate and endDate parameters Nov 1, 2024
@toddrob99 toddrob99 added the enhancement New feature or request label Nov 1, 2024
@toddrob99
Copy link
Owner

Fixing in v1.8.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants