Debian Codegraph @

recipes/argument.recipe

raw
1 import re
2
3 from calibre.web.feeds.recipes import BasicNewsRecipe
4
5
6 class argumentRecipe(BasicNewsRecipe):
7 __author__ = 'bubak'
8 title = '!argument'
9 description = 'casopisargument.cz'
10 oldest_article = 1
11 max_articles_per_feed = 20
12
13 sections = [('Argument', 'http://casopisargument.cz')]
14
15 language = 'cs'
16 cover_url = 'http://casopisargument.cz/wp-content/uploads/2016/12/logo-argument.png'
17 remove_javascript = True
18 no_stylesheets = True
19
20 remove_attributes = []
21 remove_tags_before = dict(name='h1', attrs={'class': ['entry-title']})
22 remove_tags_after = dict(name='footer', attrs={'class': ['entry-footer']})
23 remove_tags = [dict(name='img'), dict(name='div', attrs={'id': ['AAAsocial-bookmark']})]
24
25 preprocess_regexps = [(re.compile(r'<a\s[^>]*>([^<]*)</a>', re.DOTALL | re.IGNORECASE), lambda match: match.group(1))]
26
27 def parse_index(self):
28 res = []
29 seen_titles = set()
30 for section in self.sections:
31 self.log('\tTrying section ' + section[0])
32 articles = []
33 soup = self.index_to_soup(section[1])
34 content = soup.findAll('article')
35 if content is None:
36 raise ValueError('Could not find category content')
37 for c in content:
38 article = c.find('a', text=re.compile(r'.'))
39 if article and article.get('href'):
40 url = article['href']
41 title = re.sub(r'^\s*(\S.*\S)\s*$', r'\1', article.text)
42 if url.startswith('/'):
43 url = 'http://casopisargument.cz' + url
44 if title in seen_titles:
45 self.log('\tAlready seen: ', title)
46 continue
47 seen_titles.add(title)
48 self.log('\tFound article:', title, 'at', url)
49 articles.append({'title': title, 'url': url, 'description': '', 'date': ''})
50 res.append((section[0], articles))
51 return res