-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ef333e
commit 506b68e
Showing
7 changed files
with
48 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,35 @@ | ||
from sleeper.api import LeagueAPIClient | ||
from sleeper.api.league import get_league, get_rosters, get_user_leagues_for_year | ||
from sleeper.enum import Sport | ||
from sleeper.model import ( | ||
League, | ||
Matchup, | ||
PlayoffMatchup, | ||
Roster, | ||
SportState, | ||
TradedPick, | ||
Transaction, | ||
User, | ||
) | ||
|
||
if __name__ == "__main__": | ||
# get a league by its ID | ||
league: League = LeagueAPIClient.get_league(league_id="my_league_id") | ||
league = get_league(league_id="my_league_id") | ||
|
||
# get all leagues for a user by its ID in a particular year | ||
user_leagues: list[League] = LeagueAPIClient.get_user_leagues_for_year( | ||
user_leagues = get_user_leagues_for_year( | ||
user_id="my_user_id", sport=Sport.NFL, year="2020" | ||
) | ||
|
||
# get all rosters in a particular league | ||
league_rosters: list[Roster] = LeagueAPIClient.get_rosters(league_id="my_league_id") | ||
league_rosters = get_rosters(league_id="my_league_id") | ||
|
||
# get all users in a particular league | ||
league_users: list[User] = LeagueAPIClient.get_users_in_league( | ||
league_id="my_league_id" | ||
) | ||
league_users = get_users_in_league(league_id="my_league_id") | ||
|
||
# get all matchups in a week for a particular league | ||
week_1_matchups: list[Matchup] = LeagueAPIClient.get_matchups_for_week( | ||
league_id="my_league_id", week=1 | ||
) | ||
week_1_matchups = get_matchups_for_week(league_id="my_league_id", week=1) | ||
|
||
# get the winners bracket for a particular league | ||
winners_bracket: list[PlayoffMatchup] = LeagueAPIClient.get_winners_bracket( | ||
league_id="my_league_id" | ||
) | ||
winners_bracket = get_winners_bracket(league_id="my_league_id") | ||
|
||
# get the losers bracket for a particular league | ||
losers_bracket: list[PlayoffMatchup] = LeagueAPIClient.get_losers_bracket( | ||
league_id="my_league_id" | ||
) | ||
losers_bracket = get_losers_bracket(league_id="my_league_id") | ||
|
||
# get all transactions in a week for a particular league | ||
week_1_transactions: list[Transaction] = LeagueAPIClient.get_transactions( | ||
league_id="my_league_id", week=1 | ||
) | ||
week_1_transactions = get_transactions(league_id="my_league_id", week=1) | ||
|
||
# get all traded picks for a particular league | ||
traded_picks: list[TradedPick] = LeagueAPIClient.get_traded_picks( | ||
league_id="my_league_id" | ||
) | ||
traded_picks = get_traded_picks(league_id="my_league_id") | ||
|
||
# get the state of a particular sport | ||
nfl_state: SportState = LeagueAPIClient.get_sport_state(sport=Sport.NFL) | ||
nfl_state = get_sport_state(sport=Sport.NFL) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,27 @@ | ||
from sleeper.api.constants import ( | ||
LEAGUE_ROUTE, | ||
LEAGUES_ROUTE, | ||
SLEEPER_APP_BASE_URL, | ||
USER_ROUTE, | ||
VERSION, | ||
) | ||
from sleeper.api.util import build_route, get | ||
from sleeper.enum import Sport | ||
|
||
|
||
def get_league(*, league_id: str) -> dict: | ||
url = build_route(SLEEPER_APP_BASE_URL, VERSION, LEAGUE_ROUTE, league_id) | ||
return get(url) | ||
|
||
|
||
def get_user_leagues_for_year(*, user_id: str, sport: Sport, year: int) -> list[dict]: | ||
url = build_route( | ||
SLEEPER_APP_BASE_URL, | ||
VERSION, | ||
USER_ROUTE, | ||
user_id, | ||
LEAGUES_ROUTE, | ||
sport.value.lower(), | ||
year, | ||
) | ||
return get(url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters