@@ -658,20 +658,54 @@ def league_leaders(leaderCategories,leagueId=None,season=None):
658
658
659
659
return "This function is not yet available."
660
660
661
- def standings (leagueId = None ,season = None ,standingsTypes = None ):
662
- """Get standings for a given league and season
661
+ def standings (leagueId = None ,season = None ,standingsTypes = None ,date = None ):
662
+ """Get standings for a given league and season.
663
+
664
+ Format for date = 'MM/DD/YYYY', e.g. '04/24/2019'
663
665
"""
664
666
if not leagueId : leagueId = '103,104'
665
- if not season : season = datetime .now ().year
667
+ params = {'leagueId' :leagueId }
668
+ if date : params .update ({'date' :date })
669
+ if not season :
670
+ if date :
671
+ season = date [- 4 :]
672
+ else :
673
+ season = datetime .now ().year
666
674
if not standingsTypes : standingsTypes = 'regularSeason'
667
- params = { 'leagueId' : leagueId , 'season' : season }
675
+ params . update ({ 'season' : season , 'standingsTypes' : standingsTypes })
668
676
if leagueId : params .update ({'leagueId' :leagueId })
677
+ params .update ({'hydrate' :'team(division)' ,'fields' :'records,standingsType,teamRecords,team,name,division,id,nameShort,abbreviation,divisionRank,gamesBack,wildCardRank,wildCardGamesBack,wildCardEliminationNumber,divisionGamesBack,clinched,eliminationNumber,winningPercentage,type,wins,losses' })
669
678
670
679
r = get ('standings' ,params )
671
680
672
-
673
-
674
- return "This function is not yet available."
681
+ standings = ''
682
+ divisions = {}
683
+
684
+ for y in r ['records' ]:
685
+ for x in y ['teamRecords' ]:
686
+ if x ['team' ]['division' ]['id' ] not in divisions .keys ():
687
+ divisions .update ({x ['team' ]['division' ]['id' ]:{'div_name' :x ['team' ]['division' ]['name' ],'teams' :[]}})
688
+ team = {
689
+ 'name' : x ['team' ]['name' ],
690
+ 'div_rank' : x ['divisionRank' ],
691
+ 'w' : x ['wins' ],
692
+ 'l' : x ['losses' ],
693
+ 'gb' : x ['gamesBack' ],
694
+ 'wc_rank' : x .get ('wildCardRank' ,'-' ),
695
+ 'wc_gb' : x .get ('wildCardGamesBack' ,'-' ),
696
+ 'wc_elim_num' : x .get ('wildCardEliminationNumber' ,'-' ),
697
+ 'elim_num' : x ['eliminationNumber' ]
698
+ }
699
+ divisions [x ['team' ]['division' ]['id' ]]['teams' ].append (team )
700
+
701
+ for div_id ,div in divisions .items ():
702
+ standings += div ['div_name' ] + '\n '
703
+ standings += '{:^4} {:<21} {:^3} {:^3} {:^4} {:^4} {:^7} {:^5} {:^4}\n ' .format (* ['Rank' ,'Team' ,'W' ,'L' ,'GB' ,'(E#)' ,'WC Rank' ,'WC GB' ,'(E#)' ])
704
+ for t in div ['teams' ]:
705
+ standings += '{div_rank:^4} {name:<21} {w:^3} {l:^3} {gb:^4} {elim_num:^4} {wc_rank:^7} {wc_gb:^5} {wc_elim_num:^4}\n ' .format (** t )
706
+ standings += '\n '
707
+
708
+ return standings
675
709
676
710
def roster (teamId ,rosterType = None ,season = None ,date = None ):
677
711
"""Get the roster for a given team.
0 commit comments