diff --git a/espn_api/base_league.py b/espn_api/base_league.py index 9cebb842..d6934993 100644 --- a/espn_api/base_league.py +++ b/espn_api/base_league.py @@ -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() diff --git a/espn_api/football/league.py b/espn_api/football/league.py index 1272ce30..5d128f07 100644 --- a/espn_api/football/league.py +++ b/espn_api/football/league.py @@ -259,11 +259,12 @@ 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}}} @@ -271,6 +272,6 @@ def player_info(self, name: str): 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])