diff --git a/recipes/le_monde.recipe b/recipes/le_monde.recipe index 4a26ca65dc..c597f32586 100644 --- a/recipes/le_monde.recipe +++ b/recipes/le_monde.recipe @@ -3,10 +3,15 @@ __copyright__ = '2012' ''' lemonde.fr ''' -import re 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): title = 'Le Monde' __author__ = 'veezh' @@ -20,100 +25,24 @@ class LeMonde(BasicNewsRecipe): category = 'news, France, world' language = 'fr' extra_css = ''' - h1{font-size:130%;} - h2{font-size:100%;} - blockquote.aside {background-color: #DDD; padding: 0.5em;} - .ariane{font-size:xx-small;} - .source{font-size:xx-small;} - /*.href{font-size:xx-small;}*/ - /*.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''), lambda match: ' '), - (re.compile(r'\("'), lambda match: '(« '), - (re.compile(r'"\)'), lambda match: ' »)'), - (re.compile(r'“'), lambda match: '(« '), - (re.compile(r'”'), lambda match: ' »)'), - (re.compile(r'>\''), lambda match: '>‘'), - (re.compile(r' \''), lambda match: ' ‘'), - (re.compile(r' "'), lambda match: ' « '), - (re.compile(r'>"'), lambda match: '>« '), - (re.compile(r'"<'), lambda match: ' »<'), - (re.compile(r'" '), lambda match: ' » '), - (re.compile(r'",'), lambda match: ' »,'), - (re.compile(r'\''), lambda match: '’'), - (re.compile(r'"'), lambda match: '« '), - (re.compile(r'""'), lambda match: '« '), - (re.compile(r'""'), lambda match: ' »'), - (re.compile(r'"'), lambda match: ' »'), - (re.compile(r'""'), lambda match: '>« '), - (re.compile(r'"<'), lambda match: ' »<'), - (re.compile(r'’"'), lambda match: '’« '), - (re.compile(r' "'), lambda match: ' « '), - (re.compile(r'" '), lambda match: ' » '), - (re.compile(r'"\.'), lambda match: ' ».'), - (re.compile(r'",'), lambda match: ' »,'), - (re.compile(r'"\?'), lambda match: ' »?'), - (re.compile(r'":'), lambda match: ' »:'), - (re.compile(r'";'), lambda match: ' »;'), - (re.compile(r'"\!'), lambda match: ' »!'), - (re.compile(r' :'), lambda match: ' :'), - (re.compile(r' ;'), lambda match: ' ;'), - (re.compile(r' \?'), lambda match: ' ?'), - (re.compile(r' \!'), lambda match: ' !'), - (re.compile(r'\s»'), lambda match: ' »'), - (re.compile(r'«\s'), lambda match: '« '), - (re.compile(r' %'), lambda match: ' %'), - (re.compile(r'\.jpg » width='), lambda match: '.jpg'), - (re.compile(r'\.png » width='), lambda match: '.png'), - (re.compile(r' – '), lambda match: ' – '), - (re.compile(r'figcaption style="display:none"'), lambda match: 'figcaption'), - (re.compile(r' – '), lambda match: ' – '), - (re.compile(r' - '), lambda match: ' – '), - (re.compile(r' -,'), lambda match: ' –,'), - (re.compile(r'»:'), lambda match: '» :'), - ] + img{max-width:100%} + h1{font-size:1.2em !important; line-height:1.2em !important; } + h2{font-size:1em !important; line-height:1em !important; } + h3{font-size:1em !important; text-transform:uppercase !important; color:#666;} + #photo{text-align:center !important; margin:10px 0 -8px;} + #lgd{font-size:1em !important; line-height:1em !important; font-style:italic; color:#333;} ''' keep_only_tags = [ - dict(name='article', attrs={}) + dict(itemprop=['Headline', 'description']), + classes('bloc_signature'), + dict(itemprop=['articleBody']), ] + remove_empty_feeds = True - remove_tags = [ - dict(attrs={'class': ['rubriques_liees']}), - dict(attrs={'class': ['sociaux']}), - dict(attrs={'class': ['bloc_base meme_sujet']}), - dict(name='p', attrs={'class': ['lire']}) - ] - - remove_tags_after = [dict(id='fb-like')] + def preprocess_html(self, soup): + for lgd in soup.findAll(id="lgd"): + lgd.contents[-1].extract() + return soup def get_article_url(self, article): url = article.get('guid', None) @@ -121,11 +50,6 @@ class LeMonde(BasicNewsRecipe): url = None 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 = [ ('A la une', 'http://www.lemonde.fr/rss/une.xml'), ('International', 'http://www.lemonde.fr/rss/tag/international.xml'), diff --git a/recipes/le_monde_sub.recipe b/recipes/le_monde_sub.recipe index 7b19a0cea4..2b0f264d1e 100644 --- a/recipes/le_monde_sub.recipe +++ b/recipes/le_monde_sub.recipe @@ -11,6 +11,12 @@ from calibre.ptempfile import PersistentTemporaryFile 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): title = u'Le Monde: Édition abonnés' @@ -35,7 +41,11 @@ class LeMonde(BasicNewsRecipe): #photo{text-align:center !important; margin:10px 0 -8px;} #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): BasicNewsRecipe.__init__(self, options, log, progress_reporter)