| 1 |
from __future__ import print_function |
| 2 |
|
| 3 |
# -*- mode: python -*- |
| 4 |
# -*- coding: utf-8 -*- |
| 5 |
# vim:fileencoding=utf-8 |
| 6 |
|
| 7 |
__license__ = 'GPL v3' |
| 8 |
__copyright__ = '2009-2017, Darko Miletic <darko.miletic at gmail.com>' |
| 9 |
''' |
| 10 |
elmundo.es |
| 11 |
''' |
| 12 |
import time |
| 13 |
|
| 14 |
from calibre.ptempfile import PersistentTemporaryFile |
| 15 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 16 |
|
| 17 |
|
| 18 |
class ElMundo(BasicNewsRecipe): |
| 19 |
title = 'El Mundo' |
| 20 |
__author__ = 'Darko Miletic' |
| 21 |
description = 'Lider de informacion en espaƱol' |
| 22 |
publisher = 'Unidad Editorial Informacion General S.L.U.' |
| 23 |
category = 'news, politics, Spain' |
| 24 |
oldest_article = 2 |
| 25 |
max_articles_per_feed = 100 |
| 26 |
no_stylesheets = True |
| 27 |
use_embedded_content = False |
| 28 |
encoding = 'iso8859_15' |
| 29 |
remove_javascript = True |
| 30 |
remove_empty_feeds = True |
| 31 |
language = 'es' |
| 32 |
ignore_duplicate_articles = {'url'} |
| 33 |
masthead_url = 'http://e00-elmundo.uecdn.es/assets/v7/img/svg/elmundo.svg' |
| 34 |
publication_type = 'newspaper' |
| 35 |
articles_are_obfuscated = True |
| 36 |
auto_cleanup = True |
| 37 |
temp_files = [] |
| 38 |
extra_css = ''' |
| 39 |
body{font-family: "PT serif",Georgia,serif,times} |
| 40 |
.metadata_noticia{font-size: small} |
| 41 |
.pestana_GDP{font-size: small; font-weight:bold} |
| 42 |
h1 {color: #333333; font-family: "Clear Sans Bold",Arial,sans-serif,helvetica} |
| 43 |
.hora{color: red} |
| 44 |
.update{color: gray} |
| 45 |
''' |
| 46 |
|
| 47 |
conversion_options = {'comments': description, 'tags': category, 'language': language, 'publisher': publisher} |
| 48 |
|
| 49 |
remove_tags = [dict(attrs={'class': lambda x: x and ('aside-tools' or 'publicidad') in x.split()})] |
| 50 |
|
| 51 |
feeds = [ |
| 52 |
('Portada', 'http://estaticos.elmundo.es/elmundo/rss/portada.xml'), |
| 53 |
('Deportes', 'http://estaticos.elmundo.es/elmundodeporte/rss/portada.xml'), |
| 54 |
('Economia', 'http://estaticos.elmundo.es/elmundo/rss/economia.xml'), |
| 55 |
('Espa\xf1a', 'http://estaticos.elmundo.es/elmundo/rss/espana.xml'), |
| 56 |
('Internacional', 'http://estaticos.elmundo.es/elmundo/rss/internacional.xml'), |
| 57 |
('Cultura', 'http://estaticos.elmundo.es/elmundo/rss/cultura.xml'), |
| 58 |
('Ciencia/Ecolog\xeda', 'http://estaticos.elmundo.es/elmundo/rss/ciencia.xml'), |
| 59 |
('Comunicaci\xf3n', 'http://estaticos.elmundo.es/elmundo/rss/comunicacion.xml'), |
| 60 |
('Televisi\xf3n', 'http://estaticos.elmundo.es/elmundo/rss/television.xml'), |
| 61 |
('Salud', 'http://estaticos.elmundo.es/elmundosalud/rss/portada.xml'), |
| 62 |
('Solidaridad', 'http://estaticos.elmundo.es/elmundo/rss/solidaridad.xml'), |
| 63 |
('Su vivienda', 'http://estaticos.elmundo.es/elmundo/rss/suvivienda.xml'), |
| 64 |
('Motor', 'http://estaticos.elmundo.es/elmundodeporte/rss/motor.xml'), |
| 65 |
('Madrid', 'http://estaticos.elmundo.es/elmundo/rss/madrid.xml'), |
| 66 |
('Barcelona', 'http://estaticos.elmundo.es/elmundo/rss/barcelona.xml'), |
| 67 |
('Pa\xeds Vasco', 'http://estaticos.elmundo.es/elmundo/rss/paisvasco.xml'), |
| 68 |
('Baleares', 'http://estaticos.elmundo.es/elmundo/rss/baleares.xml'), |
| 69 |
('Castilla y Le\xf3n', 'http://estaticos.elmundo.es/elmundo/rss/castillayleon.xml'), |
| 70 |
('Valladolid', 'http://estaticos.elmundo.es/elmundo/rss/valladolid.xml'), |
| 71 |
('Valencia', 'http://estaticos.elmundo.es/elmundo/rss/valencia.xml'), |
| 72 |
('Alicante', 'http://estaticos.elmundo.es/elmundo/rss/alicante.xml'), |
| 73 |
('Castell\xf3n', 'http://estaticos.elmundo.es/elmundo/rss/castellon.xml'), |
| 74 |
('Andaluc\xeda', 'http://estaticos.elmundo.es/elmundo/rss/andalucia.xml'), |
| 75 |
('Sevilla', 'http://estaticos.elmundo.es/elmundo/rss/andalucia_sevilla.xml'), |
| 76 |
('M\xe1laga', 'http://estaticos.elmundo.es/elmundo/rss/andalucia_malaga.xml'), |
| 77 |
] |
| 78 |
|
| 79 |
def get_cover_url(self): |
| 80 |
cover = self.masthead_url |
| 81 |
st = time.localtime() |
| 82 |
year = str(st.tm_year) |
| 83 |
month = '%.2d' % st.tm_mon |
| 84 |
day = '%.2d' % st.tm_mday |
| 85 |
cover = 'http://img.kiosko.net/' + '/'.join([year, month, day]) + '/es/elmundo.750.jpg' |
| 86 |
try: |
| 87 |
self.browser.open(cover) |
| 88 |
except Exception: |
| 89 |
self.log('\nPortada no disponible') |
| 90 |
return cover |
| 91 |
|
| 92 |
def get_obfuscated_article(self, url): |
| 93 |
count = 0 |
| 94 |
tries = 5 |
| 95 |
html = None |
| 96 |
while count < tries: |
| 97 |
try: |
| 98 |
response = self.browser.open(url) |
| 99 |
html = response.read() |
| 100 |
count = tries |
| 101 |
except Exception: |
| 102 |
print('Retrying download...') |
| 103 |
count += 1 |
| 104 |
if html is not None: |
| 105 |
tfile = PersistentTemporaryFile('_fa.html') |
| 106 |
tfile.write(html) |
| 107 |
tfile.close() |
| 108 |
self.temp_files.append(tfile) |
| 109 |
return tfile.name |
| 110 |
return None |
| 111 |
|
| 112 |
def image_url_processor(self, baseurl, url): |
| 113 |
if url.startswith('//'): |
| 114 |
return 'http:' + url |
| 115 |
if url.startswith('file://'): |
| 116 |
return url.replace('file://', 'http://') |
| 117 |
return url |