Debian Codegraph @

recipes/tagesspiegel.recipe

raw
1 #!/usr/bin/env python
2 # vim:fileencoding=utf-8
3 # License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
4
5 from __future__ import absolute_import, division, print_function, unicode_literals
6
7 from calibre.web.feeds.recipes import BasicNewsRecipe
8
9
10 def classes(classes):
11 q = frozenset(classes.split(' '))
12 return dict(attrs={'class': lambda x: x and frozenset(x.split()).intersection(q)})
13
14
15 class TagesspiegelRss(BasicNewsRecipe):
16 title = 'Der Tagesspiegel'
17 __author__ = 'Kovid Goyal'
18 oldest_article = 1
19 max_articles_per_feed = 100
20 language = 'de'
21 publication_type = 'newspaper'
22 no_stylesheets = True
23 remove_stylesheets = True
24 remove_javascript = True
25 encoding = 'utf-8'
26 use_embedded_content = False
27 ignore_duplicate_articles = {'title', 'url'}
28 remove_empty_feeds = True
29
30 recipe_specific_options = {
31 'days': {
32 'short': 'Oldest article to download from this news source. In days ',
33 'long': 'For example, 0.5, gives you articles from the past 12 hours',
34 'default': str(oldest_article),
35 }
36 }
37
38 def __init__(self, *args, **kwargs):
39 BasicNewsRecipe.__init__(self, *args, **kwargs)
40 d = self.recipe_specific_options.get('days')
41 if d and isinstance(d, str):
42 self.oldest_article = float(d)
43
44 def get_browser(self):
45 return BasicNewsRecipe.get_browser(self, verify_ssl_certificates=False)
46
47 def get_cover_url(self):
48 from datetime import date
49
50 cover = 'https://img.kiosko.net/' + date.today().strftime('%Y/%m/%d') + '/de/tagesspiegel.750.jpg'
51 return cover
52
53 keep_only_tags = [dict(name='header', attrs={'class': 'Bo'}), dict(name='div', attrs={'id': 'story-elements'})]
54
55 remove_tags = [dict(name='aside'), classes('iqd_mainAd Bs')]
56
57 feeds = [
58 ('Politik', 'http://www.tagesspiegel.de/contentexport/feed/politik'),
59 ('Meinung', 'http://www.tagesspiegel.de/contentexport/feed/meinung'),
60 ('Berlin', 'http://www.tagesspiegel.de/contentexport/feed/berlin'),
61 ('Wirtschaft', 'http://www.tagesspiegel.de/contentexport/feed/wirtschaft'),
62 ('Sport', 'http://www.tagesspiegel.de/contentexport/feed/sport'),
63 ('Kultur', 'http://www.tagesspiegel.de/contentexport/feed/kultur'),
64 ('Weltspiegel', 'http://www.tagesspiegel.de/contentexport/feed/weltspiegel'),
65 ('Medien', 'http://www.tagesspiegel.de/contentexport/feed/medien'),
66 ('Wissen', 'http://www.tagesspiegel.de/contentexport/feed/wissen'),
67 ]