Debian Codegraph @

recipes/el_correo.recipe

raw
1 #!/usr/bin/env python
2 # vim:fileencoding=utf-8
3 """
4 http://www.elcorreo.com/
5 """
6
7 from calibre.web.feeds.news import BasicNewsRecipe, classes
8
9
10 class elcorreo(BasicNewsRecipe):
11 title = 'El Correo'
12 __author__ = 'unkn0wn'
13 description = 'Daily newspaper in Bilbao and the Basque Country of northern Spain'
14 oldest_article = 1 # days
15 language = 'es'
16 no_stylesheets = True
17 remove_attributes = ['height', 'width', 'style']
18 ignore_duplicate_articles = {'url'}
19 encoding = 'utf-8'
20 masthead_url = 'https://s1.ppllstatics.com/starfish/1.3.76/assets/images/logos/logo-elcorreo.svg'
21 remove_empty_feeds = True
22 resolve_internal_links = True
23 max_articles_per_feed = 25 # articles
24 compress_news_images = True
25
26 recipe_specific_options = {
27 'days': {
28 'short': 'Oldest article to download from this news source. In days ',
29 'long': 'For example, 0.5, gives you articles from the past 12 hours',
30 'default': str(oldest_article),
31 }
32 }
33
34 def __init__(self, *args, **kwargs):
35 BasicNewsRecipe.__init__(self, *args, **kwargs)
36 d = self.recipe_specific_options.get('days')
37 if d and isinstance(d, str):
38 self.oldest_article = float(d)
39
40 extra_css = '''
41 .v-mdl-ath__inf, .v-mdl-ath__p--2, .v-mdl-ath__p {font-size:small; color:#404040;}
42 .v-fc, .v-a-fig { text-align:center; font-size:small; }
43 #sub { font-style:italic; color:#202020; }
44 blockquote, em { color:#202020; }
45 img { display:block; margin:0 auto; }
46 '''
47
48 def get_cover_url(self):
49 from datetime import date
50
51 return 'https://portada.iperiodico.es/' + date.today().strftime('%Y/%m/%d') + '_elcorreo.750.jpg'
52
53 keep_only_tags = [
54 dict(name='article', attrs={'class': lambda x: x and set(x.split()).intersection({'v-a--d-bs', 'v-a--d-opn', 'v-a--d-rpg'})}),
55 classes('v-d--ab-c v-d--rpg'),
56 ]
57
58 remove_tags = [
59 dict(name=['svg', 'section', 'nav']),
60 dict(attrs={'data-voc-component': ['dropdown', 'modal', 'slider-grab']}),
61 classes(
62 'v-mdl-ath__img-c v-adv v-i-b v-mdl-ath__c--2 v-d-cmp-adv v-d-cmp-nws v-pill-m--zoom v-stk-adv slider-grab g-artboard v-d-cmp-rld v-pill-m--glly'
63 ),
64 ]
65
66 def preprocess_html(self, soup):
67 art = soup.find('article')
68 h1 = soup.find('h1')
69 h2 = soup.find('h2')
70 if h1 and art:
71 art.insert_before(h1)
72 if h2 and h1:
73 h1.insert_after(h2)
74 h2.name = 'p'
75 h2['id'] = 'sub'
76 for but in soup.findAll('button'):
77 if but.find('img'):
78 but.name = 'div'
79 else:
80 but.extract()
81 x = soup.find(**classes('v-mdl-ath__c'))
82 if x:
83 for p in x.findAll('p'):
84 p.name = 'div'
85 return soup
86
87 def get_browser(self, *args, **kwargs):
88 kwargs['user_agent'] = 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
89 br = BasicNewsRecipe.get_browser(self, *args, **kwargs)
90 br.addheaders += [('Referer', 'https://www.google.com/'), ('X-Forwarded-For', '66.249.66.1')]
91 return br
92
93 # https://www.elcorreo.com/rss/
94 feeds = [
95 ('Portada', 'http://www.elcorreo.com/rss/atom/portada'),
96 ('Mundo', 'http://www.elcorreo.com/rss/atom/?section=internacional'),
97 ('Bizkaia', 'http://www.elcorreo.com/rss/atom/?section=bizkaia'),
98 ('Opinión', 'https://www.elcorreo.com/rss/atom/?section=opinion'),
99 ('Internacional', 'https://www.elcorreo.com/rss/atom/?section=internacional'),
100 ('Ciencia', 'https://www.elcorreo.com/rss/atom/?section=ciencia'),
101 # ('Guipuzkoa', 'http://www.elcorreo.com/rss/atom/?section=gipuzkoa'),
102 # ('Araba', 'http://www.elcorreo.com/rss/atom/?section=araba'),
103 # ('La Rioja', 'http://www.elcorreo.com/rss/atom/?section=larioja'),
104 # ('Miranda', 'http://www.elcorreo.com/rss/atom/?section=miranda'),
105 ('Economía', 'http://www.elcorreo.com/rss/atom/?section=economia'),
106 # ('Culturas', 'http://www.elcorreo.com/rss/atom/?section=culturas'),
107 ('Politica', 'http://www.elcorreo.com/rss/atom/?section=politica'),
108 # ('De tiendas', 'https://www.elcorreo.com/rss/atom/?section=de-tiendas'),
109 # ('Elecciones', 'https://www.elcorreo.com/rss/atom/?section=elecciones'),
110 # ('Sociedad', 'https://www.elcorreo.com/rss/atom/?section=sociedad'),
111 # ('Vivir', 'https://www.elcorreo.com/rss/atom/?section=vivir'),
112 ('Tecnología', 'http://www.elcorreo.com/rss/atom/?section=tecnologia'),
113 # ('Gente - Estilo', 'http://www.elcorreo.com/rss/atom/?section=gente-estilo'),
114 # ('Planes', 'http://www.elcorreo.com/rss/atom/?section=planes'),
115 # ('Athletic', 'http://www.elcorreo.com/rss/atom/?section=athletic'),
116 # ('Alavés', 'http://www.elcorreo.com/rss/atom/?section=alaves'),
117 # ('Bilbao Basket', 'http://www.elcorreo.com/rss/atom/?section=bilbaobasket'),
118 # ('Baskonia', 'http://www.elcorreo.com/rss/atom/?section=baskonia'),
119 ('Deportes', 'http://www.elcorreo.com/rss/atom/?section=deportes'),
120 # ('Jaiak', 'http://www.elcorreo.com/rss/atom/?section=jaiak'),
121 # ('La Blanca', 'http://www.elcorreo.com/rss/atom/?section=la-blanca-vitoria'),
122 # ('Aste Nagusia', 'http://www.elcorreo.com/rss/atom/?section=aste-nagusia-bilbao'),
123 # ('Semana Santa', 'http://www.elcorreo.com/rss/atom/?section=semana-santa'),
124 # ('Festivales', 'http://www.elcorreo.com/rss/atom/?section=festivales')
125 ]