Skip to content

Commit

Permalink
style: Format code with isort and autopep8
Browse files Browse the repository at this point in the history
  • Loading branch information
deepsource-autofix[bot] committed Jun 11, 2023
1 parent 293653c commit a76d5c8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 26 deletions.
9 changes: 6 additions & 3 deletions classes/simkl.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ def __init__(self, client_id: str = SIMKL_CLIENT_ID):

async def __aenter__(self):
"""Enter the async context manager"""
self.session = aiohttp.ClientSession(headers={"User-Agent": USER_AGENT})
self.session = aiohttp.ClientSession(
headers={"User-Agent": USER_AGENT})
return self

async def __aexit__(self, exc_type, exc_val, exc_tb) -> None:
Expand Down Expand Up @@ -356,7 +357,8 @@ async def search_by_title(
params["extended"] = "full"
params["page"] = page
params["limit"] = limit
media_type = media_type.value if isinstance(media_type, Enum) else media_type
media_type = media_type.value if isinstance(
media_type, Enum) else media_type
async with self.session.get(
f"{self.base_url}/search/{media_type}", params=params
) as response:
Expand Down Expand Up @@ -544,7 +546,8 @@ async def get_title_ids(
"""
if isinstance(media_type, SimklMediaTypes):
media_type = media_type.value
cache_file_path = self.get_cache_file_path(f"ids/{media_type}/{media_id}.json")
cache_file_path = self.get_cache_file_path(
f"ids/{media_type}/{media_id}.json")
cached_data = self.read_cached_data(cache_file_path)
if cached_data is not None:
cached_data = SimklRelations(
Expand Down
28 changes: 20 additions & 8 deletions extensions/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from modules.const import EMOJI_UNEXPECTED_ERROR


class ExtenalSitesRelations(ipy.Extension):
"""Extension class for /relations"""

Expand Down Expand Up @@ -45,7 +46,9 @@ async def search_simkl_id(
media_type (Simkl.TmdbMediaTypes | None, optional): The media type if it's TMDB. Defaults to None.
"""
async with Simkl() as simkl:
entry: list[dict] | None = await simkl.search_by_id(provider, media_id, media_type=media_type)
entry: list[dict] | None = await simkl.search_by_id(
provider, media_id, media_type=media_type
)
if not entry:
raise SimklTypeError(
"Could not find any entry with the given ID",
Expand Down Expand Up @@ -332,7 +335,13 @@ async def relations_shows(
platform=AnimeApi.AnimeApiPlatforms(platform),
)

if platform not in ["simkl", "trakt", "tmdb", "tvdb", "imdb",]:
if platform not in [
"simkl",
"trakt",
"tmdb",
"tvdb",
"imdb",
]:
pfm = (
anime_api.myanimelist
if anime_api.myanimelist
Expand Down Expand Up @@ -396,9 +405,7 @@ async def relations_shows(
)
trakt_type = trakt_data.type
trakt_data = (
trakt_data.show
if trakt_data.type == "show"
else trakt_data.movie
trakt_data.show if trakt_data.type == "show" else trakt_data.movie
)
trakt_id = trakt_data.ids.trakt
except ProviderHttpError as eht:
Expand Down Expand Up @@ -428,7 +435,9 @@ async def relations_shows(
is_slug = True
elif simkl_dat.tvdb is not None or trakt_data.ids.tvdb is not None:
if simkl_dat.tvdb is not None:
tvdb_id = f"https://www.thetvdb.com/deferrer/{tvtyp}/{simkl_dat.tvdb}"
tvdb_id = (
f"https://www.thetvdb.com/deferrer/{tvtyp}/{simkl_dat.tvdb}"
)
elif trakt_data.ids.tvdb is not None:
tvdb_id = f"https://www.thetvdb.com/deferrer/{tvtyp}/{trakt_data.ids.tvdb}"
if tmdb_id is not None:
Expand All @@ -439,7 +448,9 @@ async def relations_shows(
is_slug = True
elif simkl_dat.tvdb is not None or trakt_data.ids.tvdb is not None:
if simkl_dat.tvdb is not None:
tvdb_id = f"https://www.thetvdb.com/deferrer/{tvtyp}/{simkl_dat.tvdb}"
tvdb_id = (
f"https://www.thetvdb.com/deferrer/{tvtyp}/{simkl_dat.tvdb}"
)
elif trakt_data.ids.tvdb is not None:
tvdb_id = f"https://www.thetvdb.com/deferrer/{tvtyp}/{trakt_data.ids.tvdb}"
if tmdb_id is not None:
Expand Down Expand Up @@ -534,7 +545,8 @@ async def relations_shows(
color=0xFF0000,
timestamp=datetime.utcnow(),
)
emoji_error = re.search(r"\<(a?)\:(\w+)\:(\d+)\>", EMOJI_UNEXPECTED_ERROR)
emoji_error = re.search(
r"\<(a?)\:(\w+)\:(\d+)\>", EMOJI_UNEXPECTED_ERROR)
if emoji_error:
emoji_error = emoji_error.group(2)
dcEm.set_thumbnail(
Expand Down
3 changes: 2 additions & 1 deletion modules/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ async def generate_discord_profile_embed(
else:
nick = sanitize_markdown(data.username)
nick += " (" + lp["commons"]["default"] + ")"
joined = datetime.strptime(servData["joined_at"], "%Y-%m-%dT%H:%M:%S.%f%z")
joined = datetime.strptime(
servData["joined_at"], "%Y-%m-%dT%H:%M:%S.%f%z")
joined = int(joined.timestamp())
joined = f"<t:{joined}:R>"
if servData["premium_since"]: # type: ignore
Expand Down
29 changes: 15 additions & 14 deletions modules/platforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,7 @@ def media_id_to_platform(
raise ValueError(f"Invalid platform: {platform}")


def platforms_to_fields(
currPlatform: str,
**k: str | None
) -> list[EmbedField]:
def platforms_to_fields(currPlatform: str, **k: str | None) -> list[EmbedField]:
"""Convert a platform to a dictionary of fields"""
relsEm: list[dict[str, dict[str, str | bool]]] = []

Expand Down Expand Up @@ -363,11 +360,13 @@ def platforms_to_fields(
pin = media_id_to_platform(value, platform_mappings[platform])
if platform == "tvdb":
value = str(value).removeprefix("https://www.thetvdb.com/")
relsEm.append({
"name": f"<:{platform_mappings[platform]}:{pin['emoid']}> {pin['pf']}",
"value": f"[{value}](<{pin['uid']}>)",
"inline": True,
})
relsEm.append(
{
"name": f"<:{platform_mappings[platform]}:{pin['emoid']}> {pin['pf']}",
"value": f"[{value}](<{pin['uid']}>)",
"inline": True,
}
)
except KeyError:
continue

Expand All @@ -376,11 +375,13 @@ def platforms_to_fields(
# get the last part of the url
media_id = tvtime[-1]
pin = media_id_to_platform(media_id=media_id, platform="tvtime")
relsEm.append({
"name": f"<:tvTime:{pin['emoid']}> {pin['pf']}",
"value": f"[{k['tvdb']}](<{pin['uid']}>)",
"inline": True,
})
relsEm.append(
{
"name": f"<:tvTime:{pin['emoid']}> {pin['pf']}",
"value": f"[{k['tvdb']}](<{pin['uid']}>)",
"inline": True,
}
)

# sort the list by platform name
relsEm = sorted(relsEm, key=lambda k: k["name"])
Expand Down

0 comments on commit a76d5c8

Please sign in to comment.