Skip to content

Commit

Permalink
Merge pull request #20 from zeroquinc:trakt
Browse files Browse the repository at this point in the history
chore: trakt logging and functions optimizations
  • Loading branch information
zeroquinc authored Jun 22, 2024
2 parents 9be5658 + 40349a3 commit bb9eaed
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/trakt/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from config.globals import TRAKT_ICON

from utils.custom_logger import logger

# Function to process recent ratings and send them to a specified Discord channel as embeds
async def process_ratings(ratings_channel, username):
client = TraktClient()
Expand All @@ -30,11 +32,14 @@ async def process_rating(rating):
embed_builder = EmbedBuilder(title=title, description=description, color=0xFF0000)
embed_builder.set_thumbnail(url=rating.poster)
embed_builder.set_author(name=author, icon_url=TRAKT_ICON)

logger.info(f"Sending rating embed to Discord: {title} - {description}")

await embed_builder.send_embed(ratings_channel)

for rating in ratings:
await process_rating(rating)

# Function to process recent favorites and send them to a specified Discord channel as embeds
async def process_favorites(favorites_channel, username):
client = TraktClient()
Expand All @@ -43,12 +48,6 @@ async def process_favorites(favorites_channel, username):
favorites = sorted(user.get_favorites(start_time=then, end_time=now), key=lambda favorite: favorite.date)

async def process_favorite(favorite):
description_formats = {
'show': f"{username} favorited this {favorite.type}",
'season': f"{username} favorited this {favorite.type}",
'episode': f"{username} favorited this {favorite.type}",
'movie': f"{username} favorited this {favorite.type}"
}
author_formats = {
'show': "A show has been favorited on Trakt",
'season': "A season has been favorited on Trakt",
Expand All @@ -61,12 +60,15 @@ async def process_favorite(favorite):
'episode': f"{favorite.show_title} - S{favorite.season_id}E{favorite.episode_id}",
'movie': f"{favorite.title} ({favorite.year})"
}
description = description_formats[favorite.type]
description = f"{username} favorited this {favorite.type}"
author = author_formats[favorite.type]
title = title_formats[favorite.type]
embed_builder = EmbedBuilder(title=title, description=description, color=0xFF0000)
embed_builder.set_thumbnail(url=favorite.poster)
embed_builder.set_author(name=author, icon_url=TRAKT_ICON)

logger.info(f"Sending favorite embed to Discord: {title} - {description}")

await embed_builder.send_embed(favorites_channel)

for favorite in favorites:
Expand Down

0 comments on commit bb9eaed

Please sign in to comment.