Debian Codegraph @

recipes/la_jornada.recipe

raw
1 #!/usr/bin/env python
2 # vim:fileencoding=utf-8
3 __license__ = 'GPL v3'
4 __copyright__ = '2010-2012, Darko Miletic <darko.miletic at gmail.com>, Rogelio Domínguez <[email protected]>'
5 '''
6 www.jornada.com.mx
7 '''
8
9 import re
10
11 try:
12 from urllib.parse import urlencode
13 except ImportError:
14 from urllib import urlencode
15 try:
16 from urllib.parse import parse_qs, urlparse, urlunparse
17 except ImportError:
18 from urlparse import parse_qs, urlparse, urlunparse
19 from calibre import strftime
20 from calibre.web.feeds.news import BasicNewsRecipe
21
22
23 class LaJornada_mx(BasicNewsRecipe):
24 title = 'La Jornada (Mexico)'
25 __author__ = 'Darko Miletic/Rogelio Domínguez'
26 description = 'Noticias del diario mexicano La Jornada'
27 publisher = 'DEMOS, Desarrollo de Medios, S.A. de C.V.'
28 category = 'news, Mexico'
29 oldest_article = 2
30 max_articles_per_feed = 200
31 no_stylesheets = True
32 encoding = 'utf8'
33 use_embedded_content = False
34 language = 'es_MX'
35 remove_empty_feeds = True
36 cover_url = strftime('http://www.jornada.com.mx/%Y/%m/%d/portada.pdf')
37 masthead_url = 'http://www.jornada.com.mx/v7.0/imagenes/la-jornada-trans.png'
38 publication_type = 'newspaper'
39 extra_css = '''
40 body{font-family: "Times New Roman",serif }
41 .cabeza{font-size: xx-large; font-weight: bold }
42 .documentFirstHeading{font-size: xx-large; font-weight: bold }
43 .credito-articulo{font-variant: small-caps; font-weight: bold }
44 .foto{text-align: center}
45 .pie-foto{font-size: 0.9em}
46 .credito{font-weight: bold; margin-left: 1em}
47 .credito-autor{font-variant: small-caps; font-weight: bold }
48 .credito-titulo{text-align: right}
49 .hemero{text-align: right; font-size: 0.9em; margin-bottom: 0.5em }
50 .loc{font-weight: bold}
51 .carton{text-align: center}
52 .credit{font-weight: bold}
53 .sumario{font-weight: bold; text-align: center}
54 .text{margin-top: 1.4em}
55 p.inicial{display: inline; font-size: xx-large; font-weight: bold}
56 p.s-s{display: inline; text-indent: 0}
57 '''
58
59 conversion_options = {'comment': description, 'tags': category, 'publisher': publisher, 'language': language}
60
61 recipe_specific_options = {
62 'days': {
63 'short': 'Oldest article to download from this news source. In days ',
64 'long': 'For example, 0.5, gives you articles from the past 12 hours',
65 'default': str(oldest_article),
66 }
67 }
68
69 def __init__(self, *args, **kwargs):
70 BasicNewsRecipe.__init__(self, *args, **kwargs)
71 d = self.recipe_specific_options.get('days')
72 if d and isinstance(d, str):
73 self.oldest_article = float(d)
74
75 preprocess_regexps = [
76 (
77 re.compile(r'<div class="inicial">(.*)</div><p class="s-s">', re.DOTALL | re.IGNORECASE),
78 lambda match: '<p class="inicial">' + match.group(1) + '</p><p class="s-s">',
79 )
80 ]
81
82 keep_only_tags = [
83 dict(name='div', attrs={'class': ['documentContent', 'cabeza', 'sumarios', 'credito-articulo', 'text', 'carton']}),
84 dict(name='div', attrs={'id': 'renderComments'}),
85 ]
86 remove_tags = [dict(name='div', attrs={'class': ['buttonbar', 'comment-cont']})]
87
88 feeds = [
89 ('Opinion', 'http://www.jornada.com.mx/rss/opinion.xml'),
90 ('Cartones', 'http://www.jornada.com.mx/rss/cartones.xml'),
91 ('Politica', 'http://www.jornada.com.mx/rss/politica.xml'),
92 ('Economia', 'http://www.jornada.com.mx/rss/economia.xml'),
93 ('Mundo', 'http://www.jornada.com.mx/rss/mundo.xml'),
94 ('Estados', 'http://www.jornada.com.mx/rss/estados.xml'),
95 ('Capital', 'http://www.jornada.com.mx/rss/capital.xml'),
96 ('Sociedad y justicia', 'http://www.jornada.com.mx/rss/sociedad.xml'),
97 ('Ciencias', 'http://www.jornada.com.mx/rss/ciencias.xml'),
98 ('Cultura', 'http://www.jornada.com.mx/rss/cultura.xml'),
99 ('Gastronomia', 'http://www.jornada.com.mx/rss/gastronomia.xml'),
100 ('Espectaculos', 'http://www.jornada.com.mx/rss/espectaculos.xml'),
101 ('Deportes', 'http://www.jornada.com.mx/rss/deportes.xml'),
102 ('Ultimas noticias', 'http://www.jornada.com.mx/ultimas/news/RSS'),
103 ]
104
105 def preprocess_html(self, soup):
106 for item in soup.findAll(style=True):
107 del item['style']
108 return soup
109
110 def get_article_url(self, article):
111 # Get link to original article URL
112 rurl = article.get('guid', None)
113 if not rurl:
114 # Use the "link" attribute as failover
115 return article.get('link', None)
116 # Remove "partner" query param
117 u = urlparse(rurl)
118 query = parse_qs(u.query)
119 query.pop('partner', None)
120 u = u._replace(query=urlencode(query, True))
121 return urlunparse(u)