Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Recipes

Notices

Reply
 
Thread Tools Search this Thread
Old 01-18-2025, 11:03 AM   #1
alphonk
Member
alphonk began at the beginning.
 
Posts: 10
Karma: 10
Join Date: Dec 2024
Device: kindle scribe
Afrique XXI - Journal panafricain en ligne (French) - Recipe

Afrique XXI - Journal panafricain en ligne (French) - Recipe


Quote:
Code:
#!/usr/bin/env python

'''
afriquexxi.info
'''

from calibre.web.feeds.news import BasicNewsRecipe
from datetime import datetime, timedelta
from zoneinfo import ZoneInfo
import urllib.request

class AfriqueXXIRecipe(BasicNewsRecipe):
    title = 'Afrique XXI'
    description = 'Journal panafricain en ligne'
    language = 'fr'
    oldest_article = 30
    max_articles_per_feed = 50
    auto_cleanup = False
    encoding = 'utf-8'
    use_embedded_content = True
    no_stylesheets = True
    remove_javascript = True
    scale_news_images_to_device = True

    feeds = [
        ('Afrique XXI', 'https://afriquexxi.info/?page=backend&lang=fr')
    ]

    extra_css = '''
        img { max-width: 100%; height: auto; display: block; margin: 1em auto; }
        h1 { font-size: 2em; margin: 1em 0; }
        h2 { font-size: 1.5em; margin: 1em 0; }
    '''

    def default_cover(self, cover_file):
        """
        Crée une couverture personnalisée avec le logo
        """
        from qt.core import QFont, QImage, QPainter, QPen, QRect, Qt, QColor
        from calibre.gui2 import ensure_app, load_builtin_fonts, pixmap_to_data
        try:
            ensure_app()
            load_builtin_fonts()

            today = datetime.now(ZoneInfo('Europe/Paris'))
            wkd = today.weekday()
            french_weekday = {0:'Lundi',1:'Mardi',2:'Mercredi',3:'Jeudi',4:'Vendredi',5:'Samedi',6:'Dimanche'}
            french_month = {1:'janvier', 2:'février', 3:'mars', 4:'avril', 5:'mai', 6:'juin', 
                          7:'juillet', 8:'août', 9:'septembre', 10:'octobre', 11:'novembre', 12:'décembre'}
            
            weekday = french_weekday[wkd]
            month = french_month[today.month]
            date_str = f"{weekday} {today.day} {month} {today.year}"
            edition = today.strftime('Édition de %Hh')

            # Image de base
            img = QImage(1400, 1920, QImage.Format_RGB888)
            img.fill(QColor('lightgreen'))

            # Charger le logo
            logo_url = 'https://upload.wikimedia.org/wikipedia/fr/7/74/Afrique_xxi.png'
            logo_data = urllib.request.urlopen(logo_url).read()
            logo = QImage()
            logo.loadFromData(logo_data)

            # Redimensionner le logo (garder les proportions)
            logo_width = 800  # Largeur souhaitée
            scaled_logo = logo.scaledToWidth(logo_width, Qt.SmoothTransformation)

            # Position du logo (centré)
            x = (img.width() - scaled_logo.width()) // 2
            y = (img.height() - scaled_logo.height()) // 2 - 100  # Un peu au-dessus du centre

            # Dessiner le logo
            p = QPainter(img)
            p.drawImage(x, y, scaled_logo)
            p.end()

            # Ajouter la date
            p = QPainter(img)
            p.setPen(QPen(QColor('black')))
            
            font = QFont('Liberation Sans', 36)
            p.setFont(font)
            
            r = QRect(0, y + scaled_logo.height() + 50, img.width(), 100)
            p.drawText(r, Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignVCenter, date_str)

            # Ajouter l'édition
            font.setItalic(True)
            font.setPointSize(32)
            p.setFont(font)
            
            r = QRect(0, y + scaled_logo.height() + 150, img.width(), 100)
            p.drawText(r, Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignVCenter, edition)
            
            p.end()

            # Sauvegarder
            img_data = pixmap_to_data(img)
            cover_file.write(img_data)
            cover_file.flush()
            return True

        except Exception as e:
            self.log.error(f'Erreur lors de la création de la couverture: {e}')
            return False

Last edited by PeterT; 01-18-2025 at 05:56 PM. Reason: adding in code block
alphonk is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Other Non-Fiction Guérin, Eugénie de: Journal et lettres(1862)[French]V.1 -- 09 Févr 2021 bathop ePub Books 0 02-09-2021 10:58 AM
Other Non-Fiction Guérin, Maurice de: Journal, lettres et poémes(1864)[French]V.1--09 Févr. 2021 bathop ePub Books 0 02-09-2021 10:46 AM
Democracy Journal recipe? davidnye Recipes 3 02-26-2013 08:09 AM
History Blanc Alphonse-Michel: Récits d'un officier d'Afrique. V1 FRENCH. 16 MAY 2012 roger64 ePub Books 0 05-16-2012 03:35 AM
Jeune Afrique recipe? ssternin Recipes 0 07-12-2011 11:11 AM


All times are GMT -4. The time now is 04:55 AM.


MobileRead.com is a privately owned, operated and funded community.