Debian Codegraph @

recipes/common_dreams.recipe

raw
1 #!/usr/bin/env python
2 ##
3 # Title: Common Dreams
4 ##
5 # License: GNU General Public License v3 -
6 # http://www.gnu.org/copyleft/gpl.html
7
8 # Feb 2012: Cleaned up the output to have only the main article
9
10 __license__ = 'GNU General Public License v3 - http://www.gnu.org/copyleft/gpl.html'
11 '''
12 commondreams.org
13 '''
14
15 import re
16
17 from calibre.web.feeds.news import BasicNewsRecipe
18
19
20 class CommonDreams(BasicNewsRecipe):
21 # Identify the recipe
22
23 title = 'Common Dreams'
24 description = 'Breaking News & Views for the Progressive Community.'
25 cover_url = 'https://s3.amazonaws.com/s3.commondreams.org/images/common-dreams.png'
26 __author__ = 'XanthanGum'
27 language = 'en'
28
29 oldest_article = 7
30 max_articles_per_feed = 100
31
32 no_stylesheets = True
33 remove_javascript = True
34
35 # Specify extra CSS - overrides ALL other CSS (IE. Added last).
36 extra_css = '''body { font-family: verdana, helvetica, sans-serif; }
37 .introduction, .first { font-weight: bold; }
38 .cross-head { font-weight: bold; font-size: 125%; }
39 .cap, .caption { display: block; font-size: 80%; font-style: italic; }
40 .cap, .caption, .caption img, .caption span { display: block; margin: 5px auto; }
41 .byl, .byd, .byline img, .byline-name, .byline-title, .author-name, .author-position,
42 .correspondent-portrait img, .byline-lead-in, .name, .bbc-role { display: block;
43 font-size: 80%; font-style: italic; margin: 1px auto; }
44 .story-date, .published { font-size: 80%; }
45 table { width: 100%; }
46 td img { display: block; margin: 5px auto; }
47 ul { padding-top: 10px; }
48 ol { padding-top: 10px; }
49 li { padding-top: 5px; padding-bottom: 5px; }
50 h1 { font-size: 175%; font-weight: bold; }
51 h2 { font-size: 150%; font-weight: bold; }
52 h3 { font-size: 125%; font-weight: bold; }
53 h4, h5, h6 { font-size: 100%; font-weight: bold; }'''
54
55 # Remove the line breaks and float left/right and picture width/height.
56 preprocess_regexps = [
57 (re.compile(r'<br[ ]*/>', re.IGNORECASE), lambda m: ''),
58 (re.compile(r'<br[ ]*clear.*/>', re.IGNORECASE), lambda m: ''),
59 (re.compile(r'float:.*?'), lambda m: ''),
60 (re.compile(r'width:.*?px'), lambda m: ''),
61 (re.compile(r'height:.*?px'), lambda m: ''),
62 (re.compile(r'<a.*?>'), lambda m: ''),
63 (re.compile(r'</a>'), lambda m: ''),
64 ]
65
66 # Main article is inside this tag
67 keep_only_tags = [
68 dict(name='h1', attrs={'class': 'node__title managed-node-title'}),
69 dict(
70 name='div',
71 attrs={
72 'class': [
73 'field field--name-field-article-img field--type-image field--label-hidden',
74 'field field--name-body field--type-text-with-summary field--label-hidden',
75 ]
76 },
77 ),
78 ]
79
80 # Identify the news feeds
81
82 feeds = [
83 ('Headlines', 'https://www.commondreams.org/feed/headlines_rss'),
84 ('Further News Articles', 'https://www.commondreams.org/feed/further_rss'),
85 ('Views', 'https://www.commondreams.org/feed/views_rss'),
86 ('Progressive Newswire', 'https://www.commondreams.org/feed/newswire_rss'),
87 ]