Debian Codegraph @

recipes/denver_post.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.news 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 DenverPost(BasicNewsRecipe):
16 title = 'Denver Post'
17 language = 'en_US'
18 __author__ = 'Kovid Goyal'
19 oldest_article = 1 # days
20 max_articles_per_feed = 20
21
22 no_stylesheets = True
23 use_embedded_content = False
24 keep_only_tags = [
25 dict(name='h1'),
26 classes('subheadline byline header-features article-body'),
27 ]
28 remove_tags = [
29 classes('related'),
30 dict(attrs={'data-config-video-id': True}),
31 ]
32
33 feeds = [
34 ('Top Stories', 'http://feeds.denverpost.com/dp-news-topstories'),
35 ('Business', 'http://feeds.denverpost.com/dp-business'),
36 ('Sports', 'http://feeds.denverpost.com/dp-sports'),
37 ('Lifestyles', 'http://feeds.denverpost.com/dp-lifestyles'),
38 ('Politics', 'http://feeds.denverpost.com/dp-politics'),
39 ('Entertainment', 'http://feeds.denverpost.com/dp-entertainment'),
40 ]
41
42 def preprocess_html(self, soup):
43 for img in soup.findAll('img', attrs={'data-src': True}):
44 img['src'] = img['data-src']
45 del img['height']
46 del img['width']
47 return soup