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

  1. from calibre.web.feeds.news import BasicNewsRecipe
  2. #from calibre.ebooks.BeautifulSoup import BeautifulSoup, Tag
  3.  
  4. class MoneyControlRecipe(BasicNewsRecipe):
  5.     __license__  = 'GPL v3'
  6.     __author__ = 'kwetal'
  7.     language = 'en_IN'
  8.     locale = 'en_IN'
  9.     encoding = 'iso-8859-1'
  10.     version = 1
  11.  
  12.     title = u'Money Control'
  13.     publisher = u'moneycontrol.com'
  14.     category = u'News, Financial, India'
  15.     description = u'Financial news from India'
  16.  
  17.     oldest_article = 7
  18.     max_articles_per_feed = 100
  19.     use_embedded_content = False
  20.  
  21.     no_stylesheets = True
  22.     remove_javascript = True
  23.  
  24.     feeds = []
  25.     feeds.append((u'Latest News', u'http://www.moneycontrol.com/rss/latestnews.xml'))
  26.     feeds.append((u'All Stories', u'http://www.moneycontrol.com/rss/allstories.xml'))
  27.  
  28.     def print_version(self, url):
  29.         return url.replace('/stocksnews.php?', '/news_print.php?') + '&sr_no=0'
  30.  
  31.     # The articles contain really horrible html. More than one <body> and <head> section, not properly closed tags, lots and lots of
  32.     # <font> tags and some weird <o:p></o:p> markup that crashes the conversion to ebook. Needs some drastic sanitizing
  33.     '''def preprocess_html(self, soup):
  34.         freshSoup = BeautifulSoup('<html><head></head><body></body></html>')
  35.  
  36.         headline = soup.find('td', attrs = {'class': 'heading'})
  37.         if headline:
  38.             h1 = Tag(freshSoup, 'h1')
  39.             # Convert to string before adding it to the document!
  40.             h1.append(self.tag_to_string(headline))
  41.             freshSoup.body.append(h1)
  42.  
  43.         for p in soup.findAll('p'):
  44.             if p.has_key('class'):
  45.                 if p['class'] == 'MsoNormal':
  46.                     # We have some weird pagebreak marker here; it will not find all of them however
  47.                     continue
  48.  
  49.             para = Tag(freshSoup, 'p')
  50.             # Convert to string; this will loose all formatting but also all illegal markup
  51.             para.append(self.tag_to_string(p))
  52.  
  53.             freshSoup.body.append(para)
  54.  
  55.         return freshSoup
  56.     '''
  57.  
  58.