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

  1. __license__   = 'GPL v3'
  2. __copyright__ = '2009, Mathieu Godlewski <mathieu at godlewski.fr>; 2010, Louis Gesbert <meta at antislash dot info>'
  3. '''
  4. Mediapart
  5. '''
  6.  
  7. from calibre.ebooks.BeautifulSoup import Tag
  8. from calibre.web.feeds.news import BasicNewsRecipe
  9.  
  10. class Mediapart(BasicNewsRecipe):
  11.     title          = 'Mediapart'
  12.     __author__ = 'Mathieu Godlewski'
  13.     description = 'Global news in french from online newspapers'
  14.     oldest_article = 7
  15.     language = 'fr'
  16.     needs_subscription = True
  17.  
  18.     max_articles_per_feed = 50
  19.     no_stylesheets = True
  20.  
  21.     cover_url = 'http://www.mediapart.fr/sites/all/themes/mediapart/mediapart/images/annonce.jpg'
  22.  
  23.     feeds =  [
  24.         ('Les articles', 'http://www.mediapart.fr/articles/feed'),
  25.     ]
  26.  
  27. # -- print-version has poor quality on this website, better do the conversion ourselves
  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'<span class=\'auteur_staff\'>[^>]+<a title=\'[^\']*\'[^>]*>([^<]*)</a>[^<]*</span>',
  33. #              lambda match : '<i>'+match.group(1)+'</i>'),
  34. #             (r'\'', 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. #                        dict(name='br') ]
  42. #
  43. #     def print_version(self, url):
  44. #         raw = self.browser.open(url).read()
  45. #         soup = BeautifulSoup(raw.decode('utf8', 'replace'))
  46. #         div = soup.find('div', {'id':re.compile('node-\d+')})
  47. #         if div is None:
  48. #             return None
  49. #         article_id = string.replace(div['id'], 'node-', '')
  50. #         if article_id is None:
  51. #             return None
  52. #         return 'http://www.mediapart.fr/print/'+article_id
  53.  
  54. # -- Non-print version [dict(name='div', attrs={'class':'advert'})]
  55.  
  56.     keep_only_tags = [
  57.         dict(name='h1', attrs={'class':'title'}),
  58.         dict(name='div', attrs={'class':'page_papier_detail'}),
  59.         ]
  60.  
  61.     def preprocess_html(self,soup):
  62.         for title in soup.findAll('div', {'class':'titre'}):
  63.             tag = Tag(soup, 'h3')
  64.             title.replaceWith(tag)
  65.             tag.insert(0,title)
  66.         return soup
  67.  
  68. # -- Handle login
  69.  
  70.     def get_browser(self):
  71.         br = BasicNewsRecipe.get_browser()
  72.         if self.username is not None and self.password is not None:
  73.             br.open('http://www.mediapart.fr/')
  74.             br.select_form(nr=0)
  75.             br['name'] = self.username
  76.             br['pass'] = self.password
  77.             br.submit()
  78.         return br
  79.  
  80.