| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
""" |
| 4 |
zerodeux.fr |
| 5 |
""" |
| 6 |
|
| 7 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 8 |
|
| 9 |
|
| 10 |
class ZeroDeuxRecipe(BasicNewsRecipe): |
| 11 |
title = 'Zérodeux' |
| 12 |
__author__ = 'Kabonix' |
| 13 |
description = "Revue d'art contemporain trimestrielle" |
| 14 |
publisher = 'Zérodeux' |
| 15 |
category = 'art, contemporary art, criticism' |
| 16 |
language = 'fr' |
| 17 |
encoding = 'utf-8' |
| 18 |
oldest_article = 60 |
| 19 |
max_articles_per_feed = 25 |
| 20 |
|
| 21 |
no_stylesheets = True |
| 22 |
remove_javascript = True |
| 23 |
auto_cleanup = False |
| 24 |
|
| 25 |
feeds = [ |
| 26 |
('Essais', 'https://www.zerodeux.fr/category/essais/feed/'), |
| 27 |
('Guests', 'https://www.zerodeux.fr/category/guests/feed/'), |
| 28 |
('Interviews', 'https://www.zerodeux.fr/category/interviews/feed/'), |
| 29 |
('Reviews', 'https://www.zerodeux.fr/category/reviews/feed/'), |
| 30 |
('News', 'https://www.zerodeux.fr/category/news/feed/'), |
| 31 |
('Special Web', 'https://www.zerodeux.fr/category/specialweb/feed/'), |
| 32 |
] |
| 33 |
|
| 34 |
def get_cover_url(self): |
| 35 |
soup = self.index_to_soup('https://www.zerodeux.fr') |
| 36 |
cover_div = soup.find('div', {'id': 'responsive_lightbox_image_widget-2'}) |
| 37 |
if cover_div: |
| 38 |
cover_img = cover_div.find('img', {'class': 'rl-image-widget-image'}) |
| 39 |
if cover_img and 'src' in cover_img.attrs: |
| 40 |
return cover_img['src'] |
| 41 |
return None |
| 42 |
|
| 43 |
keep_only_tags = [dict(name='article', attrs={'id': 'single-post'})] |
| 44 |
|
| 45 |
remove_tags = [ |
| 46 |
dict(name='div', attrs={'class': ['single-associate', 'single-info', 'transition']}), |
| 47 |
dict(name='div', attrs={'id': ['sidebar', 'menu_footer']}), |
| 48 |
dict(name='ul', attrs={'class': ['single-info']}), # Supprime le bloc "Partage" |
| 49 |
dict(name='li', text='Du même auteur :'), # Supprime le titre "Du même auteur" |
| 50 |
dict(name='p', attrs={'class': ['recomand']}), # Supprime "articles liés" |
| 51 |
] |
| 52 |
|
| 53 |
def preprocess_html(self, soup): |
| 54 |
# Nettoyage des styles |
| 55 |
for tag in soup.findAll(True): |
| 56 |
if 'style' in tag.attrs: |
| 57 |
del tag['style'] |
| 58 |
|
| 59 |
# Nettoyage des images |
| 60 |
for img in soup.findAll('img'): |
| 61 |
for attr in ['srcset', 'sizes', 'loading', 'class', 'width', 'height', 'decoding', 'fetchpriority']: |
| 62 |
if attr in img.attrs: |
| 63 |
del img[attr] |
| 64 |
|
| 65 |
if img.get('src', '').startswith('/'): |
| 66 |
img['src'] = 'https://www.zerodeux.fr' + img['src'] |
| 67 |
|
| 68 |
# Suppression du texte "Partage :" et "Du même auteur :" |
| 69 |
for text in soup.findAll(text=True): |
| 70 |
if text.strip() in ['Partage :', 'Du même auteur :']: |
| 71 |
text.extract() |
| 72 |
|
| 73 |
return soup |
| 74 |
|
| 75 |
extra_css = ''' |
| 76 |
h1 { font-size: 1.8em; font-weight: bold; margin: 0 0 1em 0; } |
| 77 |
h2 { font-size: 1.4em; font-weight: bold; margin: 1em 0; } |
| 78 |
.single-author { font-style: italic; margin-bottom: 1.5em; color: #666; } |
| 79 |
img { max-width: 100%; height: auto; margin: 1em auto; } |
| 80 |
figcaption { font-size: 0.9em; font-style: italic; color: #666; margin: 0.5em 0 1.5em 0; } |
| 81 |
p { margin-bottom: 1em; line-height: 1.5; } |
| 82 |
ol { margin: 1em 0 1em 2em; } |
| 83 |
blockquote { margin: 1em 0; padding: 0 1em; border-left: 3px solid #ccc; } |
| 84 |
.wp-block-image { margin: 1.5em 0; } |
| 85 |
.has-small-font-size { font-size: 0.9em; } |
| 86 |
''' |
| 87 |
|
| 88 |
def populate_article_metadata(self, article, soup, first): |
| 89 |
author_div = soup.find('div', {'class': 'single-author'}) |
| 90 |
if author_div: |
| 91 |
author = author_div.get_text().strip() |
| 92 |
if author.startswith('par '): |
| 93 |
author = author[4:] |
| 94 |
article.author = author |