Skip to content

Commit

Permalink
avatar func
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyagreco committed Sep 9, 2024
1 parent 4831747 commit 950580e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions sleeper/api/avatar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from sleeper.api.constants import AVATARS_ROUTE, SLEEPER_CDN_BASE_URL, THUMBS_ROUTE
from sleeper.api.util import build_route, get_content


def get_avatar(*, avatar_id: str, as_thumbnail: bool = False) -> bytes:
if as_thumbnail:
url = build_route(
SLEEPER_CDN_BASE_URL,
None,
AVATARS_ROUTE,
THUMBS_ROUTE,
avatar_id,
)
else:
url = build_route(SLEEPER_CDN_BASE_URL, None, AVATARS_ROUTE, avatar_id)

return get_content(url)
6 changes: 6 additions & 0 deletions sleeper/api/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ def get(url: str) -> Optional[dict | list]:
return response.json()


def get_content(url: str) -> bytes:
response = requests.get(url)
response.raise_for_status()
return response.content


def add_filters(url: str, *args: list[tuple[str, any]]) -> str:
"""
Adds filters to the given url.
Expand Down

0 comments on commit 950580e

Please sign in to comment.