Debian Codegraph @

recipes/lemonde_dip.recipe

raw
1 __license__ = 'GPL v3'
2 __copyright__ = '2008-2011, Darko Miletic <darko.miletic at gmail.com>'
3 '''
4 mondediplo.com
5 '''
6
7 try:
8 from urllib.parse import urlencode
9 except ImportError:
10 from urllib import urlencode
11 from calibre import strftime
12 from calibre.web.feeds.news import BasicNewsRecipe
13
14
15 class LeMondeDiplomatiqueEn(BasicNewsRecipe):
16 title = 'Le Monde diplomatique - English edition'
17 __author__ = 'Darko Miletic'
18 description = "Le Monde diplomatique is the place you go when you want to know what's really happening. This is a major international paper that is truly independent, that sees the world in fresh ways, that focuses on places no other publications reach. We offer a clear, considered view of the conflicting interests and complexities of a modern global world. LMD in English is a concise version of the Paris-based parent edition, publishing all the major stories each month, expertly translated, and with some London-based commissions too. We offer a taster of LMD quality on our website where a selection of articles are available each month." # noqa: E501
19 publisher = 'Le Monde diplomatique'
20 category = 'news, politics, world'
21 no_stylesheets = True
22 oldest_article = 31
23 delay = 1
24 encoding = 'utf-8'
25 needs_subscription = True
26 masthead_url = 'http://mondediplo.com/squelettes/pics/logo-30.gif'
27 publication_type = 'magazine'
28 PREFIX = 'http://mondediplo.com/'
29 LOGIN = PREFIX + '2009/09/02congo'
30 INDEX = PREFIX + strftime('%Y/%m/')
31 use_embedded_content = False
32 language = 'en'
33 extra_css = '''
34 body{font-family: "Luxi sans","Lucida sans","Lucida Grande",Lucida,"Lucida Sans Unicode",sans-serif}
35 .surtitre{font-size: 1.2em; font-variant: small-caps; margin-bottom: 0.5em}
36 .chapo{font-size: 1.2em; font-weight: bold; margin: 1em 0 0.5em}
37 .texte{font-family: Georgia,"Times New Roman",serif} h1{color: #990000}
38 .notes{border-top: 1px solid #CCCCCC; font-size: 0.9em; line-height: 1.4em}
39 '''
40
41 conversion_options = {'comment': description, 'tags': category, 'publisher': publisher, 'language': language}
42
43 def get_browser(self):
44 br = BasicNewsRecipe.get_browser(self)
45 br.open(self.LOGIN)
46 if self.username is not None and self.password is not None:
47 data = urlencode({'login': self.username, 'pass': self.password, 'enter': 'enter'})
48 br.open(self.LOGIN, data)
49 return br
50
51 keep_only_tags = [dict(name='div', attrs={'id': 'contenu'}), dict(name='div', attrs={'class': 'notes surlignable'})]
52 remove_tags = [dict(name=['object', 'link', 'script', 'iframe', 'base'])]
53 remove_attributes = ['height', 'width', 'name', 'lang']
54
55 def parse_index(self):
56 articles = []
57 soup = self.index_to_soup(self.INDEX)
58 cnt = soup.find('div', attrs={'class': 'som_num'})
59 for item in cnt.findAll('li'):
60 description = ''
61 feed_link = item.find('a', href=True)
62 if feed_link is None:
63 continue
64 desc = item.find('div', attrs={'class': 'chapo'})
65 if desc:
66 description = desc.string
67 url = self.PREFIX + feed_link['href'].partition('/../')[2]
68 title = self.tag_to_string(feed_link)
69 date = strftime(self.timefmt)
70 articles.append({'title': title, 'date': date, 'url': url, 'description': description})
71 return [(self.title, articles)]
72
73 def get_cover_url(self):
74 cover_url = None
75 soup = self.index_to_soup(self.INDEX)
76 cover_item = soup.find('div', attrs={'class': 'current'})
77 if cover_item:
78 ap = cover_item.find('img', attrs={'class': 'spip_logos'})
79 if ap:
80 cover_url = self.INDEX + ap['src']
81 return cover_url
82
83 def preprocess_html(self, soup):
84 for item in soup.findAll(style=True):
85 del item['style']
86 for item in soup.findAll('a'):
87 if item.string is not None:
88 str = item.string
89 item.replaceWith(str)
90 else:
91 str = self.tag_to_string(item)
92 item.replaceWith(str)
93 return soup