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

  1. from __future__ import with_statement
  2. __license__ = 'GPL 3'
  3. __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
  4.  
  5. import time
  6. from calibre.web.feeds.news import BasicNewsRecipe
  7.  
  8. class TheHindu(BasicNewsRecipe):
  9.     title                 = u'The Hindu'
  10.     language = 'en_IN'
  11.  
  12.     oldest_article        = 7
  13.     __author__            = 'Kovid Goyal'
  14.     max_articles_per_feed = 100
  15.     no_stylesheets = True
  16.  
  17.     keep_only_tags = [dict(id='content')]
  18.     remove_tags = [dict(attrs={'class':['article-links', 'breadcr']}),
  19.             dict(id=['email-section', 'right-column', 'printfooter'])]
  20.  
  21.     extra_css = '.photo-caption { font-size: smaller }'
  22.  
  23.     def postprocess_html(self, soup, first_fetch):
  24.         for t in soup.findAll(['table', 'tr', 'td','center']):
  25.             t.name = 'div'
  26.         return soup
  27.  
  28.     def parse_index(self):
  29.         today = time.strftime('%Y-%m-%d')
  30.         soup = self.index_to_soup(
  31.                 'http://www.thehindu.com/todays-paper/tp-index/?date=' + today)
  32.         div = soup.find(id='left-column')
  33.         feeds = []
  34.         current_section = None
  35.         current_articles = []
  36.         for x in div.findAll(['h3', 'div']):
  37.             if current_section and x.get('class', '') == 'tpaper':
  38.                 a = x.find('a', href=True)
  39.                 if a is not None:
  40.                     current_articles.append({'url':a['href']+'?css=print',
  41.                         'title':self.tag_to_string(a), 'date': '',
  42.                         'description':''})
  43.             if x.name == 'h3':
  44.                 if current_section and current_articles:
  45.                     feeds.append((current_section, current_articles))
  46.                 current_section = self.tag_to_string(x)
  47.                 current_articles = []
  48.         return feeds
  49.  
  50.  
  51.