Merge branch 'newsfeed_mediapart_add_timeoncover_image' of https://github.com/lhoupert/calibre

This commit is contained in:
Kovid Goyal 2021-01-15 16:06:19 +05:30
commit 6f0c2433bb
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -8,7 +8,7 @@
# 3) Fix the cover image so it doesnt disappear from the Kindle menu # 3) Fix the cover image so it doesnt disappear from the Kindle menu
# ( cover image format is changed to .jpeg) # ( cover image format is changed to .jpeg)
# 14 Jan 2021 - Add Mediapart Logo url as masthead_url and change cover # 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 from __future__ import unicode_literals
__license__ = 'GPL v3' __license__ = 'GPL v3'
@ -18,7 +18,7 @@ Mediapart
''' '''
import re 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 import feeds_from_index
from calibre.web.feeds.news import BasicNewsRecipe 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 = [ feeds = [
('La Une', 'http://www.mediapart.fr/articles/feed'), ('La Une', 'http://www.mediapart.fr/articles/feed'),
@ -259,23 +261,44 @@ class Mediapart(BasicNewsRecipe):
# Get data # Get data
image_url = 'https://raw.githubusercontent.com/lhoupert/calibre_contrib/main/mediapart.jpeg' image_url = 'https://raw.githubusercontent.com/lhoupert/calibre_contrib/main/mediapart.jpeg'
data = self.index_to_soup(image_url, raw=True) 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 = QImage()
img.loadFromData(data) 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 = QPen(Qt.black)
pen.setWidth(4) pen.setWidth(4)
p.setPen(pen) p.setPen(pen)
font = QFont() font = QFont()
font.setFamily('Times') font.setFamily('Times')
font.setBold(True) font.setItalic(True)
font.setPointSize(78) font.setPointSize(66)
p.setFont(font) p.setFont(font)
# Add date # Add date
r = QRect(0, 600, 744,200) r = QRect(0, 720, 744,100)
p.drawText(r, Qt.AlignmentFlag.AlignJustify | Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignCenter, date) p.drawText(r, Qt.AlignmentFlag.AlignJustify | Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignCenter, edition)
p.end() p.end()
return pixmap_to_data(img) return pixmap_to_data(img)