Debian Codegraph @

recipes/la_republica.recipe

raw
1 from __future__ import print_function
2
3 __license__ = 'GPL v3'
4 __author__ = 'Lorenzo Vigentini, based on Darko Miletic, Gabriele Marini; minor fixes by faber1971'
5 __copyright__ = '2009-2012, Darko Miletic <darko.miletic at gmail.com>, Lorenzo Vigentini <l.vigentini at gmail.com>, faber1971'
6
7 '''
8 http://www.repubblica.it/
9 '''
10
11 from calibre.ptempfile import PersistentTemporaryFile
12 from calibre.web.feeds.news import BasicNewsRecipe
13
14
15 class LaRepubblica(BasicNewsRecipe):
16 title = 'La Repubblica'
17 __author__ = 'Lorenzo Vigentini, Gabriele Marini, Darko Miletic, faber1971'
18 description = 'il quotidiano online con tutte le notizie in tempo reale. News e ultime notizie. Tutti i settori: politica, cronaca, economia, sport, esteri, scienza, tecnologia, internet, spettacoli, musica, cultura, arte, mostre, libri, dvd, vhs, concerti, cinema, attori, attrici, recensioni, chat, cucina, mappe. Le citta di Repubblica: Roma, Milano, Bologna, Firenze, Palermo, Napoli, Bari, Torino.' # noqa: E501
19 masthead_url = 'http://www.repubblica.it/static/images/homepage/2010/la-repubblica-logo-home-payoff.png'
20 publisher = "Gruppo editoriale L'Espresso"
21 category = 'News, politics, culture, economy, general interest'
22 language = 'it'
23 timefmt = '[%a, %d %b, %Y]'
24 oldest_article = 1
25 encoding = 'utf8'
26 use_embedded_content = False
27 no_stylesheets = True
28 publication_type = 'newspaper'
29 articles_are_obfuscated = True
30 temp_files = []
31 extra_css = '''
32 img{display: block}
33 '''
34
35 remove_attributes = ['width', 'height', 'lang', 'xmlns:og', 'xmlns:fb']
36
37 def get_article_url(self, article):
38 link = BasicNewsRecipe.get_article_url(self, article)
39 if link and '.repubblica.it/' not in link:
40 link2 = article.get('id', article.get('guid', None))
41 if link2:
42 link = link2
43 return link.rpartition('?')[0]
44
45 def get_obfuscated_article(self, url):
46 count = 0
47 while count < 10:
48 try:
49 response = self.browser.open(url)
50 html = response.read()
51 count = 10
52 except Exception:
53 print('Retrying download...')
54 count += 1
55 self.temp_files.append(PersistentTemporaryFile('_fa.html'))
56 self.temp_files[-1].write(html)
57 self.temp_files[-1].close()
58 return self.temp_files[-1].name
59
60 keep_only_tags = [
61 dict(attrs={'class': 'articolo'}),
62 dict(attrs={'class': 'body-text'}),
63 dict(name='p', attrs={'class': 'disclaimer clearfix'}),
64 dict(name='div', attrs={'id': 'main'}),
65 dict(attrs={'id': 'contA'}),
66 ]
67
68 remove_tags = [
69 dict(name=['object', 'link', 'meta', 'iframe', 'embed']),
70 dict(name='span', attrs={'class': 'linkindice'}),
71 dict(name='div', attrs={'class': ['bottom-mobile', 'adv adv-middle-inline']}),
72 dict(name='div', attrs={'id': ['rssdiv', 'blocco', 'fb-like-head', 'sidebar']}),
73 dict(name='div', attrs={'class': ['utility', 'fb-like-button', 'archive-button']}),
74 dict(name='div', attrs={'class': 'generalbox'}),
75 dict(name='ul', attrs={'id': 'hystory'}),
76 ]
77
78 feeds = [
79 ('Homepage', 'http://www.repubblica.it/rss/homepage/rss2.0.xml'),
80 ('Cronaca', 'http://www.repubblica.it/rss/cronaca/rss2.0.xml'),
81 ('Esteri', 'http://www.repubblica.it/rss/esteri/rss2.0.xml'),
82 ('Economia', 'http://www.repubblica.it/rss/economia/rss2.0.xml'),
83 ('Politica', 'http://www.repubblica.it/rss/politica/rss2.0.xml'),
84 ('Scienze', 'http://www.repubblica.it/rss/scienze/rss2.0.xml'),
85 ('Tecnologia', 'http://www.repubblica.it/rss/tecnologia/rss2.0.xml'),
86 ('Scuola e Universita', 'http://www.repubblica.it/rss/scuola_e_universita/rss2.0.xml'),
87 ('Ambiente', 'http://www.repubblica.it/rss/ambiente/rss2.0.xml'),
88 ('Cultura', 'http://www.repubblica.it/rss/spettacoli_e_cultura/rss2.0.xml'),
89 ('Persone', 'http://www.repubblica.it/rss/persone/rss2.0.xml'),
90 ('Sport', 'http://www.repubblica.it/rss/sport/rss2.0.xml'),
91 ('Calcio', 'http://www.repubblica.it/rss/sport/calcio/rss2.0.xml'),
92 ('Motori', 'http://www.repubblica.it/rss/motori/rss2.0.xml'),
93 ('Roma', 'http://roma.repubblica.it/rss/rss2.0.xml'),
94 ('Torino', 'http://torino.repubblica.it/rss/rss2.0.xml'),
95 ('Milano', 'feed://milano.repubblica.it/rss/rss2.0.xml'),
96 ('Napoli', 'feed://napoli.repubblica.it/rss/rss2.0.xml'),
97 ('Bari', 'http://bari.repubblica.it/rss/rss2.0.xml'),
98 ('Palermo', 'feed://palermo.repubblica.it/rss/rss2.0.xml'),
99 ]
100
101 def preprocess_html(self, soup):
102 for item in soup.findAll(['hgroup', 'deresponsabilizzazione', 'per']):
103 item.name = 'div'
104 item.attrs = []
105 for item in soup.findAll(style=True):
106 del item['style']
107 return soup
108
109 def preprocess_raw_html(self, raw, url):
110 return '<html><head>' + raw[raw.find('</head>') :]