home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Calibre / calibre-0.8.18.msi / file_280 / le_monde.recipe < prev    next >
Text File  |  2011-09-09  |  7KB  |  140 lines

  1. __license__   = 'GPL v3'
  2. __copyright__ = '2011'
  3. '''
  4. lemonde.fr
  5. '''
  6. import re
  7. from calibre.web.feeds.recipes import BasicNewsRecipe
  8.  
  9. class LeMonde(BasicNewsRecipe):
  10.     title                  = 'Le Monde'
  11.     __author__             = 'veezh'
  12.     description            = 'Actualit├⌐s'
  13.     oldest_article         = 1
  14.     max_articles_per_feed  = 100
  15.     no_stylesheets         = True
  16.     #delay                  = 1
  17.     use_embedded_content   = False
  18.     encoding               = 'cp1252'
  19.     publisher              = 'lemonde.fr'
  20.     category               = 'news, France, world'
  21.     language               = 'fr'
  22.     #publication_type       = 'newsportal'
  23.     extra_css = '''
  24.                     h1{font-size:130%;}
  25.                     .ariane{font-size:xx-small;}
  26.                     .source{font-size:xx-small;}
  27.                     #.href{font-size:xx-small;}
  28.                     .LM_caption{color:#666666; font-size:x-small;}
  29.                     #.main-article-info{font-family:Arial,Helvetica,sans-serif;}
  30.                     #full-contents{font-size:small; font-family:Arial,Helvetica,sans-serif;font-weight:normal;}
  31.                     #match-stats-summary{font-size:small; font-family:Arial,Helvetica,sans-serif;font-weight:normal;}
  32.                 '''
  33.     #preprocess_regexps     = [(re.compile(r'<!--.*?-->', re.DOTALL), lambda m: '')]
  34.     conversion_options = {
  35.                               'comments'        : description
  36.                              ,'tags'            : category
  37.                              ,'language'        : language
  38.                              ,'publisher'       : publisher
  39.                              ,'linearize_tables': True
  40.                           }
  41.  
  42.     remove_empty_feeds = True
  43.  
  44.     filterDuplicates = True
  45.  
  46.     def preprocess_html(self, soup):
  47.         for alink in soup.findAll('a'):
  48.             if alink.string is not None:
  49.                tstr = alink.string
  50.                alink.replaceWith(tstr)
  51.         return self.adeify_images(soup)
  52.  
  53.     preprocess_regexps = [
  54.         (re.compile(r'([0-9])%'), lambda m: m.group(1) + ' %'),
  55.         (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)),
  56.         (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)),
  57.         (re.compile(r'<span>'), lambda match: ' <span>'),
  58.         (re.compile(r'\("'), lambda match: '(« '),
  59.         (re.compile(r'"\)'), lambda match: ' »)'),
  60.         (re.compile(r'“'), lambda match: '(« '),
  61.         (re.compile(r'”'), lambda match: ' »)'),
  62.         (re.compile(r'>\''), lambda match: '>‘'),
  63.         (re.compile(r' \''), lambda match: ' ‘'),
  64.         (re.compile(r'\''), lambda match: '’'),
  65.         (re.compile(r'"<em>'), lambda match: '<em>« '),
  66.         (re.compile(r'"<em>"</em><em>'), lambda match: '<em>« '),
  67.         (re.compile(r'"<a href='), lambda match: '« <a href='),
  68.         (re.compile(r'</em>"'), lambda match: ' »</em>'),
  69.         (re.compile(r'</a>"'), lambda match: ' »</a>'),
  70.         (re.compile(r'"</'), lambda match: ' »</'),
  71.         (re.compile(r'>"'), lambda match: '>« '),
  72.         (re.compile(r'"<'), lambda match: ' »<'),
  73.         (re.compile(r'’"'), lambda match: '’┬½ '),
  74.         (re.compile(r' "'), lambda match: ' « '),
  75.         (re.compile(r'" '), lambda match: ' » '),
  76.         (re.compile(r'"\.'), lambda match: ' ».'),
  77.         (re.compile(r'",'), lambda match: ' »,'),
  78.         (re.compile(r'"\?'), lambda match: ' »?'),
  79.         (re.compile(r'":'), lambda match: ' »:'),
  80.         (re.compile(r'";'), lambda match: ' »;'),
  81.         (re.compile(r'"\!'), lambda match: ' »!'),
  82.         (re.compile(r' :'), lambda match: ' :'),
  83.         (re.compile(r' ;'), lambda match: ' ;'),
  84.         (re.compile(r' \?'), lambda match: ' ?'),
  85.         (re.compile(r' \!'), lambda match: ' !'),
  86.         (re.compile(r'\s┬╗'), lambda match: ' ┬╗'),
  87.         (re.compile(r'┬½\s'), lambda match: '┬½ '),
  88.         (re.compile(r' %'), lambda match: ' %'),
  89.         (re.compile(r'\.jpg » border='), lambda match: '.jpg'),
  90.         (re.compile(r'\.png » border='), lambda match: '.png'),
  91.         (re.compile(r' – '), lambda match: ' – '),
  92.         (re.compile(r' ΓÇô '), lambda match: ' – '),
  93.         (re.compile(r' - '), lambda match: ' – '),
  94.         (re.compile(r' -,'), lambda match: ' –,'),
  95.         (re.compile(r'»:'), lambda match: '» :'),
  96.         ]
  97.  
  98.  
  99.     keep_only_tags    = [
  100.                        dict(name='div', attrs={'class':['contenu']})
  101.                         ]
  102.     remove_tags = [dict(name='div', attrs={'class':['LM_atome']})]
  103.     remove_tags_after = [dict(id='appel_temoignage')]
  104.  
  105.     def get_article_url(self, article):
  106.           url = article.get('guid', None)
  107.           if '/chat/' in url or '.blog' in url or '/video/' in url or '/sport/' in url or '/portfolio/' in url or '/visuel/' in url :
  108.               url = None
  109.           return url
  110.  
  111. #    def get_article_url(self, article):
  112. #        link = article.get('link')
  113. #        if 'blog' not in link and ('chat' not in link):
  114. #             return link
  115.  
  116.     feeds          = [
  117.                       ('A la une', 'http://www.lemonde.fr/rss/une.xml'),
  118.                       ('International', 'http://www.lemonde.fr/rss/tag/international.xml'),
  119.                       ('Europe', 'http://www.lemonde.fr/rss/tag/europe.xml'),
  120.                       (u'Soci├⌐t├⌐', 'http://www.lemonde.fr/rss/tag/societe.xml'),
  121.                       ('Economie', 'http://www.lemonde.fr/rss/tag/economie.xml'),
  122.                       (u'M├⌐dias', 'http://www.lemonde.fr/rss/tag/actualite-medias.xml'),
  123.                       (u'Plan├¿te', 'http://www.lemonde.fr/rss/tag/planete.xml'),
  124.                       ('Culture', 'http://www.lemonde.fr/rss/tag/culture.xml'),
  125.                       ('Technologies', 'http://www.lemonde.fr/rss/tag/technologies.xml'),
  126.                       ('Livres', 'http://www.lemonde.fr/rss/tag/livres.xml'),
  127.  
  128.                     ]
  129.  
  130.     def get_cover_url(self):
  131.         cover_url = None
  132.         soup = self.index_to_soup('http://www.lemonde.fr/web/monde_pdf/0,33-0,1-0,0.html')
  133.         link_item = soup.find('div',attrs={'class':'pg-gch'})
  134.  
  135.         if link_item and link_item.img:
  136.            cover_url = link_item.img['src']
  137.  
  138.         return cover_url
  139.  
  140.