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

Initial Baseball Implementation #195

Open
cwendt94 opened this issue Apr 4, 2021 · 9 comments
Open

Initial Baseball Implementation #195

cwendt94 opened this issue Apr 4, 2021 · 9 comments

Comments

@cwendt94
Copy link
Owner

cwendt94 commented Apr 4, 2021

No description provided.

@ProgrammerMatt
Copy link

Looking to possibly use this!

@tomrulz
Copy link

tomrulz commented Apr 7, 2021

league = League(league_id=333670215, year=2021, debug=True)
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\Tom\Anaconda3\lib\site-packages\espn_api\baseball\league.py", line 22, in init
self._fetch_teams(data)
File "C:\Users\Tom\Anaconda3\lib\site-packages\espn_api\baseball\league.py", line 31, in _fetch_teams
super()._fetch_teams(data, TeamClass=Team)
File "C:\Users\Tom\Anaconda3\lib\site-packages\espn_api\base_league.py", line 65, in _fetch_teams
self.teams.append(TeamClass(team, roster=roster, member=member, schedule=schedule, year=seasonId))
File "C:\Users\Tom\Anaconda3\lib\site-packages\espn_api\baseball\team.py", line 26, in init
self.stats = {STATS_MAP[i]: j for i, j in data['valuesByStat'].items()}
File "C:\Users\Tom\Anaconda3\lib\site-packages\espn_api\baseball\team.py", line 26, in
self.stats = {STATS_MAP[i]: j for i, j in data['valuesByStat'].items()}
KeyError: '0'

@tomrulz
Copy link

tomrulz commented Apr 7, 2021

Hello. When trying to initialize the league I get a keyerror 0. I searched through some previous issues, didn't see anything similar. Any advice? Thank you in advance.

I have tried to use the API with your test league from the implementation ticket and I got it to work! But when I try my league info I the KeyError.

@cwendt94
Copy link
Owner Author

cwendt94 commented Apr 7, 2021

@tomrulz thanks for reporting this! I found the issue, the team object was trying to map stats which has not been added yet for baseball.

Package version v0.14.1 has the fix!

@tomrulz
Copy link

tomrulz commented Apr 7, 2021

you the man!

@LastBastion1005
Copy link

Is there still going to be baseball implementation eventually? Very interested!

@cwendt94
Copy link
Owner Author

There is already some basic baseball features implemented that you can use for one of your old leagues. The wiki still needs to be updated but you can check out the available functions in the code here. Initialization is like the other leagues

from espn_api.baseball import League
league = League(league_id: int, year: int, espn_s2: str = None, swid: str = None, username: str = None, password: str = None, debug=False)

Some of the available features are recent_activity , free_agents, box_scores, and able to access teams and rosters by the league object league.teams[0].roster

@ChandlerCGray
Copy link

Hey @cwendt94 . I've really been enjoying playing around with the baseball side!

However, I did find a strange bug in league.free_agents in that position will oftentimes be wrong, especially for pitchers.

from espn_api.baseball import League

league = League(league_id=1234, year=2024, espn_s2='<redacted>', swid='<redacted>')

# Gather free agent pitchers
free_agents = league.free_agents(position_id=14, size=1)
print("\nFree Agents")
for free_agent in free_agents:
    print(f"Name: {free_agent.name}, Eligible Positions: {free_agent.eligibleSlots}, Position: {free_agent.position}, Team: {free_agent.proTeam}, PlayerId {free_agent.playerId}")
    print(f"Name: {free_agent.name}, Eligible Positions: {free_agent.eligibleSlots}, Position: {free_agent.eligibleSlots[0]}, Team: {free_agent.proTeam}, PlayerId {free_agent.playerId}")

Output:

Free Agents
Name: Nestor Cortes, Eligible Positions: ['P', 'SP', 'BE', 'IL'], Position: C, Team: NYY, PlayerId 36480
Name: Nestor Cortes, Eligible Positions: ['P', 'SP', 'BE', 'IL'], Position: P, Team: NYY, PlayerId 36480

As you can see, I was able to work around this using {free_agent.eligibleSlots[0]}.

Side note: Any chance we will get the docs soon? I'd love to dive a little deeper.

@cwendt94
Copy link
Owner Author

cwendt94 commented Apr 8, 2024

I just looked into it and it seems like for pitchers ESPN sets their default position id to 1 in the data they are returning, which in the position maps to 1B https://github.com/cwendt94/espn-api/blob/master/espn_api/baseball/constant.py#L3. Thats not a eligible position. Not sure exactly why they are returning that.

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

No branches or pull requests

5 participants