Skip to content

Commit

Permalink
Merge pull request #121 from cwendt94/PlayerInfoBug
Browse files Browse the repository at this point in the history
Player Info Bug Temp Fix
  • Loading branch information
cwendt94 authored Sep 19, 2020
2 parents edae9d8 + 780b203 commit ea5038d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 3 additions & 1 deletion espn_api/base_league.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def _fetch_players(self):
for player in data:
# two way map to find playerId's by name
self.player_map[player['id']] = player['fullName']
self.player_map[player['fullName']] = player['id']
# if two players have the same fullname use first one for now
if player['fullName'] not in self.player_map:
self.player_map[player['fullName']] = player['id']

def _get_pro_schedule(self, scoringPeriodId: int = None):
data = self.espn_request.get_pro_schedule()
Expand Down
11 changes: 6 additions & 5 deletions espn_api/football/league.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,18 +259,19 @@ def free_agents(self, week: int=None, size: int=50, position: str=None) -> List[

return [BoxPlayer(player, pro_schedule, positional_rankings, week) for player in players]

def player_info(self, name: str):
def player_info(self, name: str = None, playerId: int = None):
''' Returns Player class if name found '''
playerId = self.player_map.get(name)

if playerId is None:
if name:
playerId = self.player_map.get(name)
if playerId is None or isinstance(playerId, str):
return None
params = { 'view': 'kona_playercard' }
filters = {'players':{'filterIds':{'value':[playerId]}, 'filterStatsForTopScoringPeriodIds':{'value':16}}}
headers = {'x-fantasy-filter': json.dumps(filters)}

data = self.espn_request.league_get(params=params, headers=headers)

player = data['players'][0]
return Player(player)
if len(data['players']) > 0:
return Player(data['players'][0])

0 comments on commit ea5038d

Please sign in to comment.