From b485e5fbd3a127dc13d8b647c6819c2e314cf0fd Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Mon, 4 Apr 2022 11:15:27 +0200 Subject: [PATCH] Legimi update. --- src/depot/legimi.py | 58 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/src/depot/legimi.py b/src/depot/legimi.py index 3a6829a8..01f4ee2e 100644 --- a/src/depot/legimi.py +++ b/src/depot/legimi.py @@ -6,6 +6,7 @@ from librarian.html import transform_abstrakt from librarian.builders import EpubBuilder, MobiBuilder from librarian.cover import LegimiCornerCover, LegimiCover import requests +from slugify import slugify @@ -17,6 +18,9 @@ fundraising=[ "Przekaż 1% podatku na Wolne Lektury.
\nKRS: 0000070056
\nNazwa organizacji: Fundacja Nowoczesna Polska
\nKażda wpłacona kwota zostanie przeznaczona na rozwój Wolnych Lektur." ] +description_add = '

Książkę polecają Wolne Lektury — najpopularniejsza biblioteka on-line.

' + + class Legimi: #BASE_URL = 'https://wydawca.legimi.com' BASE_URL = 'https://panel.legimi.pl' @@ -86,7 +90,7 @@ class Legimi: 'Isbn': '', 'LanguageLocale': lang_code_3to2(meta.language), - 'Description': '

—

', + 'Description': description_add, } if meta.isbn_html: isbn = meta.isbn_html @@ -142,6 +146,58 @@ class Legimi: book.legimi_id = legimi_id book.save(update_fields=['legimi_id']) + def get_description(self, wlbook): + description = '' + abstract = wlbook.tree.find('.//abstrakt') + if abstract is not None: + description = transform_abstrakt(abstract) + description += description_add + description += '

' + description += ', '.join( + '{}'.format( + slugify(p.readable()), + p.readable(), + ) + for p in wlbook.meta.authors + ) + '
' + description += '{}
'.format( + wlbook.meta.url.slug, + wlbook.meta.title + ) + if wlbook.meta.translators: + description += 'tłum. ' + ', '.join(p.readable() for p in wlbook.meta.translators) + '
' + description += 'Epoka: ' + ', '.join( + '{}'.format( + slugify(p), + p, + ) + for p in wlbook.meta.epochs + ) + ' ' + description += 'Rodzaj: ' + ', '.join( + '{}'.format( + slugify(p), + p, + ) + for p in wlbook.meta.kinds + ) + ' ' + description += 'Gatunek: ' + ', '.join( + '{}'.format( + slugify(p), + p, + ) + for p in wlbook.meta.genres + ) + '

' + + if wlbook.meta.audience: + description += '

{} to lektura szkolna.'.format(wlbook.meta.title) + if wlbook.tree.find('//pe'): + description += '
Ebook {title} zawiera przypisy opracowane specjalnie dla uczennic i uczniów {school}.'.format( + title=wlbook.meta.title, + school='szkoły podstawowej' if wlbook.meta.audience == 'SP' else 'liceum i technikum' + ) + description += '

' + return description + def create_book(self, book_data, files_data): data = { 'createValidationTrue': 'true', -- 2.20.1