Skip to content

Commit

Permalink
Updated Fields and Added Formatting (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyagreco authored May 22, 2023
1 parent fec0c3d commit 5188254
Show file tree
Hide file tree
Showing 71 changed files with 1,293 additions and 1,101 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/formatting-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Formatting Check

on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
inputs:
manual:
description: "Trigger the workflow manually"
required: false

jobs:
format:
name: Check code formatting
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.10"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install black==23.3.0
- name: Check Formatting
run: |
black --config pyproject.toml --check --diff .
- name: Install autoflake
run: pip install autoflake==2.1.1

- name: Check for Unused Imports
run: autoflake --config pyproject.toml --check .
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

- N/A
- Added more fields to response objects

## [1.5.0]

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ Pull requests are welcome. For major changes, please open an issue first to disc

Please make sure to update tests as appropriate.

## Development

_Run these commands from the root folder_
- Format Code: `./main fmt`
- Run Unit Tests: `./main test`
- Generate Coverage Report: `./main cov`

## License

[MIT](https://choosealicense.com/licenses/mit/)
7 changes: 7 additions & 0 deletions batch/coverage.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@echo off

cd test
coverage run -m pytest
coverage xml -o coverage.xml
coverage html
cd ..
4 changes: 4 additions & 0 deletions batch/format.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@echo off

black --config=pyproject.toml .
autoflake --config=pyproject.toml .
4 changes: 4 additions & 0 deletions batch/test.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@echo off

cd test
pytest
9 changes: 6 additions & 3 deletions example/avatar_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

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")
AvatarAPIClient.get_avatar(
avatar_id="my_avatar_id", save_to_path="C:\\Desktop\\avatar\\my_avatar.png"
)

# 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)
AvatarAPIClient.get_avatar(
avatar_id="my_avatar_id", save_to_path="C:\\Desktop\\avatar\\my_avatar.png", thumbnail=True
)
13 changes: 9 additions & 4 deletions example/draft_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

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")
user_drafts: list[Draft] = DraftAPIClient.get_user_drafts_for_year(
user_id="my_user_id", sport=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")
Expand All @@ -16,7 +17,11 @@
draft: Draft = DraftAPIClient.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)
draft_picks: list[PlayerDraftPick] = DraftAPIClient.get_player_draft_picks(
draft_id="my_draft_id", sport=Sport.NFL
)

# get all traded draft picks for a particular draft
traded_draft_picks: list[DraftPick] = DraftAPIClient.get_traded_draft_picks(draft_id="my_draft_id")
traded_draft_picks: list[DraftPick] = DraftAPIClient.get_traded_draft_picks(
draft_id="my_draft_id"
)
32 changes: 25 additions & 7 deletions example/league_example.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
from sleeper.api import LeagueAPIClient
from sleeper.enum import Sport
from sleeper.model import League, Roster, User, Matchup, PlayoffMatchup, Transaction, TradedPick, SportState
from sleeper.model import (
League,
Roster,
User,
Matchup,
PlayoffMatchup,
Transaction,
TradedPick,
SportState,
)

if __name__ == "__main__":
# get a league by its ID
league: League = LeagueAPIClient.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")
user_leagues: list[League] = LeagueAPIClient.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")
Expand All @@ -17,16 +27,24 @@
league_users: list[User] = LeagueAPIClient.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: list[Matchup] = LeagueAPIClient.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: list[PlayoffMatchup] = LeagueAPIClient.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: list[PlayoffMatchup] = LeagueAPIClient.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: list[Transaction] = LeagueAPIClient.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")
Expand Down
10 changes: 6 additions & 4 deletions example/player_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
nfl_players: dict[str, Player] = PlayerAPIClient.get_all_players(sport=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)
nfl_added_trending_players: list[PlayerTrend] = PlayerAPIClient.get_trending_players(
sport=Sport.NFL, trend_type=TrendType.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)
nfl_dropped_trending_players: list[PlayerTrend] = PlayerAPIClient.get_trending_players(
sport=Sport.NFL, trend_type=TrendType.DROP
)
61 changes: 27 additions & 34 deletions example/unofficial/player_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,47 @@

if __name__ == "__main__":
# get player stats for a player for a particular sport, week, and season
player_stats_week: PlayerStats = UPlayerAPIClient.get_player_stats(sport=Sport.NFL,
player_id="1234",
season="2020",
week=1)
player_stats_week: PlayerStats = UPlayerAPIClient.get_player_stats(
sport=Sport.NFL, player_id="1234", season="2020", week=1
)

# get player stats for a player for the entire season in a particular sport and season
player_stats_season: PlayerStats = UPlayerAPIClient.get_player_stats(sport=Sport.NFL,
player_id="1234",
season="2020")
player_stats_season: PlayerStats = UPlayerAPIClient.get_player_stats(
sport=Sport.NFL, player_id="1234", season="2020"
)

# get player projections for a player for a particular sport, week, and season
player_projections_week: PlayerStats = UPlayerAPIClient.get_player_projections(sport=Sport.NFL,
player_id="1234",
season="2020",
week=1)
player_projections_week: PlayerStats = UPlayerAPIClient.get_player_projections(
sport=Sport.NFL, player_id="1234", season="2020", week=1
)

# get player projections for a player for the entire season in a particular sport and season
player_projections_season: PlayerStats = UPlayerAPIClient.get_player_projections(sport=Sport.NFL,
player_id="1234",
season="2020")
player_projections_season: PlayerStats = UPlayerAPIClient.get_player_projections(
sport=Sport.NFL, player_id="1234", season="2020"
)

# get all player stats for a particular sport, season, and week
all_player_stats: list[PlayerStats] = UPlayerAPIClient.get_all_player_stats(sport=Sport.NFL,
season="2020",
week=1)
all_player_stats: list[PlayerStats] = UPlayerAPIClient.get_all_player_stats(
sport=Sport.NFL, season="2020", week=1
)

# get all player stats for QBs and RBs for a particular sport, season, and week
all_player_stats_qbs_rbs: list[PlayerStats] = UPlayerAPIClient.get_all_player_stats(sport=Sport.NFL,
season="2020",
week=1,
positions=[NFLPosition.QB,
NFLPosition.RB])
all_player_stats_qbs_rbs: list[PlayerStats] = UPlayerAPIClient.get_all_player_stats(
sport=Sport.NFL, season="2020", week=1, positions=[NFLPosition.QB, NFLPosition.RB]
)

# get all player projections for a particular sport, season, and week
all_player_projections: list[PlayerStats] = UPlayerAPIClient.get_all_player_projections(sport=Sport.NFL,
season="2020",
week=1)
all_player_projections: list[PlayerStats] = UPlayerAPIClient.get_all_player_projections(
sport=Sport.NFL, season="2020", week=1
)

# get all player projections for QBs and RBs for a particular sport, season, and week
all_player_projections_qbs_rbs: list[PlayerStats] = UPlayerAPIClient.get_all_player_projections(sport=Sport.NFL,
season="2020",
week=1,
positions=[
NFLPosition.QB,
NFLPosition.RB])
all_player_projections_qbs_rbs: list[PlayerStats] = UPlayerAPIClient.get_all_player_projections(
sport=Sport.NFL, season="2020", week=1, positions=[NFLPosition.QB, NFLPosition.RB]
)

# get a player's headshot and save locally
# the file path should save to a file that has the extension '.png'
UPlayerAPIClient.get_player_head_shot(sport=Sport.NFL,
player_id="1234",
save_to_path="C:\\Desktop\\avatar\\my_headshot.png")
UPlayerAPIClient.get_player_head_shot(
sport=Sport.NFL, player_id="1234", save_to_path="C:\\Desktop\\avatar\\my_headshot.png"
)
4 changes: 3 additions & 1 deletion example/unofficial/sport_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

if __name__ == "__main__":
# get regular season schedule for a particular sport and season
regular_season: list[Game] = USportAPIClient.get_regular_season_schedule(sport=Sport.NFL, season="2020")
regular_season: list[Game] = USportAPIClient.get_regular_season_schedule(
sport=Sport.NFL, season="2020"
)
11 changes: 11 additions & 0 deletions main.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@echo off

IF "%1"=="fmt" (
call batch\format.bat
) ELSE IF "%1" == "test" (
call batch\test.bat
) ELSE IF "%1"=="cov" (
call batch\coverage.bat
) ELSE (
echo Invalid flag. Please specify a valid flag.
)
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[tool.black]
line-length = 100
skip-magic-trailing-comma = true
include = '\.py$'

[autoflake]
ignore_init_module_imports = true
in_place = true
recursive = true
remove_all_unused_imports = true
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
packages=setuptools.find_packages(exclude=("test", "docs")),
install_requires=required_packages,
python_requires=f">={minimum_python_version_required}",
keywords="nfl football sleeper sleeper-api sleeper-fantasy-football fantasy-football wrapper wrapper-api"
keywords="nfl football sleeper sleeper-api sleeper-fantasy-football fantasy-football wrapper wrapper-api",
)
6 changes: 3 additions & 3 deletions sleeper/api/AvatarAPIClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@


class AvatarAPIClient(SleeperAPIClient):

@classmethod
def get_avatar(cls, *, avatar_id: str, save_to_path: str, **kwargs) -> None:
thumbnail = kwargs.pop("thumbnail", False)
if thumbnail:
url = cls._build_route(cls._SLEEPER_CDN_BASE_URL, None, cls._AVATARS_ROUTE, cls._THUMBS_ROUTE,
avatar_id)
url = cls._build_route(
cls._SLEEPER_CDN_BASE_URL, None, cls._AVATARS_ROUTE, cls._THUMBS_ROUTE, avatar_id
)
else:
url = cls._build_route(cls._SLEEPER_CDN_BASE_URL, None, cls._AVATARS_ROUTE, avatar_id)
image_file = cls._get_image_file(url)
Expand Down
Loading

0 comments on commit 5188254

Please sign in to comment.