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

  1. __license__   = 'GPL v3'
  2. __copyright__ = '2011, Darko Miletic <darko.miletic at gmail.com>'
  3. '''
  4. techcrunch.com
  5. '''
  6.  
  7. from calibre.web.feeds.news import BasicNewsRecipe
  8.  
  9. class TechCrunch(BasicNewsRecipe):
  10.     title                 = 'TechCrunch'
  11.     __author__            = 'Darko Miletic'
  12.     description           = 'IT News'
  13.     publisher             = 'AOL Inc.'
  14.     category              = 'news, IT'
  15.     oldest_article        = 2
  16.     max_articles_per_feed = 200
  17.     no_stylesheets        = True
  18.     encoding              = 'utf8'
  19.     use_embedded_content  = False
  20.     language              = 'en'
  21.     remove_empty_feeds    = True
  22.     publication_type      = 'newsportal'
  23.     masthead_url          = 'http://s2.wp.com/wp-content/themes/vip/tctechcrunch2/images/site-logo.png'
  24.     extra_css             = """
  25.                                body{font-family: Helvetica,Arial,sans-serif }
  26.                                img{margin-bottom: 0.4em; display:block}
  27.                             """
  28.  
  29.     conversion_options = {
  30.                           'comment'   : description
  31.                         , 'tags'      : category
  32.                         , 'publisher' : publisher
  33.                         , 'language'  : language
  34.                         }
  35.  
  36.     remove_tags = [dict(name=['meta','link'])]
  37.     remove_attributes=['lang']
  38.     keep_only_tags=[
  39.                       dict(name='h1', attrs={'class':'headline'})
  40.                      ,dict(attrs={'class':['author','post-time','body-copy']})
  41.                    ]
  42.  
  43.     feeds = [(u'News', u'http://feeds.feedburner.com/TechCrunch/')]
  44.  
  45.     def preprocess_html(self, soup):
  46.         for item in soup.findAll(style=True):
  47.             del item['style']
  48.         for item in soup.findAll('a'):
  49.             limg = item.find('img')
  50.             if item.string is not None:
  51.                str = item.string
  52.                item.replaceWith(str)
  53.             else:
  54.                if limg:
  55.                   item.name = 'div'
  56.                   item.attrs = []
  57.                else:
  58.                    str = self.tag_to_string(item)
  59.                    item.replaceWith(str)
  60.         for item in soup.findAll('img'):
  61.             if not item.has_key('alt'):
  62.                item['alt'] = 'image'            
  63.         return soup
  64.