Skip to content

Commit

Permalink
Merge pull request #74 from cwendt94/FixByeScoreBoardImproveRecent
Browse files Browse the repository at this point in the history
Fixes scoreboard away. Add filter and date to recent activity
  • Loading branch information
cwendt94 authored Oct 31, 2019
2 parents 5e7cf8b + b2ac638 commit d578496
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions ff_espn_api/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
9 changes: 6 additions & 3 deletions ff_espn_api/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 4 additions & 4 deletions ff_espn_api/league.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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'
}
Expand Down
9 changes: 7 additions & 2 deletions ff_espn_api/matchup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
2 changes: 1 addition & 1 deletion tests/unit/test_league.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit d578496

Please sign in to comment.