| 1 |
#!/usr/bin/env python |
| 2 |
""" |
| 3 |
orientxxi.info |
| 4 |
""" |
| 5 |
|
| 6 |
from datetime import datetime |
| 7 |
from zoneinfo import ZoneInfo |
| 8 |
|
| 9 |
from calibre.utils.img import image_from_data |
| 10 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 11 |
|
| 12 |
|
| 13 |
class OrientXXIRecipe(BasicNewsRecipe): |
| 14 |
title = 'Orient XXI' |
| 15 |
__author__ = 'Votre Nom' |
| 16 |
description = 'Magazine en ligne sur le Monde arabe et musulman' |
| 17 |
language = 'fr' |
| 18 |
oldest_article = 30 |
| 19 |
max_articles_per_feed = 50 |
| 20 |
auto_cleanup = False |
| 21 |
encoding = 'utf-8' |
| 22 |
use_embedded_content = True |
| 23 |
no_stylesheets = True |
| 24 |
remove_javascript = True |
| 25 |
scale_news_images_to_device = True |
| 26 |
|
| 27 |
feeds = [('Orient XXI', 'https://orientxxi.info/?page=backend&lang=fr')] |
| 28 |
|
| 29 |
extra_css = ''' |
| 30 |
img { max-width: 100%; height: auto; display: block; margin: 1em auto; } |
| 31 |
h1 { font-size: 2em; margin: 1em 0; } |
| 32 |
h2 { font-size: 1.5em; margin: 1em 0; } |
| 33 |
''' |
| 34 |
|
| 35 |
def default_cover(self, cover_file): |
| 36 |
""" |
| 37 |
Crée une couverture personnalisée pour Orient XXI |
| 38 |
""" |
| 39 |
from qt.core import QColor, QFont, QImage, QPainter, QPen, QRect, Qt |
| 40 |
|
| 41 |
from calibre.gui2 import ensure_app, load_builtin_fonts, pixmap_to_data |
| 42 |
|
| 43 |
try: |
| 44 |
# Préparation de l'environnement Qt |
| 45 |
ensure_app() |
| 46 |
load_builtin_fonts() |
| 47 |
|
| 48 |
# Date en français |
| 49 |
today = datetime.now(ZoneInfo('Europe/Paris')) |
| 50 |
wkd = today.weekday() |
| 51 |
french_weekday = {0: 'Lundi', 1: 'Mardi', 2: 'Mercredi', 3: 'Jeudi', 4: 'Vendredi', 5: 'Samedi', 6: 'Dimanche'} |
| 52 |
french_month = { |
| 53 |
1: 'janvier', |
| 54 |
2: 'février', |
| 55 |
3: 'mars', |
| 56 |
4: 'avril', |
| 57 |
5: 'mai', |
| 58 |
6: 'juin', |
| 59 |
7: 'juillet', |
| 60 |
8: 'août', |
| 61 |
9: 'septembre', |
| 62 |
10: 'octobre', |
| 63 |
11: 'novembre', |
| 64 |
12: 'décembre', |
| 65 |
} |
| 66 |
|
| 67 |
weekday = french_weekday[wkd] |
| 68 |
month = french_month[today.month] |
| 69 |
date_str = f'{weekday} {today.day} {month} {today.year}' |
| 70 |
edition = today.strftime('Édition de %Hh%M') |
| 71 |
|
| 72 |
# Création de l'image de base (ratio ~1.6 pour format livre) |
| 73 |
img = QImage(1200, 1920, QImage.Format_RGB888) |
| 74 |
img.fill(QColor(255, 140, 0)) # Fond orange tangerine (darkorange) |
| 75 |
|
| 76 |
# Télécharger le logo |
| 77 |
logo_url = 'https://upload.wikimedia.org/wikipedia/fr/1/15/Orient_XXI.png' |
| 78 |
|
| 79 |
# Utiliser urllib pour télécharger l'image |
| 80 |
try: |
| 81 |
logo_data = self.get_browser().open(logo_url).read() |
| 82 |
logo_img = image_from_data(logo_data) |
| 83 |
|
| 84 |
if not logo_img.isNull(): |
| 85 |
# Calculer la largeur proportionnelle pour une hauteur de 300px |
| 86 |
logo_height = 300 |
| 87 |
logo_width = int(logo_img.width() * (logo_height / logo_img.height())) |
| 88 |
|
| 89 |
# Texte du titre |
| 90 |
p = QPainter(img) |
| 91 |
|
| 92 |
# Centrer le logo |
| 93 |
logo_x = (1200 - logo_width) // 2 |
| 94 |
logo_y = 300 # Positionnement au-dessus du titre |
| 95 |
|
| 96 |
# Dessiner le logo |
| 97 |
p.drawImage(QRect(logo_x, logo_y, logo_width, logo_height), logo_img) |
| 98 |
|
| 99 |
# Couleur texte (noir) |
| 100 |
pen = QPen(QColor('black')) |
| 101 |
p.setPen(pen) |
| 102 |
|
| 103 |
# Titre principal |
| 104 |
font = QFont() |
| 105 |
font.setFamily('Liberation Sans') |
| 106 |
font.setPointSize(60) |
| 107 |
font.setBold(True) |
| 108 |
p.setFont(font) |
| 109 |
|
| 110 |
# Ajuster la position du titre pour être sous le logo |
| 111 |
title_rect = QRect(0, 700, 1200, 100) |
| 112 |
p.drawText(title_rect, Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignVCenter, 'ORIENT') |
| 113 |
|
| 114 |
# Sous-titre |
| 115 |
font.setPointSize(40) |
| 116 |
p.setFont(font) |
| 117 |
subtitle_rect = QRect(0, 800, 1200, 100) |
| 118 |
p.drawText(subtitle_rect, Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignVCenter, 'XXI') |
| 119 |
|
| 120 |
# Date et édition |
| 121 |
font.setPointSize(36) |
| 122 |
font.setBold(False) |
| 123 |
p.setFont(font) |
| 124 |
date_rect = QRect(0, 950, 1200, 100) |
| 125 |
p.drawText(date_rect, Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignVCenter, date_str) |
| 126 |
|
| 127 |
font.setPointSize(32) |
| 128 |
font.setItalic(True) |
| 129 |
p.setFont(font) |
| 130 |
edition_rect = QRect(0, 1050, 1200, 100) |
| 131 |
p.drawText(edition_rect, Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignVCenter, edition) |
| 132 |
|
| 133 |
p.end() |
| 134 |
except Exception as e: |
| 135 |
self.log.error(f'Erreur lors du téléchargement ou du traitement du logo: {e}') |
| 136 |
|
| 137 |
# Si échec du téléchargement du logo, créer quand même la couverture sans logo |
| 138 |
p = QPainter(img) |
| 139 |
pen = QPen(QColor('black')) |
| 140 |
p.setPen(pen) |
| 141 |
|
| 142 |
# Titre principal |
| 143 |
font = QFont() |
| 144 |
font.setFamily('Liberation Sans') |
| 145 |
font.setPointSize(60) |
| 146 |
font.setBold(True) |
| 147 |
p.setFont(font) |
| 148 |
|
| 149 |
# Positions standard sans logo |
| 150 |
title_rect = QRect(0, 700, 1200, 100) |
| 151 |
p.drawText(title_rect, Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignVCenter, 'ORIENT') |
| 152 |
|
| 153 |
# Sous-titre |
| 154 |
font.setPointSize(40) |
| 155 |
p.setFont(font) |
| 156 |
subtitle_rect = QRect(0, 800, 1200, 100) |
| 157 |
p.drawText(subtitle_rect, Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignVCenter, 'XXI') |
| 158 |
|
| 159 |
# Date et édition |
| 160 |
font.setPointSize(36) |
| 161 |
font.setBold(False) |
| 162 |
p.setFont(font) |
| 163 |
date_rect = QRect(0, 950, 1200, 100) |
| 164 |
p.drawText(date_rect, Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignVCenter, date_str) |
| 165 |
|
| 166 |
font.setPointSize(32) |
| 167 |
font.setItalic(True) |
| 168 |
p.setFont(font) |
| 169 |
edition_rect = QRect(0, 1050, 1200, 100) |
| 170 |
p.drawText(edition_rect, Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignVCenter, edition) |
| 171 |
|
| 172 |
p.end() |
| 173 |
|
| 174 |
# Sauvegarde de l'image |
| 175 |
img_data = pixmap_to_data(img) |
| 176 |
cover_file.write(img_data) |
| 177 |
cover_file.flush() |
| 178 |
return True |
| 179 |
|
| 180 |
except Exception as e: |
| 181 |
self.log.error(f'Erreur lors de la création de la couverture: {e}') |
| 182 |
return False |