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

  1. __license__   = 'GPL v3'
  2. __copyright__ = '2010-2011, Darko Miletic <darko.miletic at gmail.com>'
  3. '''
  4. smh.com.au
  5. '''
  6. from calibre import strftime
  7. from calibre.web.feeds.news import BasicNewsRecipe
  8. from calibre.ebooks.BeautifulSoup import BeautifulSoup
  9.  
  10. class Smh_au(BasicNewsRecipe):
  11.     title                 = 'The Sydney Morning Herald - Printed edition'
  12.     __author__            = 'Darko Miletic'
  13.     description           = 'Breaking news from Sydney, Australia and the world. Features the latest business, sport, entertainment, travel, lifestyle, and technology news.'
  14.     publisher             = 'Fairfax Digital'
  15.     category              = 'news, politics, Australia, Sydney'
  16.     oldest_article        = 2
  17.     max_articles_per_feed = 200
  18.     no_stylesheets        = True
  19.     encoding              = 'utf-8'
  20.     use_embedded_content  = False
  21.     language              = 'en_AU'
  22.     remove_empty_feeds    = True
  23.     masthead_url          = 'http://images.smh.com.au/2010/02/02/1087188/smh-620.jpg'
  24.     publication_type      = 'newspaper'
  25.     extra_css             = """ 
  26.                                 h1{font-family: Georgia,"Times New Roman",Times,serif } 
  27.                                 body{font-family: Arial,Helvetica,sans-serif} 
  28.                                 .cT-imageLandscape,.cT-imagePortrait{font-size: x-small} 
  29.                             """
  30.  
  31.     conversion_options = {
  32.                           'comment'   : description
  33.                         , 'tags'      : category
  34.                         , 'publisher' : publisher
  35.                         , 'language'  : language
  36.                         }
  37.  
  38.     remove_tags = [
  39.                      dict(name='div', attrs={'id':['googleAds','moreGoogleAds','comments']})
  40.                     ,dict(name='div', attrs={'class':'cT-imageMultimedia'})
  41.                     ,dict(name=['object','embed','iframe'])
  42.                   ]
  43.     remove_tags_after = [dict(name='div',attrs={'class':'articleBody'})]
  44.     keep_only_tags    = [dict(name='div',attrs={'id':'content'})]
  45.     remove_tags       = [ 
  46.                           dict(attrs={'class':'hidden'}), 
  47.                           dict(name=['link','meta','base','embed','object','iframe'])
  48.                         ]
  49.     remove_attributes = ['width','height','lang']
  50.  
  51.     def parse_index(self):
  52.         articles = []
  53.         rawc = self.index_to_soup('http://www.smh.com.au/todays-paper',True)
  54.         soup = BeautifulSoup(rawc,fromEncoding=self.encoding)
  55.         for itimg in soup.findAll('img',src=True):
  56.             if itimg['src'].endswith('frontpage.jpg'):
  57.                self.cover_url = itimg['src']
  58.  
  59.         for item in soup.findAll(attrs={'class':'cN-storyHeadlineLead cfix'}):
  60.             description = ''
  61.             title_prefix = ''
  62.             feed_link = item.find('a',href=True)
  63.             descript = item.find('p')
  64.             if descript:
  65.                description = self.tag_to_string(descript)
  66.             if feed_link:
  67.                 url   = feed_link['href']
  68.                 title = title_prefix + 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.tag_to_string(soup.find('title')), articles)]
  77.  
  78.     def preprocess_html(self, soup):
  79.         for item in soup.findAll(style=True):
  80.             del item['style']
  81.         for item in soup.findAll('bod'):
  82.             item.name = 'div'
  83.         for item in soup.findAll('img'):
  84.             if not item.has_key('alt'):
  85.                item['alt'] = 'image'
  86.         return soup
  87.