Debian Codegraph @

recipes/bild_de.recipe

raw
1 #!/usr/bin/env python
2 # vim:fileencoding=utf-8
3 from __future__ import absolute_import, division, print_function, unicode_literals
4
5 '''
6 bild.de
7 '''
8
9 import re
10
11 from calibre.web.feeds.recipes import BasicNewsRecipe
12
13
14 class AdvancedUserRecipe1303841067(BasicNewsRecipe):
15 title = 'Bild.de'
16 __author__ = 'schuster'
17 description = 'RSS-Feeds von Bild.de'
18 language = 'de'
19
20 oldest_article = 1
21 max_articles_per_feed = 100
22 no_stylesheets = True
23 remove_javascript = True
24 use_embedded_content = False
25 remove_empty_feeds = True
26
27 masthead_url = 'http://a3.l3-images.myspacecdn.com/images02/56/0232f842170b4d349779f8379c27e073/l.jpg'
28
29 # By default, no local news feeds will be fetched. To change this,
30 # just uncomment the lines for the regions you are interested in.
31 feeds = [
32 ('Politik', 'http://www.bild.de/rss-feeds/rss-16725492,feed=politik.bild.html'),
33 ('Unterhaltung', 'http://www.bild.de/rss-feeds/rss-16725492,feed=unterhaltung.bild.html'),
34 ('Sport', 'http://www.bild.de/rss-feeds/rss-16725492,feed=sport.bild.html'),
35 ('Lifestyle', 'http://www.bild.de/rss-feeds/rss-16725492,feed=lifestyle.bild.html'),
36 ('Ratgeber', 'http://www.bild.de/rss-feeds/rss-16725492,feed=ratgeber.bild.html'),
37 ('Auto', 'http://www.bild.de/rss-feeds/rss-16725492,feed=auto.bild.html'),
38 ('Digital', 'http://www.bild.de/rss-feeds/rss-16725492,feed=digital.bild.html'),
39 ('Spiele', 'http://www.bild.de/rss-feeds/rss-16725492,feed=spiele.bild.html'),
40 ('Leserreporter', 'http://www.bild.de/rss-feeds/rss-16725492,feed=leserreporter.bild.html'),
41 # ('Berlin', 'http://www.bild.de/rss-feeds/rss-16725492,feed=Newsticker.bild.html'),
42 # ('Bremen', 'http://www.bild.de/rss-feeds/rss-16725492,feed=bremen.bild.html'),
43 # ('Chemnitz', 'http://www.bild.de/rssfeeds/rss3/rss3-20745882,feed=ressort-regio-chemnitz.bild.html'),
44 # ('Dresden', 'http://www.bild.de/rss-feeds/rss-16725492,feed=dresden.bild.html'),
45 # ('Düsseldorf', 'http://www.bild.de/rss-feeds/rss-16725492,feed=duesseldorf.bild.html'),
46 # ('Frankfurt/Main', 'http://www.bild.de/rss-feeds/rss-16725492,feed=regio-frankfurt.bild.html'),
47 # ('Hamburg', 'http://www.bild.de/rss-feeds/rss-16725492,feed=hamburg.bild.html'),
48 # ('Hannover', 'http://www.bild.de/rss-feeds/rss-16725492,feed=regio-hannover.bild.html'),
49 # ('Köln', 'http://www.bild.de/rss-feeds/rss-16725492,feed=regio-koeln.bild.html'),
50 # ('Leipzig', 'http://www.bild.de/rss-feeds/rss-16725492,feed=leipzig.bild.html'),
51 # ('München', 'http://www.bild.de/rss-feeds/rss-16725492,feed=muenchen.bild.html'),
52 # ('Ruhrgebiet', 'http://www.bild.de/rss-feeds/rss-16725492,feed=ruhrgebiet.bild.html'),
53 # ('Saarland', 'http://www.bild.de/rssfeeds/rss3/rss3-20745882,feed=regional-saarland.bild.html'),
54 # ('Stuttgart', 'http://www.bild.de/rss-feeds/rss-16725492,feed=regio-stuttgart.bild.html')
55 ]
56
57 keep_only_tags = [dict(name='article')]
58
59 remove_tags = [
60 dict(name=['aside', 'iframe']),
61 dict(attrs={'class': ['socialbar', 'social-sharing flank', 'vel', 'back']}),
62 dict(name='img', attrs={'alt': 'logo'}),
63 dict(name='div', attrs={'class': re.compile(r'infoEl')}),
64 dict(name='span', attrs={'class': re.compile(r'loupe')}),
65 ]
66
67 remove_tags_after = [dict(name='div', attrs={'itemprop': re.compile(r'articleBody')})]
68
69 def preprocess_html(self, soup):
70 # skip articles without relevant content
71 if not soup.find('article'):
72 self.abort_article()
73 # remove all style attributes
74 for item in soup.findAll(attrs={'style': True}):
75 del item['style']
76 # remove <br> within headlines
77 for h1 in soup.findAll('h1'):
78 for br in h1.findAll('br'):
79 br.replaceWith(' ')
80 # remove all links
81 for a in soup.findAll('a'):
82 a.replaceWith(a.renderContents().decode('utf-8'))
83 return soup