Debian Codegraph @

recipes/animal_politico.recipe

raw
1 #!/usr/bin/env python
2 # encoding: utf-8
3
4 import re
5
6 from calibre.web.feeds.news import BasicNewsRecipe
7
8
9 def classes(classes):
10 q = frozenset(classes.split(' '))
11 return dict(attrs={'class': lambda x: x and frozenset(x.split()).intersection(q)})
12
13
14 class AnimalPolitico(BasicNewsRecipe):
15 title = 'Animal PolĂ­tico'
16 description = 'Noticias PolĂ­ticas'
17 __author__ = 'Jose Ortiz'
18 masthead_url = 'https://www.animalpolitico.com/wp-content/themes/animalpolitico-2019/static/assets/logo_black.svg'
19 language = 'es_MX'
20 ignore_duplicate_articles = {'title', 'url'}
21 conversion_options = {'tags': 'News, Mexico', 'publisher': 'Animal Politico', 'comments': description}
22
23 keep_only_tags = [classes('ap_single_first ap_single_content ax_single')]
24 remove_tags = [classes('ap_single_sharers_head ap_single_sharers_share')]
25
26 def parse_index(self):
27 soup = self.index_to_soup('http://www.animalpolitico.com/')
28 articles = []
29 for a in soup(name='a', attrs={'href': True, 'title': True, 'data-author': True, 'data-type': True, 'data-home-title': True}):
30 title = a['title']
31 url = a['href']
32 author = a['data-author']
33 self.log('\t', title, ' at ', url)
34
35 articles.append({'title': title, 'author': author, 'url': url})
36 ans = {}
37 for article in articles:
38 if re.match(r'https?://www\.animalpolitico\.com/elsabueso/.', article['url'], re.I):
39 ans.setdefault('El Sabueso', []).append(article)
40 elif re.match(r'https?://www\.animalpolitico\.com/.', article['url'], re.I):
41 ans.setdefault('Noticias', []).append(article)
42 elif re.match(r'https?://www\.animalgourmet\.com/.', article['url'], re.I):
43 ans.setdefault('Comida', []).append(article)
44
45 return [(sec, ans[sec]) for sec in sorted(ans)]
46
47 def populate_article_metadata(self, article, soup, first):
48 if re.match(r'https?://www\.animalpolitico\.com/.', article.url, re.I):
49 article.formatted_date = self.tag_to_string(soup.find(**classes('ap_single_first')).find(**classes('ap_single_first_info_date')))