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

  1. __license__   = 'GPL v3'
  2. __copyright__ = '2010, Darko Miletic <darko.miletic at gmail.com>'
  3. '''
  4. scmp.com
  5. '''
  6.  
  7. import re
  8. from calibre.web.feeds.news import BasicNewsRecipe
  9.  
  10. class SCMP(BasicNewsRecipe):
  11.     title                 = 'South China Morning Post'
  12.     __author__            = 'llam'
  13.     description           = "SCMP.com, Hong Kong's premier online English daily provides exclusive up-to-date news, audio video news, podcasts, RSS Feeds, Blogs, breaking news, top stories, award winning news and analysis on Hong Kong and China."
  14.     publisher             = 'South China Morning Post Publishers Ltd.'
  15.     category              = 'SCMP, Online news, Hong Kong News, China news, Business news, English newspaper, daily newspaper, Lifestyle news, Sport news, Audio Video news, Asia news, World news, economy news, investor relations news, RSS Feeds'
  16.     oldest_article        = 2
  17.     delay                 = 1
  18.     max_articles_per_feed = 200
  19.     no_stylesheets        = True
  20.     encoding              = 'utf-8'
  21.     use_embedded_content  = False
  22.     language              = 'en_CN'
  23.     remove_empty_feeds    = True
  24.     needs_subscription    = True
  25.     publication_type      = 'newspaper'
  26.     masthead_url          = 'http://www.scmp.com/images/logo_scmp_home.gif'
  27.     extra_css             = ' body{font-family: Arial,Helvetica,sans-serif } '
  28.  
  29.     conversion_options = {
  30.                           'comment'   : description
  31.                         , 'tags'      : category
  32.                         , 'publisher' : publisher
  33.                         , 'language'  : language
  34.                         }
  35.  
  36.     def get_browser(self):
  37.         br = BasicNewsRecipe.get_browser()
  38.         #br.set_debug_http(True)
  39.         #br.set_debug_responses(True)
  40.         #br.set_debug_redirects(True)
  41.         if self.username is not None and self.password is not None:
  42.            br.open('http://www.scmp.com/portal/site/SCMP/')
  43.            br.select_form(name='loginForm')
  44.            br['Login'   ] = self.username
  45.            br['Password'] = self.password
  46.            br.submit()
  47.         return br
  48.  
  49.     remove_attributes=['width','height','border']
  50.  
  51.     keep_only_tags = [
  52.                         dict(attrs={'id':['ART','photoBox']})
  53.                        ,dict(attrs={'class':['article_label','article_byline','article_body']})
  54.                      ]
  55.  
  56.     preprocess_regexps = [
  57.        (re.compile(r'<P><table((?!<table).)*class="embscreen"((?!</table>).)*</table>', re.DOTALL|re.IGNORECASE),
  58.         lambda match: ''),
  59.     ]
  60.  
  61.     feeds = [
  62.               (u'Business'     , u'http://www.scmp.com/rss/business.xml'       )
  63.              ,(u'Hong Kong'    , u'http://www.scmp.com/rss/hong_kong.xml'      )
  64.              ,(u'China'        , u'http://www.scmp.com/rss/china.xml'          )
  65.              ,(u'Asia & World' , u'http://www.scmp.com/rss/news_asia_world.xml')
  66.              ,(u'Opinion'      , u'http://www.scmp.com/rss/opinion.xml'        )
  67.              ,(u'LifeSTYLE'    , u'http://www.scmp.com/rss/lifestyle.xml'      )
  68.              ,(u'Sport'        , u'http://www.scmp.com/rss/sport.xml'          )
  69.             ]
  70.  
  71.     def print_version(self, url):
  72.         rpart, sep, rest = url.rpartition('&')
  73.         return rpart #+ sep + urllib.quote_plus(rest)
  74.  
  75.     def preprocess_html(self, soup):
  76.         for item in soup.findAll(style=True):
  77.             del item['style']
  78.         items = soup.findAll(src="/images/label_icon.gif")
  79.         [item.extract() for item in items]
  80.         return self.adeify_images(soup)
  81.