Debian Codegraph @

recipes/tijd.recipe

raw
1 #!/usr/bin/env python
2
3 __license__ = 'GPL v3'
4 __copyright__ = '2009, Darko Miletic <darko.miletic at gmail.com>'
5 '''
6 www.tijd.be
7 '''
8 from calibre.ebooks.BeautifulSoup import Tag
9 from calibre.web.feeds.news import BasicNewsRecipe
10
11
12 def new_tag(soup, name, attrs=()):
13 impl = getattr(soup, 'new_tag', None)
14 if impl is not None:
15 return impl(name, attrs=dict(attrs))
16 return Tag(soup, name, attrs=attrs or None)
17
18
19 class DeTijd(BasicNewsRecipe):
20 title = 'De Tijd'
21 __author__ = 'Darko Miletic'
22 description = 'News from Belgium in Dutch'
23 publisher = 'De Tijd'
24 category = 'news, politics, Belgium'
25 oldest_article = 2
26 max_articles_per_feed = 100
27 no_stylesheets = True
28 use_embedded_content = False
29 encoding = 'utf-8'
30 language = 'nl_BE'
31
32 lang = 'nl-BE'
33 direction = 'ltr'
34
35 keep_only_tags = [
36 dict(name='div', attrs={'id': 'lcol'}),
37 dict(name='div', attrs={'class': 'l-main-container-article__asset-container'}),
38 dict(name='div', attrs={'class': 'l-main-container-article__body clearfix highlightable '}),
39 dict(name='div', attrs={'class': 'l-main-container-article__intro highlightable '}),
40 dict(name='div', attrs={'class': 'l-main-container-article__sidebar-inline'}),
41 dict(name='div', attrs={'class': 'l-main-container-article__title '}),
42 ]
43 remove_tags = [dict(name=['embed', 'object']), dict(name='div', attrs={'id': 'art_reactwrap'})]
44 remove_tags_after = dict(name='div', attrs={'id': 'art_author'})
45
46 feeds = [
47 ('Volledig nieuwsaanbod', 'https://www.tijd.be/rss/nieuws.xml'),
48 ('Ondernemen', 'https://www.tijd.be/rss/ondernemen.xml'),
49 ('Politiek en Economie', 'https://www.tijd.be/rss/politiek.xml'),
50 ('Markten', 'https://www.tijd.be/rss/markten_live.xml'),
51 ('Opinie', 'https://www.tijd.be/rss/opinie.xml'),
52 ('Cultuur', 'https://www.tijd.be/rss/cultuur.xml'),
53 ('Netto', 'https://www.tijd.be/rss/netto.xml'),
54 ('Sabato', 'https://www.tijd.be/rss/sabato.xml'),
55 ]
56
57 def preprocess_html(self, soup):
58 del soup.body['onload']
59 for item in soup.findAll(style=True):
60 del item['style']
61 soup.html['lang'] = self.lang
62 soup.html['dir'] = self.direction
63 mlang = new_tag(soup, 'meta', [('http-equiv', 'Content-Language'), ('content', self.lang)])
64 mcharset = new_tag(soup, 'meta', [('http-equiv', 'Content-Type'), ('content', 'text/html; charset=utf-8')])
65 soup.head.insert(0, mlang)
66 soup.head.insert(1, mcharset)
67 return soup