Skip to content
Open
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ sleeper-api-wrapper contributors

[scipio314](https://github.com/scipio314)
- Fixed KeyError in the get_team_score() method.

[Kofi Darfour](https://github.com/kodarfour)
- Added ties data to the data returned by the get_standings() method.
- Added ability to fetch players from the NBA in the get_all_players() method.
- Updated documentation
- get_standings()
- get_all_players()
- get_trending_players()
- Made consistent with updated Sleeper API documentation.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ Gets the standings in a league. Returns a list of the standings in order of most
Data returned looks like:

~~~
[(username, number_of_wins, number_of_losses, total_points), (username, number_of_wins, number_of_losses, total_points),...]
[(username, number_of_wins, number_of_losses, number_of_ties, total_points), (username, number_of_wins, number_of_losses, number_of_ties, total_points),...]
~~~
- types: username(str), number_of_wins(int), number_of_losses(int), total_points(int)
- types: username(str), number_of_wins(int), number_of_losses(int), number_of_ties(int), total_points(int)
- "username" could be None if a user does not have a username.

Example usage:
Expand Down Expand Up @@ -330,14 +330,16 @@ from sleeper_wrapper import Players
players = Players()
~~~
<a name="get_all_players"></a>
### Players.get_all_players()
Gets all of the players in fantasy football. Data returned looks like: https://docs.sleeper.app/#fetch-all-players
### Players.get_all_players(sport)
Gets all of the players in fantasy football or basketaball (Recommended to use once per day). Data returned looks like: https://docs.sleeper.app/#fetch-all-players

- sport: (str) The sport to get. Only "nfl" or "nba" right now.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming we add it, need lcs here to match line 342


<a name="get_trending_players"></a>
### Players.get_trending_players(sport, add_drop, hours, limit)
Gets all of the players in fantasy football. Data returned looks like: https://docs.sleeper.app/#trending-players

- sport: (str) The sport to get. Supports only "nfl" right now.
- sport: (str) The sport to get. Supports all sports (nfl, nba, lcs, etc...).
- add_drop: (str) Either "add" or "drop".
- hours: (int or str) Number of hours to look back. Default is 24 hours.
- limit: (int or str) Number of results you want. Default is 25.
Expand Down
7 changes: 4 additions & 3 deletions sleeper_wrapper/league.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,18 @@ def get_standings(self, rosters, users):
points = roster["settings"]["fpts"]
name = roster["owner_id"]
losses = roster["settings"]["losses"]
ties = roster["settings"]["ties"]
if name is not None:
roster_tuple = (wins, losses, points, users_dict[name])
roster_tuple = (wins, losses, ties, points, users_dict[name])
else:
roster_tuple = (wins, losses, points, None)
roster_tuple = (wins, losses, ties, points, None)
roster_standings_list.append(roster_tuple)

roster_standings_list.sort(reverse = 1)

clean_standings_list = []
for item in roster_standings_list:
clean_standings_list.append((item[3], str(item[0]), str(item[1]), str(item[2])))
clean_standings_list.append((item[4], str(item[0]), str(item[1]), str(item[2]), str(item[3])))

return clean_standings_list

Expand Down
7 changes: 5 additions & 2 deletions sleeper_wrapper/players.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ class Players(BaseApi):
def __init__(self):
pass

def get_all_players(self):
return self._call("https://api.sleeper.app/v1/players/nfl")
def get_all_players(self, sport):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should probably have sport="nfl" as the default argument since this would change functionality for people and I assume most users are using the package for NFL data and not NBA or LCS.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dtsong meant to tag you here. Any thoughts on adding support for these other sports?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that the Sleeper API has those support, enabling that in the wrapper would be a good idea since the scope of this wrapper is primarily around the Sleeper API itself.

if sport == "nfl":
return self._call("https://api.sleeper.app/v1/players/nfl")
if sport == "nba":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this should be elif sport == "nba" and then there should be an else statement with some sort of logging to let the user know if they provided a sport argument that is not supported by the API. I did double check and this call does return NBA players. lcs is also supported, so if we're gonna add one, then we should probably add both.

return self._call("https://api.sleeper.app/v1/players/nba")

def get_trending_players(self,sport, add_drop, hours=24, limit=25 ):
return self._call("https://api.sleeper.app/v1/players/{}/trending/{}?lookback_hours={}&limit={}".format(sport, add_drop, hours, limit))