Debian Codegraph @

recipes/le_gorafi.recipe

raw
1 from __future__ import unicode_literals
2
3 __license__ = 'GPL v3'
4 __copyright__ = '2013, Malah <malah at neuf dot fr>'
5 '''
6 Le GORAFI.fr
7 '''
8
9 __author__ = '2013, Malah <malah at neuf dot fr>'
10 from calibre.web.feeds.news import BasicNewsRecipe
11
12
13 class LeGorafi(BasicNewsRecipe):
14 title = 'Le GORAFI.fr'
15 __author__ = 'Malah, LAntoine'
16 description = "Depuis 1826, toute l'information de sources contradictoires"
17 oldest_article = 7
18 language = 'fr'
19 max_articles_per_feed = 100
20 use_embedded_content = False
21 no_stylesheets = True
22 compress_news_images = True
23 extra_css = '''
24 img {
25 max-width: 100% !important;
26 height: auto !important;
27 }
28 '''
29
30 keep_only_tags = [
31 dict(name='h1'),
32 dict(name='img', attrs={'class': 'attachment- size- wp-post-image'}),
33 dict(name='div', attrs={'id': 'mvp-content-main'}),
34 ]
35 remove_tags = [
36 dict(name='div', attrs={'class': 'heateor_sss_sharing_container'}),
37 ]
38 feeds = ['http://www.legorafi.fr/feed/']
39
40 def preprocess_html(self, soup):
41 for img in soup.findAll('img'):
42 if 'svg' in img['src']:
43 img.decompose() # Removes the tag entirely
44 return soup
45
46 def is_cover(article):
47 return 'gorafi-magazine' in article.url
48
49 def get_cover_url(self):
50 feeds = BasicNewsRecipe.parse_feeds(self)
51 for feed in feeds:
52 for article in feed.articles:
53 if LeGorafi.is_cover(article):
54 soup = self.index_to_soup(article.url)
55 img = soup.select_one('#mvp-post-feat-img img')
56 return img['data-lazy-src']
57 print('No cover found')
58 return None
59
60 def parse_feeds(self):
61 feeds = BasicNewsRecipe.parse_feeds(self)
62 for feed in feeds:
63 for article in feed.articles:
64 if LeGorafi.is_cover(article):
65 feed.articles.remove(article)
66 return feeds