Debian Codegraph @

recipes/deccan_herald.recipe

raw
1 from calibre.web.feeds.news import BasicNewsRecipe, classes
2
3
4 def absurl(url):
5 if url.startswith('/'):
6 return 'https://www.deccanherald.com' + url
7
8
9 class herald(BasicNewsRecipe):
10 title = 'Deccan Herald'
11 __author__ = 'unkn0wn'
12 description = 'Deccan Herald is an Indian English language daily newspaper published from the Indian state of Karnataka.'
13 language = 'en_IN'
14 no_stylesheets = True
15 remove_attributes = ['height', 'width', 'style']
16 ignore_duplicate_articles = {'url', 'title'}
17 encoding = 'utf-8'
18
19 keep_only_tags = [classes('article-title article-author__name'), dict(name='div', attrs={'id': 'main-content'})]
20
21 remove_tags = [
22 classes(
23 'storyShare social-media-icons in_article_video static_text'
24 ' nl-optin-mobile dk_only article-banner-adver-wrapper wb_holder'
25 ' field-name-field-tags section-full strip--business'
26 )
27 ]
28
29 def parse_index(self):
30 index = 'https://www.deccanherald.com/'
31 sections = ['india', 'world', 'elections', 'opinion', 'specials', 'business', 'sports']
32 feeds = []
33
34 for sec in sections:
35 soup = self.index_to_soup(index + sec)
36 section = sec.capitalize()
37 self.log(section)
38 articles = []
39 for a in soup.findAll('a', attrs={'href': lambda x: x and x.startswith('/' + sec + '/')}):
40 url = absurl(a['href'].split('?')[0])
41 if url in {index + sec + '/', index + sec}:
42 continue
43 title = self.tag_to_string(a)
44 self.log('\t', title, '\n\t\t', url)
45 articles.append({'title': title, 'url': url})
46 if articles:
47 feeds.append((section, articles))
48 return feeds