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

  1. __license__   = 'GPL v3'
  2. __copyright__ = '2010, Louis Gesbert <meta at antislash dot info>'
  3. '''
  4. Rue89
  5. '''
  6.  
  7. __author__ = '2010, Louis Gesbert <meta at antislash dot info>'
  8.  
  9. import re
  10. from calibre.ebooks.BeautifulSoup import Tag
  11. from calibre.web.feeds.news import BasicNewsRecipe
  12.  
  13. class Rue89(BasicNewsRecipe):
  14.     title = 'Rue89'
  15.     __author__ = 'Louis Gesbert'
  16.     description = 'Popular free french news website'
  17.     title = u'Rue89'
  18.     language = 'fr'
  19.     oldest_article = 7
  20.     max_articles_per_feed = 50
  21.  
  22.     feeds = [(u'La Une', u'http://www.rue89.com/homepage/feed')]
  23.  
  24.     no_stylesheets = True
  25.  
  26.     preprocess_regexps = [
  27.         (re.compile(r'<(/?)h2>', re.IGNORECASE|re.DOTALL),
  28.          lambda match : '<'+match.group(1)+'h3>'),
  29.         (re.compile(r'<div class="print-title">([^>]+)</div>', re.IGNORECASE|re.DOTALL),
  30.          lambda match : '<h2>'+match.group(1)+'</h2>'),
  31.         (re.compile(r'<img[^>]+src="[^"]*/numeros/(\d+)[^0-9.">]*.gif"[^>]*/>', re.IGNORECASE|re.DOTALL),
  32.          lambda match : '<span style="font-family: Sans-serif; color: red; font-size:24pt; padding=2pt;">'+match.group(1)+'</span>'),
  33.         (re.compile(r'\''), lambda match: '’'),
  34.         ]
  35.  
  36.     def preprocess_html(self,soup):
  37.         body = Tag(soup, 'body')
  38.         title = soup.find('h1', {'class':'title'})
  39.         content = soup.find('div', {'class':'content'})
  40.         soup.body.replaceWith(body)
  41.         body.insert(0, title)
  42.         body.insert(1, content)
  43.         return soup
  44.  
  45.     remove_tags = [ #dict(name='div', attrs={'class':'print-source_url'}),
  46.                     #dict(name='div', attrs={'class':'print-links'}),
  47.                     #dict(name='img', attrs={'class':'print-logo'}),
  48.                     dict(name='div', attrs={'class':'content_top'}),
  49.                     dict(name='div', attrs={'id':'sidebar-left'}), ]
  50.  
  51. # -- print-version has poor quality on this website, better do the conversion ourselves
  52. #    def print_version(self, url):
  53. #        return re.sub('^.*-([0-9]+)$', 'http://www.rue89.com/print/\\1',url)
  54.