Debian Codegraph @

recipes/freenature.recipe

raw
1 from calibre.web.feeds.news import BasicNewsRecipe
2
3
4 def classes(classes):
5 q = frozenset(classes.split(' '))
6 return dict(attrs={'class': lambda x: x and frozenset(x.split()).intersection(q)})
7
8
9 class NatureNews(BasicNewsRecipe):
10 title = 'Nature News'
11 language = 'en'
12 __author__ = 'Kovid Goyal'
13 oldest_article = 31 # days
14 remove_empty_feeds = True
15 max_articles_per_feed = 50
16
17 no_stylesheets = True
18 use_embedded_content = False
19 remove_javascript = True
20 keep_only_tags = [
21 classes('container-type-article'),
22 ]
23 remove_tags = [
24 dict(id='related-articles'),
25 classes('u-hide-print hide-print visually-hidden'),
26 dict(name=['meta', 'link', 'source']),
27 ]
28
29 # News and comments
30 feeds = [('Nature News', 'http://feeds.nature.com/nature/rss/current')]
31
32 def preprocess_html(self, soup):
33 for img in soup.findAll('img', src=lambda x: x and x.startswith('//')):
34 img['src'] = 'https:' + img['src']
35 print(img)
36 return soup