home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_3902 < prev    next >
Encoding:
Text File  |  2009-10-14  |  1.7 KB  |  54 lines

  1. #!/usr/bin/env  python
  2.  
  3. __license__   = 'GPL v3'
  4. __copyright__ = '2009, Mathieu Godlewski <mathieu at godlewski.fr>'
  5. '''
  6. Mediapart
  7. '''
  8.  
  9. import re, string
  10. from calibre.ebooks.BeautifulSoup import BeautifulSoup
  11. from calibre.web.feeds.news import BasicNewsRecipe
  12.  
  13. class Mediapart(BasicNewsRecipe):
  14.     title          = 'Mediapart'
  15.     __author__ = 'Mathieu Godlewski <mathieu at godlewski.fr>'
  16.     description = 'Global news in french from online newspapers'
  17.     oldest_article = 7
  18.     language = 'fr'
  19.  
  20.     max_articles_per_feed = 50
  21.     no_stylesheets = True
  22.  
  23.     html2lrf_options = ['--base-font-size', '10']
  24.  
  25.     feeds =  [
  26.         ('Les articles', 'http://www.mediapart.fr/articles/feed'),
  27.     ]
  28.  
  29.     preprocess_regexps = [ (re.compile(i[0], re.IGNORECASE|re.DOTALL), i[1]) for i in
  30.         [
  31.             (r'<div class="print-title">([^>]+)</div>', lambda match : '<h2>'+match.group(1)+'</h2>'),
  32.             (r'<p>Mediapart\.fr</p>', lambda match : ''),
  33.             (r'<p[^>]*>[\s]*</p>', lambda match : ''),
  34.             (r'<p><a href="[^\.]+\.pdf">[^>]*</a></p>', lambda match : ''),
  35.         ]
  36.     ]
  37.  
  38.     remove_tags    = [ dict(name='div', attrs={'class':'print-source_url'}),
  39.                                   dict(name='div', attrs={'class':'print-links'}),
  40.                                   dict(name='img', attrs={'src':'entete_article.png'}),
  41.     ]
  42.  
  43.  
  44.     def print_version(self, url):
  45.         raw = self.browser.open(url).read()
  46.         soup = BeautifulSoup(raw.decode('utf8', 'replace'))
  47.         div = soup.find('div', {'class':'node node-type-article'})
  48.         if div is None:
  49.             return None
  50.         article_id = string.replace(div['id'], 'node-', '')
  51.         if article_id is None:
  52.             return None
  53.         return 'http://www.mediapart.fr/print/'+article_id
  54.