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

Made power rankings get current week by default and week parameter optional #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions espnff/league.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ def _fetch_teams(self, data):
def _fetch_settings(self, data):
self.settings = Settings(data)

def power_rankings(self, week):
def power_rankings(self, week=None):
'''Return power rankings for any week'''

if week is None:
week = self.get_current_week()
# calculate win for every week
win_matrix = []
teams_sorted = sorted(self.teams, key=lambda x: x.team_id,
Expand All @@ -98,6 +99,30 @@ def power_rankings(self, week):
power_rank = power_points(dominance_matrix, teams_sorted, week)
return power_rank

def get_current_week(self):
'''Return current week'''
params = {
'leagueId': self.league_id,
'seasonId': self.year
}

r = requests.get('%sscoreboard' % (self.ENDPOINT, ), params=params)
self.status = r.status_code
data = r.json()

if self.status == 401:
raise PrivateLeagueException(data['error'][0]['message'])

elif self.status == 404:
raise InvalidLeagueException(data['error'][0]['message'])

elif self.status != 200:
raise UnknownLeagueException('Unknown %s Error' % self.status)

week = data['scoreboard']['scoringPeriodId']

return week

def scoreboard(self, week=None):
'''Returns list of matchups for a given week'''
params = {
Expand Down