Debian Codegraph @

recipes/politico.recipe

raw
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 __license__ = 'GPL v3'
5 __copyright__ = '2009, Darko Miletic <darko.miletic at gmail.com>'
6 '''
7 politico.com
8 '''
9
10 from calibre.web.feeds.news import BasicNewsRecipe
11
12
13 class Politico(BasicNewsRecipe):
14 title = 'Politico'
15 __author__ = 'Darko Miletic and Sujata Raman'
16 description = 'Political news from USA'
17 publisher = 'Capitol News Company, LLC'
18 category = 'news, politics, USA'
19 oldest_article = 7
20 max_articles_per_feed = 100
21 use_embedded_content = False
22 no_stylesheets = True
23 remove_javascript = True
24 encoding = 'UTF-8'
25 language = 'en'
26
27 html2lrf_options = ['--comment', description, '--category', category, '--publisher', publisher, '--ignore-tables']
28
29 html2epub_options = 'publisher="' + publisher + '"\ncomments="' + description + '"\ntags="' + category + '"\nlinearize_tables=True'
30
31 keep_only_tags = [
32 dict(name=['article']),
33 ]
34
35 remove_tags = [
36 dict(name=['notags', 'embed', 'aside', 'object', 'link', 'img', 'figure', 'svg', 'button']),
37 dict(attrs={'class': lambda x: x and 'story-tools' in x.split()}),
38 dict(attrs={'class': lambda x: x and 'story-continued' in x.split()}),
39 dict(attrs={'class': lambda x: x and 'story-supplement' in x.split()}),
40 dict(attrs={'class': lambda x: x and 'story-share' in x.split()}),
41 dict(attrs={'class': lambda x: x and 'suggested' in x.split()}),
42 ]
43
44 extra_css = '''
45 body{font-family:Arial,Sans-serif;}
46 element.style{color:#FF0000;font-family:Arial,Sans-serif;}
47 .author{color:#808080;font-size:x-small;}
48 a{ color:#003399;}
49 .byline{color:#696969 ; font-size:x-small;}
50 .story{color:#000000;}
51 td{color:#000000;}
52 '''
53
54 feeds = [
55 ('Top Stories', 'http://www.politico.com/rss/politicopicks.xml'),
56 ('Congress', 'http://www.politico.com/rss/congress.xml'),
57 ('Ideas', 'http://www.politico.com/rss/ideas.xml'),
58 ('Life', 'http://www.politico.com/rss/life.xml'),
59 ('Lobbyists', 'http://www.politico.com/rss/lobbyists.xml'),
60 ('Pitboss', 'http://www.politico.com/rss/pitboss.xml'),
61 ('Politics', 'http://www.politico.com/rss/politics.xml'),
62 ('Roger Simon', 'http://www.politico.com/rss/rogersimon.xml'),
63 ('Suite Talk', 'http://www.politico.com/rss/suitetalk.xml'),
64 ('Playbook', 'http://www.politico.com/rss/playbook.xml'),
65 ]
66
67 def preprocess_html(self, soup):
68 mtag = '<meta http-equiv="Content-Language" content="en"/>'
69 soup.head.insert(0, mtag)
70 for item in soup.findAll(style=True):
71 del item['style']
72 return soup
73
74 def postprocess_html(self, soup, first):
75
76 for tag in soup.findAll(name=['table', 'tr', 'td']):
77 tag.name = 'div'
78 return soup