From 9b34bf899d6fee6edf5ed6e3b5902da89cc1a727 Mon Sep 17 00:00:00 2001 From: Loic Houpert <10154151+lhoupert@users.noreply.github.com> Date: Thu, 14 Jan 2021 16:24:53 +0100 Subject: [PATCH] cover update2 --- recipes/mediapart.recipe | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/recipes/mediapart.recipe b/recipes/mediapart.recipe index facf3e7aab..b0b366e5e5 100644 --- a/recipes/mediapart.recipe +++ b/recipes/mediapart.recipe @@ -7,7 +7,7 @@ # been added through custom entries in the function my_parse_index. # 3) Fix the cover image so it doesnt disappear from the Kindle menu # ( cover image format is changed to .jpeg) -# +# 14 Jan 2021 - Add Mediapart Logo url as masthead_url from __future__ import unicode_literals __license__ = 'GPL v3' @@ -18,6 +18,7 @@ Mediapart import re from datetime import date, datetime, timedelta +from time import strftime from calibre.web.feeds import feeds_from_index from calibre.web.feeds.news import BasicNewsRecipe @@ -50,6 +51,7 @@ class Mediapart(BasicNewsRecipe): remove_tags = [classes('login-subscribe print-source_url')] conversion_options = {'smarten_punctuation': True} + masthead_url = "https://raw.githubusercontent.com/lhoupert/calibre_contrib/main/mediapart_masthead.png" cover_url = 'https://raw.githubusercontent.com/lhoupert/calibre_contrib/main/mediapart.jpeg' # -- @@ -240,3 +242,22 @@ class Mediapart(BasicNewsRecipe): br['password'] = self.password br.submit() return br + + def default_cover(self, cover_file): + """ + Create a generic cover for recipes that don't have a cover + This override adds time to the cover + """ + try: + from calibre.ebooks import calibre_cover + title = self.title if isinstance(self.title, unicode) else \ + self.title.decode('utf-8', 'replace') + date = strftime(self.timefmt) + time = strftime('%a %d %b %Y %-H:%M') + img_data = calibre_cover(title, date, time) + cover_file.write(img_data) + cover_file.flush() + print(f'title: {title}\ndate: {date}\ntime: {time}') + except: + self.log.exception('Failed to generate default cover') + return False