From 1d1e599b5341f53fc7e2c7d2fc67aa5ef650f496 Mon Sep 17 00:00:00 2001 From: CRMSNxyz Date: Mon, 14 Jul 2025 15:28:22 +0200 Subject: [PATCH] add: make completed work --- media/banners/completed/.gitkeep | 0 scripts/anime_list.py | 37 +++++++++++++++++++------------- scripts/formatter.py | 25 ++++++++++++++++++++- 3 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 media/banners/completed/.gitkeep diff --git a/media/banners/completed/.gitkeep b/media/banners/completed/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/scripts/anime_list.py b/scripts/anime_list.py index 161fc3e..6204091 100644 --- a/scripts/anime_list.py +++ b/scripts/anime_list.py @@ -1,7 +1,7 @@ from posix import read from graphql.utilities.find_breaking_changes import dict_diff from scripts.query import AnilistQuery -from scripts.formatter import create_cover_card +from scripts.formatter import create_cover_card_progress, create_cover_card_score import os class AnimeList: @@ -42,11 +42,15 @@ class AnimeList: if dictionary["name"] is None: dictionary["name"] = media.get('title', {}).get('romaji') + banner_image = dictionary["bannerImage"] = media.get('bannerImage') + if not banner_image: + print("no cover image found") + continue + cover_image = media.get('coverImage') + if cover_image: + dictionary['coverLarge'] = cover_image.get('large') + if self.status == "CURRENT": - dictionary["bannerImage"] = media.get('bannerImage') - cover_image = media.get('coverImage') - if cover_image: - dictionary['coverLarge'] = cover_image.get('large') dictionary["current_progress"] = entry.get('progress') started_at = entry.get('startedAt') if started_at: @@ -98,7 +102,7 @@ class AnimeList: # ✅ TODO: Check for the status if self.status == "CURRENT": for list_item in titles: - create_cover_card( + create_cover_card_progress( cover_url=list_item['coverLarge'], anime_name=list_item['name'], progress=list_item['current_progress'], @@ -117,14 +121,19 @@ class AnimeList: # ✅ TODO: if status = COMPLETED -> print titles # TODO: Try to sort these strings, by the score elif self.status == "COMPLETED": - counter = 1 - top_string = "| ID | Anime Title | Score | Rewatched |\n|:-------|:-------|:--------|:---------|\n" - for title in range(len(titles)): - anime = titles[title] + titles = self.get_animes() + for list_item in titles: + create_cover_card_score( + cover_url=list_item['bannerImage'], + anime_name=list_item['name'], + points = list_item['score'], + media_id = list_item['media_id'] + ) + + anime_media_id = list_item['media_id'] + + string = f'[![anime_image](./media/banners/completed/{anime_media_id}.jpg)](https://anilist.co/anime/{anime_media_id})\n' - anime_media_id = {anime["media_id"]} - string = f'''| {counter} | **[{anime["name"]}](https://anilist.co/anime/{anime["media_id"]})** | **{anime["score"]}** | **{anime["repeat"]}**\n''' - counter += 1 all_stings += string else: @@ -135,8 +144,6 @@ class AnimeList: anime_cover_image = anime['cover-image'] string = f'[![Anime Cover]({anime_cover_image})](https://anilist.com/anime/{anime_media_id})\n' - # string = f'\n' - # string = f'''{counter}. **[{anime["name"]}](https://anilist.co/anime/{anime["media_id"]})**\n''' counter += 1 all_stings += string diff --git a/scripts/formatter.py b/scripts/formatter.py index f829208..10a4427 100644 --- a/scripts/formatter.py +++ b/scripts/formatter.py @@ -2,7 +2,7 @@ from PIL import Image, ImageDraw, ImageFont from io import BytesIO import requests, os -def create_cover_card(cover_url, anime_name, progress, start_at, media_id) -> None: +def create_cover_card_progress(cover_url, anime_name, progress, start_at, media_id) -> None: response = requests.get(cover_url) image = Image.open(BytesIO(response.content)).convert("RGB") @@ -26,3 +26,26 @@ def create_cover_card(cover_url, anime_name, progress, start_at, media_id) -> No output_path = os.path.join(os.path.dirname(__file__), '..', 'media', 'banners', f"{media_id}.jpg") base.save(output_path) + + +def create_cover_card_score(cover_url, anime_name, points, media_id) -> None: + response = requests.get(cover_url) + image = Image.open(BytesIO(response.content)).convert("RGB") + + base_width = 800 + base_height = 250 + base = Image.new("RGB", ((base_width), base_height)) + + cover = image.resize((base_width, base_height)) + base.paste(cover) + + draw = ImageDraw.Draw(base) + font_path = os.path.join(os.path.dirname(__file__), '..', 'media', 'fonts', 'Roboto-Bold.ttf') + font = ImageFont.truetype(font_path, 18) + + text = f"{anime_name}\n {points}/10" + draw.rectangle((0, base_height - 45, base_width, base_height), fill=(0, 0, 0, 180)) + draw.text((10, base_height - 40), text, font=font, fill="white") + + output_path = os.path.join(os.path.dirname(__file__), '..', 'media', 'banners', 'completed', f"{media_id}.jpg") + base.save(output_path) -- GitLab