Debian Codegraph @

recipes/singtaohk.recipe

raw
1 #!/usr/bin/env python
2 from calibre.web.feeds.news import BasicNewsRecipe, classes
3
4
5 class STHKRecipe(BasicNewsRecipe):
6 title = '星島日報 (香港)'
7 __author__ = 'unkn0wn'
8 description = "The Sing Tao Daily is among Hong Kong's oldest Chinese language newspapers. (https://std.stheadline.com/)"
9 category = 'Chinese, News, Hong Kong'
10 language = 'zh'
11 encoding = 'utf-8'
12 masthead_url = 'https://std.stheadline.com/dist/images/[email protected]'
13 no_stylesheets = True
14 remove_javascript = True
15 ignore_duplicate_articles = {'title', 'url'}
16 remove_empty_feeds = True
17 use_embedded_content = False
18 remove_attributes = ['style', 'height', 'width']
19
20 extra_css = '''
21 img {display:block; margin:0 auto;}
22 .date { font-size:small; }
23 .caption-text, .media-library-item__attributes { font-size:small; text-align:center; }
24 '''
25
26 keep_only_tags = [dict(name='article', attrs={'class': 'content'})]
27 remove_tags = [
28 dict(name=['video', 'svg', 'button']),
29 dict(attrs={'id': 'articleShareIcons'}),
30 classes('in-article-banner stick-box-gray article-pagination comments'),
31 ]
32
33 def parse_index(self):
34 index = 'https://std.stheadline.com/'
35 sections = ['daily', 'realtime', 'supplement']
36 feeds = []
37 soup = self.index_to_soup(index)
38 for sec in sections:
39 section = sec.capitalize()
40 self.log(section)
41 articles = []
42 for a in soup.findAll('a', attrs={'href': lambda x: x and x.startswith(index + sec + '/')}):
43 url = a['href']
44 if url in {index + sec + '/', index + sec}:
45 continue
46 if '/article/' not in url:
47 continue
48 title = self.tag_to_string(a)
49 self.log('\t', title, '\n\t\t', url)
50 articles.append({'title': title, 'url': url})
51 if articles:
52 feeds.append((section, articles))
53 return feeds