| 1 |
#!/usr/bin/env python |
| 2 |
__license__ = 'GPL v3' |
| 3 |
__author__ = 'Alvaro Beiro, improving Jordi Balcells work based on an earlier version by Lorenzo Vigentini & Kovid Goyal' |
| 4 |
__copyright__ = '2008, Kovid Goyal [email protected]' |
| 5 |
description = 'Main daily newspaper from Spain - v1.05 (13, March 2023)' |
| 6 |
__docformat__ = 'restructuredtext en' |
| 7 |
|
| 8 |
''' |
| 9 |
elpais.es |
| 10 |
''' |
| 11 |
|
| 12 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 13 |
|
| 14 |
|
| 15 |
class ElPais(BasicNewsRecipe): |
| 16 |
__author__ = 'Kovid Goyal & Lorenzo Vigentini & Jordi Balcells & Alvaro Beiro' |
| 17 |
description = 'Main daily newspaper from Spain' |
| 18 |
|
| 19 |
title = 'El Pa\xeds' |
| 20 |
publisher = 'Ediciones El Pa\xeds SL' |
| 21 |
category = 'News, politics, culture, economy, general interest' |
| 22 |
publication_type = 'newspaper' |
| 23 |
|
| 24 |
language = 'es' |
| 25 |
timefmt = '[%a, %d %b, %Y]' |
| 26 |
|
| 27 |
oldest_article = 2.1 |
| 28 |
max_articles_per_feed = 25 |
| 29 |
|
| 30 |
recipe_specific_options = { |
| 31 |
'days': { |
| 32 |
'short': 'Oldest article to download from this news source. In days ', |
| 33 |
'long': 'For example, 0.5, gives you articles from the past 12 hours', |
| 34 |
'default': str(oldest_article), |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
def __init__(self, *args, **kwargs): |
| 39 |
BasicNewsRecipe.__init__(self, *args, **kwargs) |
| 40 |
d = self.recipe_specific_options.get('days') |
| 41 |
if d and isinstance(d, str): |
| 42 |
self.oldest_article = float(d) |
| 43 |
|
| 44 |
use_embedded_content = False |
| 45 |
recursion = 5 |
| 46 |
|
| 47 |
remove_javascript = True |
| 48 |
no_stylesheets = True |
| 49 |
|
| 50 |
extra_css = ''' |
| 51 |
span._db {max-width: 100%; height: auto;} |
| 52 |
.a_m_p {font-size: .75rem;} |
| 53 |
.a_m_m {text-transform: uppercase; padding-top: 0.5rem;} |
| 54 |
div.a_md_a {text-align: center; text-transform: uppercase; font-size: .8rem;} |
| 55 |
''' |
| 56 |
|
| 57 |
keep_only_tags = [ |
| 58 |
dict( |
| 59 |
attrs={ |
| 60 |
'class': [ |
| 61 |
'article_header', |
| 62 |
'article_body', |
| 63 |
'a_t', |
| 64 |
'a_st', |
| 65 |
'articulo-titulares', |
| 66 |
'articulo-apertura', |
| 67 |
'articulo__contenedora_e_m', |
| 68 |
'a_md_a', |
| 69 |
] |
| 70 |
} |
| 71 |
), |
| 72 |
dict( |
| 73 |
name='div', |
| 74 |
attrs={ |
| 75 |
'class': 'a_c', |
| 76 |
}, |
| 77 |
), |
| 78 |
] |
| 79 |
|
| 80 |
remove_tags = [ |
| 81 |
dict( |
| 82 |
attrs={ |
| 83 |
'class': [ |
| 84 |
'sumario__interior', |
| 85 |
'articulo-trust', |
| 86 |
'compartir', |
| 87 |
'articulo-tags', |
| 88 |
'outbrain', |
| 89 |
'more_info', |
| 90 |
'articulo-apoyos', |
| 91 |
'top10', |
| 92 |
'a_ei', |
| 93 |
'w-cta', |
| 94 |
'ph-v_b', |
| 95 |
] |
| 96 |
}, |
| 97 |
), |
| 98 |
dict(id='cta_id'), |
| 99 |
dict(name='svg'), |
| 100 |
] |
| 101 |
|
| 102 |
remove_attributes = ['width', 'height'] |
| 103 |
|
| 104 |
feeds = [ |
| 105 |
('Espa\xf1a', 'https://feeds.elpais.com/mrss-s/pages/ep/site/elpais.com/section/espana/portada'), |
| 106 |
('Internacional', 'https://feeds.elpais.com/mrss-s/pages/ep/site/elpais.com/section/internacional/portada'), |
| 107 |
('Economía', 'https://feeds.elpais.com/mrss-s/pages/ep/site/elpais.com/section/economia/portada'), |
| 108 |
('Opinión', 'http://ep00.epimg.net/rss/elpais/opinion.xml'), |
| 109 |
('Ciencia', 'https://feeds.elpais.com/mrss-s/pages/ep/site/elpais.com/section/ciencia/portada'), |
| 110 |
('Tecnología', 'https://feeds.elpais.com/mrss-s/pages/ep/site/elpais.com/section/tecnologia/portada'), |
| 111 |
('Cultura', 'https://feeds.elpais.com/mrss-s/pages/ep/site/elpais.com/section/cultura/portada'), |
| 112 |
('Estilo', 'https://feeds.elpais.com/mrss-s/pages/ep/site/elpais.com/section/estilo/portada'), |
| 113 |
('Deportes', 'https://feeds.elpais.com/mrss-s/pages/ep/site/elpais.com/section/deportes/portada'), |
| 114 |
('Televisión', 'https://feeds.elpais.com/mrss-s/pages/ep/site/elpais.com/section/television/portada'), |
| 115 |
('Sociedad', 'https://feeds.elpais.com/mrss-s/pages/ep/site/elpais.com/section/sociedad/portada'), |
| 116 |
('Blogs', 'http://ep01.epimg.net/rss/elpais/blogs.xml'), |
| 117 |
] |
| 118 |
|
| 119 |
def get_cover_url(self): |
| 120 |
from datetime import date |
| 121 |
|
| 122 |
cover = ( |
| 123 |
'https://srv00.epimg.net/pdf/elpais/snapshot/' |
| 124 |
+ str(date.today().year) |
| 125 |
+ '/' |
| 126 |
+ date.today().strftime('%m') |
| 127 |
+ '/elpais/' |
| 128 |
+ str(date.today().year) |
| 129 |
+ date.today().strftime('%m') |
| 130 |
+ date.today().strftime('%d') |
| 131 |
+ 'Big.jpg' |
| 132 |
) |
| 133 |
br = BasicNewsRecipe.get_browser(self) |
| 134 |
try: |
| 135 |
br.open(cover) |
| 136 |
except Exception: |
| 137 |
self.log('\nCover unavailable') |
| 138 |
cover = None |
| 139 |
return cover |
| 140 |
|
| 141 |
def image_url_processor(cls, baseurl, url): |
| 142 |
splitUrl = url.split('cloudfront-') |
| 143 |
parsedUrl = 'https://cloudfront-' + splitUrl[1] |
| 144 |
return parsedUrl |