Debian Codegraph @

recipes/el_diplo.recipe

raw
1 # -*- mode: python; coding: utf-8; -*-
2 # vim: set syntax=python fileencoding=utf-8
3
4 __license__ = 'GPL v3'
5 __copyright__ = '2023, Tomás Di Domenico <tdido at tdido.eu>'
6
7 '''
8 www.eldiplo.org
9 '''
10
11 from calibre.web.feeds.news import BasicNewsRecipe
12
13
14 class ElDiplo2023(BasicNewsRecipe):
15 title = 'Le Monde Diplomatique - cono sur'
16 __author__ = 'Tomás Di Domenico'
17 description = 'Publicación de Le Monde Diplomatique para el cono sur.'
18 publisher = 'Capital Intelectual'
19 category = 'News, Politics, Argentina, Uruguay, Paraguay, South America, World'
20 oldest_article = 31
21 no_stylesheets = True
22 encoding = 'utf8'
23 use_embedded_content = False
24 language = 'es_AR'
25 remove_empty_feeds = True
26 publication_type = 'magazine'
27 delay = 1
28 simultaneous_downloads = 1
29 timeout = 8
30 needs_subscription = True
31 ignore_duplicate_articles = {'url'}
32 temp_files = []
33 fetch_retries = 10
34 handle_gzip = True
35 compress_news_images = True
36 scale_news_images_to_device = True
37 masthead_url = 'https://www.eldiplo.org/wp-content/themes/_polenta_/assets/diplo.png'
38 INDEX = 'https://www.eldiplo.org/'
39
40 conversion_options = {'series': 'El Dipló', 'publisher': publisher, 'base_font_size': 8, 'tags': category}
41
42 keep_only_tags = [dict(name=['article'])]
43
44 remove_tags = [dict(name=['button'])]
45
46 extra_css = '''
47 .entry-title {
48 text-align: center;
49 }
50 .text-right {
51 text-align: right;
52 }
53 .bajada {
54 display: block;
55 font-family: sans-serif;
56 text-align: center;
57 font-size: 110%;
58 padding: 2%;
59 }
60 .Destacado{
61 display: block;
62 font-size: 120%;
63 font-weight: bold;
64 font-style: italic;
65 padding-left: 10%;
66 padding-right: 10%;
67 }
68 '''
69
70 def get_browser(self):
71 br = BasicNewsRecipe.get_browser(self)
72 br.open(self.INDEX)
73 if self.username is not None and self.password is not None:
74 br.select_form(id='loginform')
75 br['log'] = self.username
76 br['pwd'] = self.password
77 br.submit()
78 return br
79
80 def get_cover_url(self):
81 soup_index = self.index_to_soup(self.INDEX)
82 tag_sumario = soup_index.find('span', text='Sumario')
83 url_sumario = 'https://www.eldiplo.org' + tag_sumario.parent['href']
84
85 soup = self.index_to_soup(url_sumario)
86
87 container = soup.find('div', class_='px-5')
88 url = container.find('img')['src']
89
90 return getattr(self, 'cover_url', url)
91
92 def _process_article(self, article):
93 url = article.find('a', href=True, attrs={'class': 'title'})['href']
94 title = self.tag_to_string(article).replace('Editorial', 'Editorial: ')
95 try:
96 title, authors = title.split(', por')
97 authors = f'por {authors}'
98 except ValueError:
99 authors = ''
100 self.log('title: ', title, ' url: ', url)
101 return {'title': title, 'url': url, 'description': authors, 'date': ''}
102
103 def preprocess_html(self, soup):
104 font_size = '90%'
105
106 # make the footnotes smaller
107 for p in soup.find('div', id='nota_pie').findChildren('p', recursive=False):
108 p['style'] = f'font-size: {font_size};'
109
110 # remove extra text
111 extra_text = soup.find(string='POST TYPE: post')
112 if extra_text:
113 extra_text.parent.decompose()
114
115 return soup
116
117 def parse_index(self):
118 soup_index = self.index_to_soup(self.INDEX)
119
120 tag_sumario = soup_index.find('span', text='Sumario')
121
122 if tag_sumario is None:
123 return None
124
125 url_sumario = 'https://www.eldiplo.org' + tag_sumario.parent['href']
126 self.log(url_sumario)
127
128 soup_sumario = self.index_to_soup(url_sumario)
129
130 feeds = []
131 articles = []
132 dossiers = []
133
134 sumario = soup_sumario.find('div', class_='sumario')
135
136 for section in sumario.find_all('div', recursive=False):
137 classes = section.attrs['class']
138
139 if 'dossier' in classes:
140 dtitle = self.tag_to_string(section.find('h3'))
141 darticles = []
142 for article in section.find_all('div', recursive=False):
143 darticles.append(self._process_article(article))
144 dossiers.append((dtitle, darticles))
145 else:
146 articles.append(self._process_article(section))
147 feeds.append(('Artículos', articles))
148 feeds += dossiers
149
150 return feeds