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

  1. __license__   = 'GPL v3'
  2. __copyright__ = '2010-2011, Darko Miletic <darko.miletic at gmail.com>'
  3. '''
  4. nrc.nl
  5. '''
  6.  
  7. from calibre.web.feeds.news import BasicNewsRecipe
  8.  
  9. class Pagina12(BasicNewsRecipe):
  10.     title                 = 'NRC'
  11.     __author__            = 'Darko Miletic'
  12.     description           = 'News from Netherlands'
  13.     publisher             = 'nrc.nl'
  14.     category              = 'news, politics, Netherlands'
  15.     oldest_article        = 2
  16.     max_articles_per_feed = 200
  17.     no_stylesheets        = True
  18.     encoding              = 'utf8'
  19.     use_embedded_content  = False
  20.     language              = 'nl'
  21.     country               = 'NL'
  22.     remove_empty_feeds    = True
  23.     masthead_url          = 'http://www.nrc.nl/nrc.nl/images/logo_nrc.png'
  24.     extra_css             = """
  25.                                 body{font-family: Georgia,serif }
  26.                                 img{margin-bottom: 0.4em; display: block}
  27.                                 .bijschrift,.sectie{font-size: x-small}
  28.                                 .sectie{color: gray}
  29.                             """
  30.  
  31.     conversion_options = {
  32.                           'comment'   : description
  33.                         , 'tags'      : category
  34.                         , 'publisher' : publisher
  35.                         , 'language'  : language
  36.                         }
  37.  
  38.     keep_only_tags = [dict(attrs={'class':'uitstekendekeus'})]
  39.     remove_tags    = [
  40.                         dict(name=['meta','base','link','object','embed'])
  41.                        ,dict(attrs={'class':['reclamespace','tags-and-sharing','sharing-is-caring']})
  42.                      ]
  43.     remove_attributes=['lang']
  44.  
  45.     feeds = [
  46.               (u'Voor nieuws', u'http://www.nrc.nl/nieuws/categorie/nieuws/rss.php'           )
  47.              ,(u'Binnenland' , u'http://www.nrc.nl/nieuws/categorie/binnenland/rss.php'       )
  48.              ,(u'Buitenland' , u'http://www.nrc.nl/nieuws/categorie/buitenland/rss.php'       )
  49.              ,(u'Economie'   , u'http://www.nrc.nl/nieuws/categorie/economie/rss.php'         )
  50.              ,(u'Cultuur'    , u'http://www.nrc.nl/nieuws/categorie/cultuur/rss.php'          )
  51.              ,(u'Sport'      , u'http://www.nrc.nl/nieuws/categorie/sport/rss.php'            )
  52.              ,(u'Wetenschap ', u'http://www.nrc.nl/nieuws/categorie/wetenschap-nieuws/rss.php')
  53.             ]
  54.  
  55.     def preprocess_html(self, soup):
  56.         for item in soup.findAll(style=True):
  57.             del item['style']
  58.         for item in soup.findAll('a'):
  59.             limg = item.find('img')
  60.             if item.string is not None:
  61.                str = item.string
  62.                item.replaceWith(str)
  63.             else:
  64.                if limg:
  65.                   item.name = 'div'
  66.                   atritems =['href','target','rel']
  67.                   for atit in atritems:
  68.                       if item.has_key(atit):
  69.                          del item[atit]
  70.                else:
  71.                    str = self.tag_to_string(item)
  72.                    item.replaceWith(str)
  73.         for item in soup.findAll('img'):
  74.             if not item.has_key('alt'):
  75.                item['alt'] = 'image'
  76.         return soup
  77.