mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-09-29 15:31:08 -04:00
71 lines
2.5 KiB
Plaintext
71 lines
2.5 KiB
Plaintext
import re
|
|
from calibre.web.feeds.news import BasicNewsRecipe
|
|
|
|
class TimesOfIndia(BasicNewsRecipe):
|
|
title = u'Times of India'
|
|
language = 'en_IN'
|
|
__author__ = 'Kovid Goyal'
|
|
oldest_article = 1 #days
|
|
max_articles_per_feed = 25
|
|
|
|
no_stylesheets = True
|
|
remove_attributes = ['style']
|
|
keep_only_tags = [
|
|
{'class':re.compile(r'maintable12|prttabl')},
|
|
{'id':['mod-article-header',
|
|
'mod-a-body-after-first-para', 'mod-a-body-first-para']},
|
|
]
|
|
remove_tags = [
|
|
{'class':re.compile('tabsintbgshow|prvnxtbg')},
|
|
{'id':['fbrecommend', 'relmaindiv']}
|
|
]
|
|
|
|
feeds = [
|
|
('Top Stories',
|
|
'http://timesofindia.indiatimes.com/rssfeedstopstories.cms'),
|
|
('India',
|
|
'http://timesofindia.indiatimes.com/rssfeeds/-2128936835.cms'),
|
|
('World',
|
|
'http://timesofindia.indiatimes.com/rssfeeds/296589292.cms'),
|
|
('Mumbai',
|
|
'http://timesofindia.indiatimes.com/rssfeeds/-2128838597.cms'),
|
|
('Entertainment',
|
|
'http://timesofindia.indiatimes.com/rssfeeds/1081479906.cms'),
|
|
('Cricket',
|
|
'http://timesofindia.indiatimes.com/rssfeeds/4719161.cms'),
|
|
('Sunday TOI',
|
|
'http://timesofindia.indiatimes.com/rssfeeds/1945062111.cms'),
|
|
('Life and Style',
|
|
'http://timesofindia.indiatimes.com/rssfeeds/2886704.cms'),
|
|
('Business',
|
|
'http://timesofindia.indiatimes.com/rssfeeds/1898055.cms'),
|
|
('Mad Mad World',
|
|
'http://timesofindia.indiatimes.com/rssfeeds/2178430.cms'),
|
|
('Most Read',
|
|
'http://timesofindia.indiatimes.com/rssfeedmostread.cms')
|
|
]
|
|
|
|
def get_article_url(self, article):
|
|
# Times of India sometimes serves an ad page instead of the article,
|
|
# this code, detects and circumvents that
|
|
url = BasicNewsRecipe.get_article_url(self, article)
|
|
if '/0Ltimesofindia' in url:
|
|
url = url.partition('/0L')[-1]
|
|
url = url.replace('0B', '.').replace('0N', '.com').replace('0C',
|
|
'/').replace('0E', '-')
|
|
url = 'http://' + url.rpartition('/')[0]
|
|
match = re.search(r'/([0-9a-zA-Z]+?)\.cms', url)
|
|
if match is not None:
|
|
num = match.group(1)
|
|
num = re.sub(r'[^0-9]', '', num)
|
|
return ('http://timesofindia.indiatimes.com/articleshow/%s.cms?prtpage=1' %
|
|
num)
|
|
else:
|
|
cms = re.search(r'/(\d+)\.cms', url)
|
|
if cms is not None:
|
|
return ('http://timesofindia.indiatimes.com/articleshow/%s.cms?prtpage=1' %
|
|
cms.group(1))
|
|
|
|
return url
|
|
|