Update Le Monde

Fixes #1713040 [recipe le monde abonnés](https://bugs.launchpad.net/calibre/+bug/1713040)
This commit is contained in:
Kovid Goyal 2017-08-29 08:24:29 +05:30
parent 7e5555845b
commit bce0c6296c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 31 additions and 97 deletions

View File

@ -3,10 +3,15 @@ __copyright__ = '2012'
''' '''
lemonde.fr lemonde.fr
''' '''
import re
from calibre.web.feeds.recipes import BasicNewsRecipe from calibre.web.feeds.recipes import BasicNewsRecipe
def classes(classes):
q = frozenset(classes.split(' '))
return dict(attrs={
'class': lambda x: x and frozenset(x.split()).intersection(q)})
class LeMonde(BasicNewsRecipe): class LeMonde(BasicNewsRecipe):
title = 'Le Monde' title = 'Le Monde'
__author__ = 'veezh' __author__ = 'veezh'
@ -20,100 +25,24 @@ class LeMonde(BasicNewsRecipe):
category = 'news, France, world' category = 'news, France, world'
language = 'fr' language = 'fr'
extra_css = ''' extra_css = '''
h1{font-size:130%;} img{max-width:100%}
h2{font-size:100%;} h1{font-size:1.2em !important; line-height:1.2em !important; }
blockquote.aside {background-color: #DDD; padding: 0.5em;} h2{font-size:1em !important; line-height:1em !important; }
.ariane{font-size:xx-small;} h3{font-size:1em !important; text-transform:uppercase !important; color:#666;}
.source{font-size:xx-small;} #photo{text-align:center !important; margin:10px 0 -8px;}
/*.href{font-size:xx-small;}*/ #lgd{font-size:1em !important; line-height:1em !important; font-style:italic; color:#333;} '''
/*.figcaption style{color:#666666; font-size:x-small;}*/
/*.main-article-info{font-family:Arial,Helvetica,sans-serif;}*/
/*full-contents{font-size:small; font-family:Arial,Helvetica,sans-serif;font-weight:normal;}*/
/*match-stats-summary{font-size:small; font-family:Arial,Helvetica,sans-serif;font-weight:normal;}*/
'''
conversion_options = {
'comments': description, 'tags': category, 'language': language, 'publisher': publisher, 'linearize_tables': True
}
remove_empty_feeds = True
filterDuplicates = True
def preprocess_html(self, soup):
for aside in soup.findAll('aside'):
aside.name = 'blockquote'
aside['class'] = "aside"
for alink in soup.findAll('a'):
if alink.string is not None:
tstr = alink.string
alink.replaceWith(tstr)
return soup
preprocess_regexps = [
(re.compile(r'([0-9])%'), lambda m: m.group(1) + ' %'),
(re.compile(r'([0-9])([0-9])([0-9]) ([0-9])([0-9])([0-9])'), lambda m: m.group(
1) + m.group(2) + m.group(3) + ' ' + m.group(4) + m.group(5) + m.group(6)),
(re.compile(r'([0-9]) ([0-9])([0-9])([0-9])'), lambda m: m.group(1) +
' ' + m.group(2) + m.group(3) + m.group(4)),
(re.compile(r'<span>'), lambda match: ' <span>'),
(re.compile(r'\("'), lambda match: '(&laquo;&nbsp;'),
(re.compile(r'"\)'), lambda match: '&nbsp;&raquo;)'),
(re.compile(r'&ldquo;'), lambda match: '(&laquo;&nbsp;'),
(re.compile(r'&rdquo;'), lambda match: '&nbsp;&raquo;)'),
(re.compile(r'>\''), lambda match: '>&lsquo;'),
(re.compile(r' \''), lambda match: ' &lsquo;'),
(re.compile(r' &quot;'), lambda match: ' &laquo;&nbsp;'),
(re.compile(r'>&quot;'), lambda match: '>&laquo;&nbsp;'),
(re.compile(r'&quot;<'), lambda match: '&nbsp;&raquo;<'),
(re.compile(r'&quot; '), lambda match: '&nbsp;&raquo; '),
(re.compile(r'&quot;,'), lambda match: '&nbsp;&raquo;,'),
(re.compile(r'\''), lambda match: '&rsquo;'),
(re.compile(r'"<em>'), lambda match: '<em>&laquo;&nbsp;'),
(re.compile(r'"<em>"</em><em>'), lambda match: '<em>&laquo;&nbsp;'),
(re.compile(r'"<a href='), lambda match: '&laquo;&nbsp;<a href='),
(re.compile(r'</em>"'), lambda match: '&nbsp;&raquo;</em>'),
(re.compile(r'</a>"'), lambda match: '&nbsp;&raquo;</a>'),
(re.compile(r'"</'), lambda match: '&nbsp;&raquo;</'),
(re.compile(r'>"'), lambda match: '>&laquo;&nbsp;'),
(re.compile(r'"<'), lambda match: '&nbsp;&raquo;<'),
(re.compile(r'&rsquo;"'), lambda match: '&rsquo;«&nbsp;'),
(re.compile(r' "'), lambda match: ' &laquo;&nbsp;'),
(re.compile(r'" '), lambda match: '&nbsp;&raquo; '),
(re.compile(r'"\.'), lambda match: '&nbsp;&raquo;.'),
(re.compile(r'",'), lambda match: '&nbsp;&raquo;,'),
(re.compile(r'"\?'), lambda match: '&nbsp;&raquo;?'),
(re.compile(r'":'), lambda match: '&nbsp;&raquo;:'),
(re.compile(r'";'), lambda match: '&nbsp;&raquo;;'),
(re.compile(r'"\!'), lambda match: '&nbsp;&raquo;!'),
(re.compile(r' :'), lambda match: '&nbsp;:'),
(re.compile(r' ;'), lambda match: '&nbsp;;'),
(re.compile(r' \?'), lambda match: '&nbsp;?'),
(re.compile(r' \!'), lambda match: '&nbsp;!'),
(re.compile(r'\s»'), lambda match: '&nbsp;»'),
(re.compile(r'«\s'), lambda match: '«&nbsp;'),
(re.compile(r' %'), lambda match: '&nbsp;%'),
(re.compile(r'\.jpg&nbsp;&raquo; width='), lambda match: '.jpg'),
(re.compile(r'\.png&nbsp;&raquo; width='), lambda match: '.png'),
(re.compile(r' &ndash; '), lambda match: '&nbsp;&ndash; '),
(re.compile(r'figcaption style="display:none"'), lambda match: 'figcaption'),
(re.compile(r' '), lambda match: '&nbsp;&ndash; '),
(re.compile(r' - '), lambda match: '&nbsp;&ndash; '),
(re.compile(r' -,'), lambda match: '&nbsp;&ndash;,'),
(re.compile(r'&raquo;:'), lambda match: '&raquo;&nbsp;:'),
]
keep_only_tags = [ keep_only_tags = [
dict(name='article', attrs={}) dict(itemprop=['Headline', 'description']),
classes('bloc_signature'),
dict(itemprop=['articleBody']),
] ]
remove_empty_feeds = True
remove_tags = [ def preprocess_html(self, soup):
dict(attrs={'class': ['rubriques_liees']}), for lgd in soup.findAll(id="lgd"):
dict(attrs={'class': ['sociaux']}), lgd.contents[-1].extract()
dict(attrs={'class': ['bloc_base meme_sujet']}), return soup
dict(name='p', attrs={'class': ['lire']})
]
remove_tags_after = [dict(id='fb-like')]
def get_article_url(self, article): def get_article_url(self, article):
url = article.get('guid', None) url = article.get('guid', None)
@ -121,11 +50,6 @@ class LeMonde(BasicNewsRecipe):
url = None url = None
return url return url
# def get_article_url(self, article):
# link = article.get('link')
# if 'blog' not in link and ('chat' not in link):
# return link
feeds = [ feeds = [
('A la une', 'http://www.lemonde.fr/rss/une.xml'), ('A la une', 'http://www.lemonde.fr/rss/une.xml'),
('International', 'http://www.lemonde.fr/rss/tag/international.xml'), ('International', 'http://www.lemonde.fr/rss/tag/international.xml'),

View File

@ -11,6 +11,12 @@ from calibre.ptempfile import PersistentTemporaryFile
from urllib2 import HTTPError from urllib2 import HTTPError
def classes(classes):
q = frozenset(classes.split(' '))
return dict(attrs={
'class': lambda x: x and frozenset(x.split()).intersection(q)})
class LeMonde(BasicNewsRecipe): class LeMonde(BasicNewsRecipe):
title = u'Le Monde: Édition abonnés' title = u'Le Monde: Édition abonnés'
@ -35,7 +41,11 @@ class LeMonde(BasicNewsRecipe):
#photo{text-align:center !important; margin:10px 0 -8px;} #photo{text-align:center !important; margin:10px 0 -8px;}
#lgd{font-size:1em !important; line-height:1em !important; font-style:italic; color:#333;} ''' #lgd{font-size:1em !important; line-height:1em !important; font-style:italic; color:#333;} '''
keep_only_tags = [dict(name=['h1', 'h2', 'h3', 'div', 'txt'])] keep_only_tags = [
dict(itemprop=['Headline', 'description']),
classes('bloc_signature'),
dict(itemprop=['articleBody']),
]
def __init__(self, options, log, progress_reporter): def __init__(self, options, log, progress_reporter):
BasicNewsRecipe.__init__(self, options, log, progress_reporter) BasicNewsRecipe.__init__(self, options, log, progress_reporter)