Debian Codegraph @

recipes/degentenaar.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.nieuwsblad.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 DeGentenaarOnline(BasicNewsRecipe):
20 title = 'De Gentenaar'
21 __author__ = 'Darko Miletic'
22 description = 'News from Belgium in Dutch'
23 publisher = 'De Gentenaar'
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 html2lrf_options = ['--comment', description, '--category', category, '--publisher', publisher]
36
37 html2epub_options = (
38 'publisher="'
39 + publisher
40 + '"\ncomments="'
41 + description
42 + '"\ntags="'
43 + category
44 + '"\noverride_css=" p {text-indent: 0cm; margin-top: 0em; margin-bottom: 0.5em} "'
45 )
46
47 keep_only_tags = [dict(name='span', attrs={'id': ['lblArticleTitle', 'lblArticleIntroduction', 'lblArticleMainText']})]
48 remove_tags = [dict(name=['embed', 'object'])]
49
50 feeds = [
51 ('Snelnieuws', 'http://feeds.nieuwsblad.be/nieuws/snelnieuws'),
52 ('Binnenland', 'http://feeds.nieuwsblad.be/nieuws/binnenland'),
53 ('Buitenland', 'http://feeds.nieuwsblad.be/nieuwsblad/buitenland'),
54 ('Economie', 'http://feeds.nieuwsblad.be/economie/home'),
55 ('Economie', 'http://feeds.nieuwsblad.be/economie/home'),
56 ('Algemeen', 'http://feeds.nieuwsblad.be/life/algemeen'),
57 ('Film', 'http://feeds.nieuwsblad.be/life/film'),
58 ('Boek', 'http://feeds.nieuwsblad.be/life/boeken'),
59 ('Muziek', 'http://feeds.nieuwsblad.be/life/muziek'),
60 ('Podium', 'http://feeds.nieuwsblad.be/life/podium'),
61 ('TV & radio', 'http://feeds.nieuwsblad.be/life/tv'),
62 ]
63
64 def print_version(self, url):
65 return url.replace('/Detail.aspx?articleid', '/PrintArticle.aspx?ArticleID')
66
67 def get_article_url(self, article):
68 return article.get('guid', None)
69
70 def preprocess_html(self, soup):
71 del soup.body['onload']
72 for item in soup.findAll(style=True):
73 del item['style']
74 for item in soup.findAll('span'):
75 item.name = 'div'
76 if item.get('id') == 'lblArticleTitle':
77 item.name = 'h3'
78
79 soup.html['lang'] = self.lang
80 soup.html['dir'] = self.direction
81 mlang = new_tag(soup, 'meta', [('http-equiv', 'Content-Language'), ('content', self.lang)])
82 mcharset = new_tag(soup, 'meta', [('http-equiv', 'Content-Type'), ('content', 'text/html; charset=utf-8')])
83 soup.head.insert(0, mlang)
84 soup.head.insert(1, mcharset)
85 return soup