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

  1. __license__   = 'GPL v3'
  2. __copyright__ = '2010, 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             = ' h1{font-family: Georgia,"Times New Roman",Times,serif } body{font-family: Arial,Helvetica,sans-serif} .cT-imageLandscape{font-size: x-small} '
  26.  
  27.     conversion_options = {
  28.                           'comment'   : description
  29.                         , 'tags'      : category
  30.                         , 'publisher' : publisher
  31.                         , 'language'  : language
  32.                         }
  33.  
  34.     remove_tags = [
  35.                      dict(name='div', attrs={'id':['googleAds','moreGoogleAds','comments']})
  36.                     ,dict(name='div', attrs={'class':'cT-imageMultimedia'})
  37.                     ,dict(name=['object','embed','iframe'])
  38.                   ]
  39.     remove_tags_after = [dict(name='div',attrs={'class':'articleBody'})]
  40.     keep_only_tags    = [dict(name='div',attrs={'id':'content'})]
  41.     remove_attributes = ['width','height']
  42.  
  43.     def parse_index(self):
  44.         articles = []
  45.         rawc = self.index_to_soup('http://www.smh.com.au/todays-paper',True)
  46.         soup = BeautifulSoup(rawc,fromEncoding=self.encoding)
  47.         for itimg in soup.findAll('img',src=True):
  48.             if itimg['src'].endswith('frontpage.jpg'):
  49.                self.cover_url = itimg['src']
  50.  
  51.         for item in soup.findAll(attrs={'class':'cN-storyHeadlineLead cfix'}):
  52.             description = ''
  53.             title_prefix = ''
  54.             feed_link = item.find('a',href=True)
  55.             descript = item.find('p')
  56.             if descript:
  57.                description = self.tag_to_string(descript)
  58.             if feed_link:
  59.                 url   = feed_link['href']
  60.                 title = title_prefix + self.tag_to_string(feed_link)
  61.                 date  = strftime(self.timefmt)
  62.                 articles.append({
  63.                                   'title'      :title
  64.                                  ,'date'       :date
  65.                                  ,'url'        :url
  66.                                  ,'description':description
  67.                                 })
  68.         return [(self.tag_to_string(soup.find('title')), articles)]
  69.