Debian Codegraph @

recipes/znetwork.recipe

raw
1 #!/usr/bin/env python
2 from calibre.web.feeds.news import BasicNewsRecipe, classes
3
4
5 class znetwork(BasicNewsRecipe):
6 title = 'ZNetwork'
7 __author__ = 'unkn0wn'
8 language = 'en'
9 description = 'ZNetwork: Left News, Analysis, Vision & Strategy'
10 oldest_article = 2
11 no_stylesheets = True
12 encoding = 'utf-8'
13 remove_javascript = True
14 use_embedded_content = False
15 remove_attributes = ['style', 'height', 'width']
16 masthead_url = 'https://znetwork.org/wp-content/uploads/2022/08/Z_logo_64.png'
17 ignore_duplicate_articles = {'url'}
18 browser_type = 'qt'
19
20 recipe_specific_options = {
21 'days': {
22 'short': 'Oldest article to download from this news source. In days ',
23 'long': 'For example, 0.5, gives you articles from the past 12 hours',
24 'default': str(oldest_article),
25 }
26 }
27
28 def __init__(self, *args, **kwargs):
29 BasicNewsRecipe.__init__(self, *args, **kwargs)
30 d = self.recipe_specific_options.get('days')
31 if d and isinstance(d, str):
32 self.oldest_article = float(d)
33
34 extra_css = '''
35 .cat-labels { font-size:small; color:#404040; }
36 .post-author, .date, .author-info, .z-post-source, .read-time { font-size:small; }
37 .sub-title { font-style:italic; color:#202020; }
38 em, blockquote { color:#202020; }
39 .wp-caption-text, .wp-element-caption { font-size:small; text-align:center; }
40 '''
41
42 keep_only_tags = [classes('cat-labels post-title z-post-source sub-title post-author date read-time featured entry-content author-info')]
43
44 remove_tags = [dict(name=['aside', 'svg', 'source', 'iframe']), classes('support-z-text yarpp-related yarpp-related-website')]
45
46 remove_tags_after = [classes('author-info')]
47
48 feeds = [('Articles', 'https://znetwork.org/feed/')]
49
50 def preprocess_html(self, soup):
51 for spn in soup.findAll(**classes('post-author date')):
52 spn.string = spn.text + ' | '
53 div = soup.findAll(**classes('featured'))
54 if div:
55 div.name = 'p'
56 p = soup.findAll(**classes('sub-title'))
57 if p:
58 p.name = 'p'
59 for h in soup.findAll(['h2', 'h3']):
60 h.name = 'h4'
61 return soup