Debian Codegraph @

recipes/elperiodico_spanish.recipe

raw
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 __license__ = 'GPL v3'
5 __copyright__ = '30 October 2010, Jordi Balcells based on an earlier recipe by Darko Miletic <darko.miletic at gmail.com>'
6 '''
7 elperiodico.cat
8 '''
9
10 from calibre.ebooks.BeautifulSoup import Tag
11 from calibre.web.feeds.news import BasicNewsRecipe
12
13
14 def new_tag(soup, name, attrs=()):
15 impl = getattr(soup, 'new_tag', None)
16 if impl is not None:
17 return impl(name, attrs=dict(attrs))
18 return Tag(soup, name, attrs=attrs or None)
19
20
21 class ElPeriodico_cat(BasicNewsRecipe):
22 title = 'El Periodico de Catalunya'
23 __author__ = 'Jordi Balcells/Darko Miletic'
24 description = 'Noticias desde Catalunya'
25 publisher = 'elperiodico.com'
26 category = 'news, politics, Spain, Catalunya'
27 oldest_article = 2
28 max_articles_per_feed = 100
29 no_stylesheets = True
30 use_embedded_content = False
31 delay = 1
32 encoding = 'cp1252'
33 language = 'es'
34
35 html2lrf_options = ['--comment', description, '--category', category, '--publisher', publisher]
36
37 html2epub_options = 'publisher="' + publisher + '"\ncomments="' + description + '"\ntags="' + category + '"'
38
39 feeds = [
40 ('Portada', 'http://www.elperiodico.com/es/rss/rss_portada.xml'),
41 ('Internacional', 'http://elperiodico.com/es/rss/internacional/rss.xml'),
42 ('Sociedad', 'http://elperiodico.com/es/rss/sociedad/rss.xml'),
43 ('Ciencia y Tecnolog\xeda', 'http://elperiodico.com/es/rss/ciencia-y-tecnologia/rss.xml'),
44 ('Deportes', 'http://elperiodico.com/es/rss/deportes/rss.xml'),
45 ('Gente', 'http://elperiodico.com/es/rss/gente/rss.xml'),
46 ('Opini\xf3n', 'http://elperiodico.com/es/rss/opinion/rss.xml'),
47 ('Pol\xedtica', 'http://elperiodico.com/es/rss/politica/rss.xml'),
48 ('Barcelona', 'http://elperiodico.com/es/rss/barcelona/rss.xml'),
49 ('Econom\xeda', 'http://elperiodico.com/es/rss/economia/rss.xml'),
50 ('Cultura y espect\xe1culos', 'http://elperiodico.com/es/rss/cultura-y-espectaculos/rss.xml'),
51 ('Tele', 'http://elperiodico.com/es/rss/cultura-y-espectaculos/rss.xml'),
52 ]
53
54 keep_only_tags = [dict(name='div', attrs={'class': 'titularnoticia'}), dict(name='div', attrs={'class': 'noticia_completa'})]
55
56 remove_tags = [dict(name='div', attrs={'class': ['opcionb', 'opcionb last', 'columna_noticia']}), dict(name='span', attrs={'class': 'opcionesnoticia'})]
57
58 def print_version(self, url):
59 return url.replace('/default.asp?', '/print.asp?')
60
61 def preprocess_html(self, soup):
62 mcharset = new_tag(soup, 'meta', [('http-equiv', 'Content-Type'), ('content', 'text/html; charset=utf-8')])
63 soup.head.insert(0, mcharset)
64 for item in soup.findAll(style=True):
65 del item['style']
66 return soup