Skip to content

Commit

Permalink
examples
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyagreco committed Sep 21, 2024
1 parent c9cba63 commit e02bc77
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
9 changes: 4 additions & 5 deletions example/draft_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
get_traded_draft_picks,
get_user_drafts_for_year,
)
from sleeper.enum import Sport

if __name__ == "__main__":
# get all drafts that a user was in for a particular year
user_drafts = get_user_drafts_for_year(
user_id="my_user_id", sport=Sport.NFL, year=2020
)
user_drafts = get_user_drafts_for_year(user_id="my_user_id", sport="nfl", year=2020)

# get all drafts for a particular league
league_drafts = get_drafts_in_league(league_id="my_league_id")
Expand All @@ -20,7 +17,9 @@
draft = get_draft(draft_id="my_draft_id")

# get all draft picks for a particular draft
draft_picks = get_player_draft_picks(draft_id="my_draft_id", sport=Sport.NFL)
draft_picks = get_player_draft_picks(
draft_id="my_draft_id",
)

# get all traded draft picks for a particular draft
traded_draft_picks = get_traded_draft_picks(draft_id="my_draft_id")
18 changes: 14 additions & 4 deletions example/league_example.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
from sleeper.api.league import get_league, get_rosters, get_user_leagues_for_year
from sleeper.enum import Sport
from sleeper.api.league import (
get_league,
get_losers_bracket,
get_matchups_for_week,
get_rosters,
get_sport_state,
get_traded_picks,
get_transactions,
get_user_leagues_for_year,
get_users_in_league,
get_winners_bracket,
)

if __name__ == "__main__":
# get a league by its ID
league = get_league(league_id="my_league_id")

# get all leagues for a user by its ID in a particular year
user_leagues = get_user_leagues_for_year(
user_id="my_user_id", sport=Sport.NFL, year="2020"
user_id="my_user_id", sport="nfl", year=2020
)

# get all rosters in a particular league
Expand All @@ -32,4 +42,4 @@
traded_picks = get_traded_picks(league_id="my_league_id")

# get the state of a particular sport
nfl_state = get_sport_state(sport=Sport.NFL)
nfl_state = get_sport_state(sport="nfl")
18 changes: 6 additions & 12 deletions example/player_example.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
from sleeper.api import PlayerAPIClient
from sleeper.enum import Sport, TrendType
from sleeper.model import Player, PlayerTrend
from sleeper.api.player import get_all_players, get_trending_players

if __name__ == "__main__":
# get all players in a particular sport
nfl_players: dict[str, Player] = PlayerAPIClient.get_all_players(sport=Sport.NFL)
nfl_players = get_all_players(sport="nfl")

# get all trending players that were added for a particular sport
nfl_added_trending_players: list[PlayerTrend] = (
PlayerAPIClient.get_trending_players(sport=Sport.NFL, trend_type=TrendType.ADD)
)
# get players that are trending up in the nfl
nfl_trending_up_players = get_trending_players(sport="nfl", trend_type="add")

# get all trending players that were dropped for a particular sport
nfl_dropped_trending_players: list[PlayerTrend] = (
PlayerAPIClient.get_trending_players(sport=Sport.NFL, trend_type=TrendType.DROP)
)
# get players that are trending down in the nfl
nfl_trending_down_players = get_trending_players(sport="nfl", trend_type="drop")
7 changes: 3 additions & 4 deletions example/user_example.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from sleeper.api import UserAPIClient
from sleeper.model import User
from sleeper.api.user import get_user

if __name__ == "__main__":
# get a user by username
user_1: User = UserAPIClient.get_user(username="my_username")
user_1 = get_user(identifier="my_username")

# get a user by ID
user_2: User = UserAPIClient.get_user(user_id="my_user_id")
user_2 = get_user(identifier="my_user_id")

0 comments on commit e02bc77

Please sign in to comment.