Debian Codegraph @

recipes/nautilus.recipe

raw
1 #!/usr/bin/env python
2 from calibre.web.feeds.news import BasicNewsRecipe, classes, prefixed_classes
3
4
5 class Nautilus(BasicNewsRecipe):
6 title = 'Nautilus Magazine'
7 language = 'en_US'
8 __author__ = 'unkn0wn'
9 oldest_article = 30 # days
10 max_articles_per_feed = 50
11 description = (
12 'Nautilus is a different kind of science magazine. Our stories take you into the depths'
13 ' of science and spotlight its ripples in our lives and cultures. We believe any subject in science,'
14 ' no matter how complex, can be explained with clarity and vitality.'
15 )
16 no_stylesheets = True
17 remove_javascript = True
18 use_embedded_content = False
19 remove_attributes = ['style', 'height', 'width']
20 masthead_url = 'https://lede-admin.nautil.us/wp-content/uploads/sites/70/sites/3/nautilus/Nautilus-logo.png?w=440'
21 ignore_duplicate_articles = {'title', 'url'}
22 remove_empty_feeds = True
23 resolve_internal_links = True
24
25 extra_css = '''
26 .calibre-nuked-tag-figcaption,
27 [class^="PostByline_textColumn__"],
28 [class^="PostHeaderMeta_timestamp__"],
29 [class^="PostBylineRiver_author__"],
30 [class^="PostBylineRiver_bio__"] {
31 font-size: small;
32 }
33 blockquote { color:#202020; text-align:center; }
34 em { color:#202020; }
35 [class^="PostHeader_dek__"] { font-style: italic; }
36 '''
37
38 recipe_specific_options = {
39 'days': {
40 'short': 'Oldest article to download from this news source. In days ',
41 'long': 'For example, 0.5, gives you articles from the past 12 hours',
42 'default': str(oldest_article),
43 },
44 'res': {
45 'short': 'For hi-res images, select a resolution from the\nfollowing options: 800, 1000, 1200 or 1500',
46 'long': 'This is useful for non e-ink devices, and for a lower file size\nthan the default, use 400 or 300.',
47 'default': '600',
48 },
49 }
50
51 def __init__(self, *args, **kwargs):
52 BasicNewsRecipe.__init__(self, *args, **kwargs)
53 d = self.recipe_specific_options.get('days')
54 if d and isinstance(d, str):
55 self.oldest_article = float(d)
56
57 keep_only_tags = [
58 prefixed_classes(
59 'FeaturedImage_fullWidthWrapper__ PostHeader_postTitle__ PostHeader_dek__ '
60 'PostByline_textColumn__ PostHeaderMeta_timestamp__ FeaturedImage_wrapper__ '
61 'PostContent_content__ PostBylineRiver_author__ PostBylineRiver_bio__'
62 )
63 ]
64
65 remove_tags = [
66 prefixed_classes('AscendiumAdUnit_wrapper__ AscendiumAdUnit_hidden__ PrimisVideoAdBlock_wrapper__'),
67 classes('wp-block-embed is-type-video is-provider-youtube'),
68 ]
69
70 remove_tags_after = [prefixed_classes('PostBylineRiver_bio__')]
71
72 feeds = [
73 ('ANTHROPOLOGY', 'https://nautil.us/topics/anthropology/feed'),
74 ('ENVIRONMENT', 'https://nautil.us/topics/environment/feed'),
75 ('HEALTH', 'https://nautil.us/topics/health/feed'),
76 ('PALEONTOLOGY', 'https://nautil.us/topics/paleontology/feed'),
77 ('TECHNOLOGY', 'https://nautil.us/topics/technology/feed'),
78 ('ARTS', 'https://nautil.us/topics/arts/feed'),
79 ('EVOLUTION', 'https://nautil.us/topics/evolution/feed'),
80 ('HISTORY', 'https://nautil.us/topics/history/feed'),
81 ('PHILOSOPHY', 'https://nautil.us/topics/philosophy/feed'),
82 ('ZOOLOGY', 'https://nautil.us/topics/zoology/feed'),
83 ('ASTRONOMY', 'https://nautil.us/topics/astronomy/feed'),
84 ('GENERAL', 'https://nautil.us/topics/general/feed'),
85 ('MATH', 'https://nautil.us/topics/math/feed'),
86 ('PHYSICS', 'https://nautil.us/topics/physics/feed'),
87 ('COMMUNICATION', 'https://nautil.us/topics/communication/feed'),
88 ('GENETICS', 'https://nautil.us/topics/genetics/feed'),
89 ('MICROBIOLOGY', 'https://nautil.us/topics/microbiology/feed'),
90 ('PHILOSOPHY', 'https://nautil.us/topics/psychology/feed'),
91 ('ECONOMICS', 'https://nautil.us/topics/economics/feed'),
92 ('GEOSCIENCE', 'https://nautil.us/topics/geoscience/feed'),
93 ('NEUROSCIENCE', 'https://nautil.us/topics/neuroscience/feed'),
94 ('SOCIOLOGY', 'https://nautil.us/topics/sociology/feed'),
95 ('OTHERS', 'https://nautil.us/feed'),
96 ]
97
98 def preprocess_html(self, soup):
99 for b in soup.findAll('button'):
100 if b.find('img'):
101 b.name = 'div'
102 for img in soup.findAll('img', src=True):
103 if 'favicon' in img['src']:
104 continue
105 res = '?w=600'
106 w = self.recipe_specific_options.get('res')
107 if w and isinstance(w, str):
108 res = '?w=' + w
109 img['src'] = img['src'].split('?')[0] + res
110 return soup