diff --git a/ff_espn_api/activity.py b/ff_espn_api/activity.py index 866b716f..439a6175 100644 --- a/ff_espn_api/activity.py +++ b/ff_espn_api/activity.py @@ -3,6 +3,7 @@ class Activity(object): def __init__(self, data, player_map, get_team_data): self.actions = [] # List of tuples (Team, action, player) + self.date = data['date'] for msg in data['messages']: team = '' action = 'UNKNOWN' diff --git a/ff_espn_api/constant.py b/ff_espn_api/constant.py index 184c8409..743bf729 100644 --- a/ff_espn_api/constant.py +++ b/ff_espn_api/constant.py @@ -71,10 +71,13 @@ } ACTIVITY_MAP = { - 178: 'ADDED', - 180: 'ADDED', + 178: 'FA ADDED', + 180: 'WAVIER ADDED', 179: 'DROPPED', 181: 'DROPPED', 239: 'DROPPED', - 244: 'TRADED' + 244: 'TRADED', + 'FA': 178, + 'WAVIER': 180, + 'TRADED': 244 } \ No newline at end of file diff --git a/ff_espn_api/league.py b/ff_espn_api/league.py index 0b3e808e..9810d5b8 100644 --- a/ff_espn_api/league.py +++ b/ff_espn_api/league.py @@ -14,7 +14,7 @@ from .player import Player from .activity import Activity from .utils import power_points, two_step_dominance -from .constant import POSITION_MAP +from .constant import POSITION_MAP, ACTIVITY_MAP def checkRequestStatus(status: int) -> None: @@ -303,14 +303,14 @@ def get_team_data(self, team_id: int) -> Team: return team return None - def recent_activity(self, size: int = 25, only_trades = False) -> List[Activity]: + def recent_activity(self, size: int = 25, only_trades = False, msg_type: str = None) -> List[Activity]: '''Returns a list of recent league activities (Add, Drop, Trade)''' if self.year < 2019: raise Exception('Cant use recent activity before 2019') msg_types = [178,180,179,239,181,244] - if only_trades: - msg_types = [244] + if msg_type in ACTIVITY_MAP: + msg_types = [ACTIVITY_MAP[msg_type]] params = { 'view': 'kona_league_communication' } diff --git a/ff_espn_api/matchup.py b/ff_espn_api/matchup.py index d87be02a..7fedbeb4 100644 --- a/ff_espn_api/matchup.py +++ b/ff_espn_api/matchup.py @@ -11,5 +11,10 @@ def _fetch_matchup_info(self): '''Fetch info for matchup''' self.home_team = self.data['home']['teamId'] self.home_score = self.data['home']['totalPoints'] - self.away_team = self.data['away']['teamId'] - self.away_score = self.data['away']['totalPoints'] + + # For Leagues with bye weeks + self.away_team = 0 + self.away_score = 0 + if 'away' in self.data: + self.away_team = self.data['away']['teamId'] + self.away_score = self.data['away']['totalPoints'] diff --git a/tests/unit/test_league.py b/tests/unit/test_league.py index 0a8f356b..d4244144 100644 --- a/tests/unit/test_league.py +++ b/tests/unit/test_league.py @@ -246,7 +246,7 @@ def test_recent_activity(self, m): activity = league.recent_activity() self.assertEqual(repr(activity[0].actions[0][0]), 'Team(Perscription Mixon)') - self.assertEqual(len(repr(activity)), 2255) + self.assertEqual(len(repr(activity)), 2369) @mock.patch.object(League, '_fetch_league') def test_cookie_set(self, mock_fetch_league):