Debian Codegraph @

recipes/straitstimes.recipe

raw
1 __license__ = 'GPL v3'
2 __copyright__ = '2009, Darko Miletic <darko.miletic at gmail.com>'
3 '''
4 www.straitstimes.com
5 '''
6
7 from calibre.web.feeds.recipes import BasicNewsRecipe
8
9
10 def classes(classes):
11 q = frozenset(classes.split(' '))
12 return dict(attrs={'class': lambda x: x and frozenset(x.split()).intersection(q)})
13
14
15 class StraitsTimes(BasicNewsRecipe):
16 title = 'The Straits Times'
17 __author__ = 'Darko Miletic'
18 description = 'Singapore newspaper'
19 oldest_article = 2
20 max_articles_per_feed = 100
21 no_stylesheets = True
22 use_embedded_content = False
23 encoding = 'utf-8'
24 publisher = 'Singapore Press Holdings Ltd.'
25 category = 'news, politics, singapore, asia'
26 language = 'en_SG'
27
28 conversion_options = {'comments': description, 'tags': category, 'language': language, 'publisher': publisher}
29 keep_only_tags = [
30 classes('node-header node-subheadline group-byline-info group-updated-timestamp group-image-frame field-name-body article-content-rawhtml')
31 ]
32 remove_tags = [
33 classes('st_telegram_boilerplate dropdown-menu ads'),
34 dict(name='source'),
35 ]
36
37 feeds = [
38 ('World', 'https://www.straitstimes.com/news/world/rss.xml'),
39 ('Business', 'https://www.straitstimes.com/news/business/rss.xml'),
40 ('Life', 'https://www.straitstimes.com/news/life/rss.xml'),
41 ('Tech', 'https://www.straitstimes.com/news/tech/rss.xml'),
42 ('Opinion', 'https://www.straitstimes.com/news/opinion/rss.xml'),
43 ('Life', 'https://www.straitstimes.com/news/life/rss.xml'),
44 ('Singapore', 'https://www.straitstimes.com/news/singapore/rss.xml'),
45 ('Asia', 'https://www.straitstimes.com/news/asia/rss.xml'),
46 ('Multimedia', 'https://www.straitstimes.com/news/multimedia/rss.xml'),
47 ('Sport', 'https://www.straitstimes.com/news/sport/rss.xml'),
48 ]
49
50 def preprocess_html(self, soup):
51 for img in soup.findAll('img', srcset=True):
52 img['src'] = img['srcset'].partition(' ')[0]
53 img['srcset'] = ''
54 return soup