toddrob99 / MLB-StatsAPI

Python wrapper for MLB Stats API
GNU General Public License v3.0
513 stars 98 forks source link

Add support for leagueId so we can retrieve data from other leagues #132

Closed BrayanMnz closed 7 months ago

BrayanMnz commented 7 months ago

Add support for leagueId so we can retrieve data from leagues different to MLB.

In the list of http://statsapi.mlb.com/api/v1/sports we have all the winter leagues under the same sportId (17), I am looking to use the leagueId parameter so that I can retrieve for example just the data for the Dominican Winter League using leagueId=131

eg:

winter_leagues_schedule = statsapi.schedule(date="2023-12-18", sportId=17)

for i in winter_leagues_schedule:
    print(i["summary"])

output

2023-12-18 - Estrellas Orientales @ Toros del Este (Scheduled)
2023-12-18 - Estrellas Occidente @ Estrellas Oriente (Scheduled)

two games from two different Winter Leagues would be great to add the granularity of filtering by league :smile:

BrayanMnz commented 7 months ago

FYI @toddrob99

BrayanMnz commented 7 months ago

Hi, @toddrob99 could you merge this?

toddrob99 commented 7 months ago

@BrayanMnz, can you give me an example of how you are looking to use this? The sportId parameter is already there, and that's the one that lets you retrieve the schedule outside MLB (for example, AAA):

> aaa_schedule = statsapi.schedule(date="2024-05-01", sportId=11)
> print(aaa_schedule[-1]["summary"])

2024-05-01 - Reno Aces @ Las Vegas Aviators (Scheduled)

The leagueId parameter would allow you to filter the results to one league within the given sport (for example, only retrieve American League schedule for sportId=1/MLB), but the current functionality does allow retrieving data for any league as far as I can tell.

BrayanMnz commented 7 months ago

Hi, @toddrob99 in the list of http://statsapi.mlb.com/api/v1/sports we have all the winter leagues under the same sportId (17), I am looking to use the leagueId parameter so that I can retrieve for example just the data for the Dominican Winter League using leagueId=131

eg:

winter_leagues_schedule = statsapi.schedule(date="2023-12-18", sportId=17)

for i in winter_leagues_schedule:
    print(i["summary"])

output

2023-12-18 - Estrellas Orientales @ Toros del Este (Scheduled)
2023-12-18 - Estrellas Occidente @ Estrellas Oriente (Scheduled)

two games from two different Winter Leagues would be great to add the granularity of filtering by league :smile:

Looking forward to continuing to contribute to this amazing work you have done, let me know how to help you and if there is any roadmap defined.

toddrob99 commented 7 months ago

Included in v1.7.1