mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
Update Liberation
This commit is contained in:
parent
70feb562be
commit
691a07dd45
@ -1,7 +1,10 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
# vim:fileencoding=utf-8
|
||||||
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Darko Miletic <darko.miletic at gmail.com>'
|
__copyright__ = '2008, Darko Miletic <darko.miletic at gmail.com>'
|
||||||
|
|
||||||
'''
|
'''
|
||||||
liberation.fr
|
liberation.fr
|
||||||
'''
|
'''
|
||||||
@ -10,61 +13,70 @@ from calibre.web.feeds.news import BasicNewsRecipe
|
|||||||
|
|
||||||
|
|
||||||
class Liberation(BasicNewsRecipe):
|
class Liberation(BasicNewsRecipe):
|
||||||
|
title = 'Libération'
|
||||||
title = u'Liberation'
|
|
||||||
__author__ = 'calibre'
|
__author__ = 'calibre'
|
||||||
description = 'Actualités'
|
description = 'Actualités'
|
||||||
category = 'Actualités, France, Monde'
|
publication_type = 'newspaper'
|
||||||
language = 'fr'
|
language = 'fr'
|
||||||
|
|
||||||
use_embedded_content = False
|
oldest_article = 2
|
||||||
timefmt = ' [%d %b %Y]'
|
max_articles_per_feed = 30
|
||||||
max_articles_per_feed = 15
|
|
||||||
no_stylesheets = True
|
no_stylesheets = True
|
||||||
remove_empty_feeds = True
|
remove_empty_feeds = True
|
||||||
|
ignore_duplicate_articles = {'title', 'url'}
|
||||||
needs_subscription = 'optional'
|
needs_subscription = 'optional'
|
||||||
|
|
||||||
keep_only_tags = [dict(name='article')]
|
masthead_url = 'https://www.liberation.fr/pf/resources/images/liberation.png?d=47'
|
||||||
remove_tags = [dict(attrs={'class': ['tool-bar']})]
|
|
||||||
|
|
||||||
feeds = [
|
feeds = [
|
||||||
|
('Libération', 'https://www.liberation.fr/arc/outboundfeeds/rss/?outputType=xml'),
|
||||||
(u'La une', u'http://rss.liberation.fr/rss/9/'),
|
('Accueil', 'https://www.liberation.fr/arc/outboundfeeds/collection/accueil-une/?outputType=xml')
|
||||||
(u'Monde', u'http://www.liberation.fr/rss/10/'),
|
|
||||||
(u'Économie', u'http://www.liberation.fr/rss/13/'),
|
|
||||||
(u'Politiques', u'http://www.liberation.fr/rss/11/'),
|
|
||||||
(u'Société', u'http://www.liberation.fr/rss/12/'),
|
|
||||||
(u'Cinéma', u'http://www.liberation.fr/rss/58/'),
|
|
||||||
(u'Écran', u'http://www.liberation.fr/rss/53/'),
|
|
||||||
(u'Sports', u'http://www.liberation.fr/rss/12/')
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
keep_only_tags = [
|
||||||
|
dict(name='div', attrs={'class': 'left-article-section'})
|
||||||
|
]
|
||||||
|
|
||||||
|
remove_tags = [
|
||||||
|
dict(name=['button', 'source']),
|
||||||
|
dict(attrs={'class': ['ts-share-bar']}),
|
||||||
|
dict(name='div', attrs={'class': [
|
||||||
|
'article-dossier', 'color_background_green', 'display_block', 'tag-container'
|
||||||
|
]})
|
||||||
|
]
|
||||||
|
|
||||||
|
remove_attributes = [
|
||||||
|
'height', 'width'
|
||||||
|
]
|
||||||
|
|
||||||
|
extra_css = '''
|
||||||
|
h2, h3, h4, h5, h6 { font-size: 1em; }
|
||||||
|
.image-metadata { font-size: 0.6em; margin-top: 0em; margin-bottom: 1.6em; }
|
||||||
|
'''
|
||||||
|
|
||||||
def get_browser(self):
|
def get_browser(self):
|
||||||
br = BasicNewsRecipe.get_browser(self)
|
br = BasicNewsRecipe.get_browser(self)
|
||||||
if self.username is not None and self.password is not None:
|
if self.username is not None and self.password is not None:
|
||||||
br.open('http://token.liberation.fr/accounts/login/')
|
try:
|
||||||
br.select_form(nr=0)
|
br.open('http://token.liberation.fr/accounts/login/')
|
||||||
br['email'] = self.username
|
br.select_form(nr=0)
|
||||||
br['password'] = self.password
|
br['email'] = self.username
|
||||||
br.submit()
|
br['password'] = self.password
|
||||||
|
br.submit()
|
||||||
|
except Exception as e:
|
||||||
|
self.log('Login failed with error: ' + str(e))
|
||||||
return br
|
return br
|
||||||
|
|
||||||
def get_masthead_url(self):
|
def get_cover_url(self):
|
||||||
masthead = 'http://s0.libe.com/libe/img/common/logo-liberation-150.png'
|
soup = self.index_to_soup('https://journal.liberation.fr/')
|
||||||
br = BasicNewsRecipe.get_browser(self)
|
cover = soup.find(name='img', attrs={'class': 'ui image'})
|
||||||
try:
|
if cover is not None and cover['src'] is not None:
|
||||||
br.open(masthead)
|
self.cover_url = 'https:' + cover['src']
|
||||||
except:
|
return self.cover_url
|
||||||
self.log("\nCover unavailable")
|
|
||||||
masthead = None
|
|
||||||
return masthead
|
|
||||||
|
|
||||||
def get_article_url(self, article):
|
def postprocess_html(self, soup, first_fetch):
|
||||||
url = BasicNewsRecipe.get_article_url(self, article)
|
# remove local hyperlinks
|
||||||
url = url.split('/')[-2]
|
for a in soup.find_all('a', {'href': True}):
|
||||||
encoding = {'0B': '.', '0C': '/', '0A': '0', '0F': '=', '0G': '&',
|
if '.liberation.fr/' in a['href']:
|
||||||
'0D': '?', '0E': '-', '0N': '.com', '0L': 'http://', '0S':
|
a.replace_with(self.tag_to_string(a))
|
||||||
'www.', '0I': '_'}
|
return soup
|
||||||
for k, v in encoding.items():
|
|
||||||
url = url.replace(k, v)
|
|
||||||
return url.partition('?')[0]
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user