diff --git a/recipes/mediapart.recipe b/recipes/mediapart.recipe index cc76ff441e..003d8b9e10 100644 --- a/recipes/mediapart.recipe +++ b/recipes/mediapart.recipe @@ -8,7 +8,7 @@ # 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 and change cover -# by adding overlaying the date on top of the Mediapart cover +# by overlaying the date on top of the Mediapart cover from __future__ import unicode_literals __license__ = 'GPL v3' @@ -18,7 +18,7 @@ Mediapart ''' import re -from datetime import date, datetime, timedelta +from datetime import date, datetime, timezone, timedelta from calibre.web.feeds import feeds_from_index from calibre.web.feeds.news import BasicNewsRecipe @@ -55,7 +55,9 @@ class Mediapart(BasicNewsRecipe): # -- - oldest_article_date = datetime.today() - timedelta(days=oldest_article) + # Get date in french time zone format + today = datetime.now(timezone.utc) + timedelta(hours=1) + oldest_article_date = today - timedelta(days=oldest_article) feeds = [ ('La Une', 'http://www.mediapart.fr/articles/feed'), @@ -259,23 +261,44 @@ class Mediapart(BasicNewsRecipe): # Get data image_url = 'https://raw.githubusercontent.com/lhoupert/calibre_contrib/main/mediapart.jpeg' data = self.index_to_soup(image_url, raw=True) + # Get date and hour corresponding to french time zone + today = datetime.now(timezone.utc) + timedelta(hours=1) + wkd = today.weekday() + french_weekday={0:'Mon',1:'Mar',2:'Mer',3:'Jeu',4:'Ven',5:'Sam',6:'Dim'} + day = french_weekday[wkd]+'.' + date = day + ' ' + today.strftime('%d %b. %Y') + edition = today.strftime('Édition de %Hh') + + # Get Cover data img = QImage() img.loadFromData(data) - p = QPainter(img) + # Overlay date on cover + p = QPainter(img) + pen = QPen(Qt.black) + pen.setWidth(6) + p.setPen(pen) + font = QFont() + font.setFamily('Times') + font.setPointSize(78) + p.setFont(font) + r = QRect(0, 600, 744,100) + p.drawText(r, Qt.AlignmentFlag.AlignJustify | Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignCenter, date) + p.end() + + # Overlay edition information on cover + p = QPainter(img) pen = QPen(Qt.black) pen.setWidth(4) p.setPen(pen) - font = QFont() font.setFamily('Times') - font.setBold(True) - font.setPointSize(78) + font.setItalic(True) + font.setPointSize(66) p.setFont(font) - # Add date - r = QRect(0, 600, 744,200) - p.drawText(r, Qt.AlignmentFlag.AlignJustify | Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignCenter, date) + r = QRect(0, 720, 744,100) + p.drawText(r, Qt.AlignmentFlag.AlignJustify | Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignCenter, edition) p.end() return pixmap_to_data(img)