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

  1. import re
  2. from calibre.web.feeds.news import BasicNewsRecipe
  3.  
  4. class TimesOfIndia(BasicNewsRecipe):
  5.     title          = u'Times of India'
  6.     language       = 'en_IN'
  7.     __author__     = 'Kovid Goyal'
  8.     oldest_article = 1 #days
  9.     max_articles_per_feed = 25
  10.  
  11.     no_stylesheets = True
  12.     keep_only_tags = [{'class':['maintable12', 'prttabl']}]
  13.     remove_tags = [
  14.             dict(style=lambda x: x and 'float' in x),
  15.             {'class':['prvnxtbg', 'footbdrin', 'bcclftr']},
  16.     ]
  17.  
  18.     feeds          = [
  19. ('Top Stories',
  20.  'http://timesofindia.indiatimes.com/rssfeedstopstories.cms'),
  21. ('India',
  22.  'http://timesofindia.indiatimes.com/rssfeeds/-2128936835.cms'),
  23. ('World',
  24.  'http://timesofindia.indiatimes.com/rssfeeds/296589292.cms'),
  25. ('Mumbai',
  26.  'http://timesofindia.indiatimes.com/rssfeeds/-2128838597.cms'),
  27. ('Entertainment',
  28.  'http://timesofindia.indiatimes.com/rssfeeds/1081479906.cms'),
  29. ('Cricket',
  30.  'http://timesofindia.indiatimes.com/rssfeeds/4719161.cms'),
  31. ('Sunday TOI',
  32.  'http://timesofindia.indiatimes.com/rssfeeds/1945062111.cms'),
  33. ('Life and Style',
  34.  'http://timesofindia.indiatimes.com/rssfeeds/2886704.cms'),
  35. ('Business',
  36.  'http://timesofindia.indiatimes.com/rssfeeds/1898055.cms'),
  37. ('Mad Mad World',
  38.  'http://timesofindia.indiatimes.com/rssfeeds/2178430.cms'),
  39. ('Most Read',
  40.  'http://timesofindia.indiatimes.com/rssfeedmostread.cms')
  41. ]
  42.  
  43.     def get_article_url(self, article):
  44.         url = BasicNewsRecipe.get_article_url(self, article)
  45.         if '/0Ltimesofindia' in url:
  46.             url = url.partition('/0L')[-1]
  47.             url = url.replace('0B', '.').replace('0N', '.com').replace('0C',
  48.                     '/').replace('0E', '-')
  49.             url = 'http://' + url.rpartition('/')[0]
  50.             match = re.search(r'/([0-9a-zA-Z]+?)\.cms', url)
  51.             if match is not None:
  52.                 num = match.group(1)
  53.                 num = re.sub(r'[^0-9]', '', num)
  54.                 return ('http://timesofindia.indiatimes.com/articleshow/%s.cms?prtpage=1' %
  55.                     num)
  56.         else:
  57.             cms = re.search(r'/(\d+)\.cms', url)
  58.             if cms is not None:
  59.                 return ('http://timesofindia.indiatimes.com/articleshow/%s.cms?prtpage=1' %
  60.                     cms.group(1))
  61.  
  62.         return url
  63.  
  64.  
  65.     def preprocess_html(self, soup):
  66.         return soup
  67.