Skip to content

Commit

Permalink
Version 2 (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyagreco authored Sep 21, 2024
1 parent 51ed448 commit d1da81c
Show file tree
Hide file tree
Showing 130 changed files with 2,970 additions and 6,273 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ jobs:
run: |
python -m pip install --upgrade pip
make deps
- name: Run unit tests
- name: Run tests
run: |
make test
make test-all
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ target/
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
Expand Down Expand Up @@ -130,4 +127,8 @@ dmypy.json

# all files with "_dnm." in them like foo_dnm.py (dnm = do not merge)
*_dnm.*
*_dnc.*

.DS_Store


1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10.14
19 changes: 4 additions & 15 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

- Removed all custom modeling
- Removed all enums
- All functions are available via import from `sleeper.api`
- Replaced kwargs with optional, named keyword arguments
- Updated package requirements

## [1.7.3]

Expand Down Expand Up @@ -73,33 +77,18 @@ All notable changes to this project will be documented in this file.
### Initial Release

[Unreleased]: https://github.com/joeyagreco/sleeper/compare/v1.7.3...HEAD

[1.7.3]: https://github.com/joeyagreco/sleeper/releases/tag/v1.7.3

[1.7.2]: https://github.com/joeyagreco/sleeper/releases/tag/v1.7.2

[1.7.1]: https://github.com/joeyagreco/sleeper/releases/tag/v1.7.1

[1.7.0]: https://github.com/joeyagreco/sleeper/releases/tag/v1.7.0

[1.6.0]: https://github.com/joeyagreco/sleeper/releases/tag/v1.6.0

[1.5.0]: https://github.com/joeyagreco/sleeper/releases/tag/v1.5.0

[1.4.0]: https://github.com/joeyagreco/sleeper/releases/tag/v1.4.0

[1.3.4]: https://github.com/joeyagreco/sleeper/releases/tag/v1.3.4

[1.3.3]: https://github.com/joeyagreco/sleeper/releases/tag/v1.3.3

[1.3.1]: https://github.com/joeyagreco/sleeper/releases/tag/v1.3.1

[1.3.0]: https://github.com/joeyagreco/sleeper/releases/tag/v1.3.0

[1.2.0]: https://github.com/joeyagreco/sleeper/releases/tag/v1.2.0

[1.1.1]: https://github.com/joeyagreco/sleeper/releases/tag/v1.1.1

[1.0.1]: https://github.com/joeyagreco/sleeper/releases/tag/v1.0.1

[1.0.0]: https://github.com/joeyagreco/sleeper/releases/tag/v1.0.0
3 changes: 1 addition & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
include sleeper/app.properties
include requirements.txt
include requirements.txt
43 changes: 24 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
PYTEST_ARGS=

.PHONY: deps
deps:
@python3 -m pip install -r requirements.dev.txt
@python3 -m pip install -r requirements.txt
@python -m pip install -r requirements.dev.txt
@python -m pip install -r requirements.txt

.PHONY: fmt
fmt:
@black --config=pyproject.toml .
@autoflake --config=pyproject.toml .
@isort .
@ruff check --fix
@ruff format

.PHONY: fmt-check
fmt-check:
@black --config=pyproject.toml --check .
@autoflake --config=pyproject.toml --check .
@isort --check-only .
@ruff check
@ruff format --check

.PHONY: test-all
test-all:
@make test-unit $(PYTEST_ARGS)
@make test-integration $(PYTEST_ARGS)

.PHONY: test
test:
@pytest test/
.PHONY: test-unit
test-unit:
@pytest test/unit $(PYTEST_ARGS)

.PHONY: up-reqs
up-reqs:
@pipreqs --force --mode no-pin
.PHONY: test-integration
test-integration:
@pytest test/integration $(PYTEST_ARGS)

.PHONY: pkg-build
pkg-build:
@rm -rf build
@rm -rf dist
@python3 setup.py sdist bdist_wheel
@python setup.py sdist bdist_wheel

.PHONY: pkg-test
pkg-test:
@python3 -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*
pkg-test: pkg-build
@python -m twine upload --repository testpypi dist/*

.PHONY: pkg-prod
pkg-prod:
@python3 -m twine upload dist/*
pkg-prod: pkg-build
@python -m twine upload dist/*
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">

<img src="https://github.com/joeyagreco/sleeper/raw/main/img/sleeper_logo_alt.png" alt="sleeper logo" width="250"/>
<img src="https://github.com/joeyagreco/sleeper/raw/main/img/sleeper.png" alt="sleeper logo" width="250"/>

A Python wrapper for the Sleeper API.

Expand Down
20 changes: 13 additions & 7 deletions example/avatar_example.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
from sleeper.api import AvatarAPIClient
from sleeper.api import get_avatar

if __name__ == "__main__":
# get avatar by ID and save locally
AvatarAPIClient.get_avatar(
avatar_id="my_avatar_id", save_to_path="C:\\Desktop\\avatar\\my_avatar.png"
)
# get avatar by ID
avatar_bytes = get_avatar(avatar_id="my_avatar_id")

# save locally
with open(
"my_avatar.png",
"wb",
) as file:
file.write(avatar_bytes)

# can pass in the "thumbnail" parameter to get a smaller-sized avatar
AvatarAPIClient.get_avatar(
avatar_id="my_avatar_id", save_to_path="C:\\Desktop\\avatar\\my_avatar.png", thumbnail=True
get_avatar(
avatar_id="my_avatar_id",
as_thumbnail=True,
)
34 changes: 17 additions & 17 deletions example/draft_example.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
from sleeper.api import DraftAPIClient
from sleeper.enum import Sport
from sleeper.model import Draft, DraftPick, PlayerDraftPick
from sleeper.api import (
get_draft,
get_drafts_in_league,
get_player_draft_picks,
get_traded_draft_picks,
get_user_drafts_for_year,
)

if __name__ == "__main__":
# get all drafts that a user was in for a particular year
user_drafts: list[Draft] = DraftAPIClient.get_user_drafts_for_year(
user_id="my_user_id", sport=Sport.NFL, year="2020"
)
# get all drafts that a user was in for a year
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: list[Draft] = DraftAPIClient.get_drafts_in_league(league_id="my_league_id")
# get all drafts for a league
league_drafts = get_drafts_in_league(league_id="my_league_id")

# get a draft by its ID
draft: Draft = DraftAPIClient.get_draft(draft_id="my_draft_id")
draft = get_draft(draft_id="my_draft_id")

# get all draft picks for a particular draft
draft_picks: list[PlayerDraftPick] = DraftAPIClient.get_player_draft_picks(
draft_id="my_draft_id", sport=Sport.NFL
# get all draft picks for a draft
draft_picks = get_player_draft_picks(
draft_id="my_draft_id",
)

# get all traded draft picks for a particular draft
traded_draft_picks: list[DraftPick] = DraftAPIClient.get_traded_draft_picks(
draft_id="my_draft_id"
)
# get all traded draft picks for a draft
traded_draft_picks = get_traded_draft_picks(draft_id="my_draft_id")
70 changes: 31 additions & 39 deletions example/league_example.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,45 @@
from sleeper.api import LeagueAPIClient
from sleeper.enum import Sport
from sleeper.model import (
League,
Matchup,
PlayoffMatchup,
Roster,
SportState,
TradedPick,
Transaction,
User,
from sleeper.api 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: 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_id="my_user_id", sport=Sport.NFL, year="2020"
# get all leagues for a user by its ID in a year
user_leagues = get_user_leagues_for_year(
user_id="my_user_id", sport="nfl", year=2023
)

# get all rosters in a particular league
league_rosters: list[Roster] = LeagueAPIClient.get_rosters(league_id="my_league_id")
# get all rosters in a league
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")
# get all users in a league
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
)
# get all matchups in a week for a league
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"
)
# get the winners bracket for a league
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"
)
# get the losers bracket for a league
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
)
# get all transactions in a week for a league
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")
# get all traded picks for a league
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)
# get the state of a sport
nfl_state = get_sport_state(sport="nfl")
20 changes: 7 additions & 13 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 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)
# get all players in a sport
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 a sport
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 a sport
nfl_trending_down_players = get_trending_players(sport="nfl", trend_type="drop")
51 changes: 0 additions & 51 deletions example/unofficial/player_example.py

This file was deleted.

9 changes: 0 additions & 9 deletions example/unofficial/sport_example.py

This file was deleted.

Loading

0 comments on commit d1da81c

Please sign in to comment.