Debian Codegraph @

recipes/muy_interesante_mexico.recipe

raw
1 #!/usr/bin/env python
2 from calibre.web.feeds.news import BasicNewsRecipe, classes
3
4
5 class MuyInteresante(BasicNewsRecipe):
6 title = 'Muy Interesante México'
7 __author__ = 'unkn0wn'
8 description = (
9 'Muy Interesante México, de la Revista Muy Interesante, es un sitio con información sobre ciencia, tecnología, historia, sociedad, medio ambiente, etc.'
10 )
11 language = 'es_MX'
12 encoding = 'utf-8'
13 no_stylesheets = True
14 remove_javascript = True
15 remove_attributes = ['style', 'height', 'width']
16 ignore_duplicate_articles = {'url'}
17 masthead_url = 'https://www.muyinteresante.com/static/img/logo_web.svg'
18 resolve_internal_links = True
19
20 def get_cover_url(self):
21 soup = self.index_to_soup('https://www.magzter.com/ES/Zinet-Media-Global/Muy-Interesante-Espa%C3%B1a/Science/1806044')
22 return soup.find('img', id=lambda s: s and 'mgd__lhd__cover' in s.split())['src']
23
24 extra_css = '''
25 .c-detail__bar, .c-detail__author, .c-detail__media__txt { font-size:small; }
26 .default-epigraph { font-style:italic; }
27 '''
28
29 keep_only_tags = [dict(name='article', attrs={'class': 'c-detail'})]
30
31 remove_tags = [dict(name=['aside', 'svg', 'script']), classes('c-detail__share')]
32
33 def preprocess_html(self, soup):
34 au = soup.find(**classes('c-detail__author'))
35 if au:
36 for p in au.findAll('p'):
37 p.name = 'div'
38 for h in soup.findAll(['h2', 'h3']):
39 h.name = 'h4'
40 return soup
41
42 def parse_index(self):
43 soup = self.index_to_soup('https://www.muyinteresante.com.mx/')
44 ans = []
45 for articles in soup.findAll('article'):
46 a = articles.find('a', attrs={'class': 'page-link', 'href': True})
47 if not a:
48 continue
49 title = self.tag_to_string(a)
50 url = a['href']
51 desc = ''
52 info = articles.find(**classes('c-article__info_content'))
53 if info:
54 desc = self.tag_to_string(info)
55 self.log('\t', title, '\n\t', desc, '\n\t\t', url)
56 ans.append({'title': title, 'url': url, 'description': desc})
57 return [('Articles', ans)]