home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_3879 < prev    next >
Encoding:
Text File  |  2010-06-11  |  3.4 KB  |  78 lines

  1. __license__   = 'GPL v3'
  2. __copyright__ = '2008-2010, Darko Miletic <darko.miletic at gmail.com>'
  3. '''
  4. mondediplo.com
  5. '''
  6.  
  7. import urllib
  8. from calibre import strftime
  9. from calibre.web.feeds.news import BasicNewsRecipe
  10.  
  11. class LeMondeDiplomatiqueEn(BasicNewsRecipe):
  12.     title                  = 'Le Monde diplomatique - English edition'
  13.     __author__             = 'Darko Miletic'
  14.     description            = 'Real journalism making sense of the world around us'
  15.     publisher              = 'Le Monde diplomatique'
  16.     category               = 'news, politics, world'
  17.     no_stylesheets         = True
  18.     oldest_article         = 31
  19.     delay                  = 1
  20.     encoding               = 'utf-8'
  21.     needs_subscription     = True
  22.     masthead_url           = 'http://mondediplo.com/squelettes/pics/logo-30.gif'
  23.     publication_type       = 'magazine'
  24.     PREFIX                 = 'http://mondediplo.com/'
  25.     LOGIN                  = PREFIX + '2009/09/02congo'
  26.     INDEX                  = PREFIX + strftime('%Y/%m/')
  27.     use_embedded_content   = False
  28.     language               = 'en'
  29.     extra_css              = ' body{font-family: "Luxi sans","Lucida sans","Lucida Grande",Lucida,"Lucida Sans Unicode",sans-serif} .surtitre{font-size: 1.2em; font-variant: small-caps; margin-bottom: 0.5em} .chapo{font-size: 1.2em; font-weight: bold; margin: 1em 0 0.5em} .texte{font-family: Georgia,"Times New Roman",serif} h1{color: #990000} .notes{border-top: 1px solid #CCCCCC; font-size: 0.9em; line-height: 1.4em} '
  30.  
  31.     conversion_options = {
  32.                           'comment'          : description
  33.                         , 'tags'             : category
  34.                         , 'publisher'        : publisher
  35.                         , 'language'         : language
  36.                         }
  37.  
  38.     def get_browser(self):
  39.         br = BasicNewsRecipe.get_browser()
  40.         br.open(self.LOGIN)
  41.         if self.username is not None and self.password is not None:
  42.             data = urllib.urlencode({ 'login':self.username
  43.                                      ,'pass':self.password
  44.                                      ,'enter':'enter'
  45.                                    })
  46.             br.open(self.LOGIN,data)
  47.         return br
  48.  
  49.     keep_only_tags    =[  
  50.                           dict(name='div', attrs={'id':'contenu'})
  51.                         , dict(name='div',attrs={'class':'notes surlignable'})
  52.                         ]
  53.     remove_tags = [dict(name=['object','link','script','iframe','base'])]
  54.     remove_attributes = ['height','width']
  55.  
  56.     def parse_index(self):
  57.         articles = []
  58.         soup = self.index_to_soup(self.INDEX)
  59.         cnt = soup.find('div',attrs={'class':'som_num'})
  60.         for item in cnt.findAll('li'):
  61.             description = ''
  62.             feed_link = item.find('a')
  63.             desc = item.find('div',attrs={'class':'chapo'})
  64.             if desc:
  65.                description = desc.string
  66.             if feed_link and feed_link.has_key('href'):
  67.                 url   = self.PREFIX + feed_link['href'].partition('/../')[2]
  68.                 title = self.tag_to_string(feed_link)
  69.                 date  = strftime(self.timefmt)
  70.                 articles.append({
  71.                                   'title'      :title
  72.                                  ,'date'       :date
  73.                                  ,'url'        :url
  74.                                  ,'description':description
  75.                                 })
  76.         return [(self.title, articles)]
  77.  
  78.