From 6c77f0ced21b29dc37db0a3626b122e884e2a472 Mon Sep 17 00:00:00 2001 From: Bulat Kurbanov Date: Tue, 6 Dec 2022 18:48:35 +0100 Subject: [PATCH] Fix get_caption --- src/app/services/caption_getter.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/app/services/caption_getter.py b/src/app/services/caption_getter.py index 6bf7648..aa32c36 100644 --- a/src/app/services/caption_getter.py +++ b/src/app/services/caption_getter.py @@ -18,10 +18,20 @@ def get_author_string(author: BookAuthor) -> str: def get_caption(book: Book) -> str: caption_title = f"📖 {book.title}" + caption_title_length = len(caption_title) caption_authors_parts = [] + authors_caption_length = 0 for author in book.authors: - caption_authors_parts.append(f"👤 {get_author_string(author)}") + author_caption = f"👤 {get_author_string(author)}" + + if ( + caption_title_length + authors_caption_length + len(author_caption) + 1 + ) <= 1024: + caption_authors_parts.append(author_caption) + authors_caption_length += len(author_caption) + 1 + else: + break if not caption_authors_parts: return caption_title