mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update El Diplo
Fixes #1891216 [New recipe for Le Monde Diplomatique - cono sur](https://bugs.launchpad.net/calibre/+bug/1891216)
This commit is contained in:
parent
2912b411f9
commit
3523a126dc
@ -1,123 +1,103 @@
|
|||||||
# Copyright 2013 Tomás Di Domenico
|
# -*- mode: python; coding: utf-8; -*-
|
||||||
#
|
# vim: set syntax=python fileencoding=utf-8
|
||||||
# This is a news fetching recipe for the Calibre ebook software, for
|
|
||||||
# fetching the Cono Sur edition of Le Monde Diplomatique (www.eldiplo.org).
|
|
||||||
#
|
|
||||||
# This recipe is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This software is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this recipe. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
import re
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
from contextlib import closing
|
__license__ = 'GPL v3'
|
||||||
from calibre.web.feeds.recipes import BasicNewsRecipe
|
__copyright__ = '2020, Darko Miletic <darko.miletic at gmail.com>'
|
||||||
|
|
||||||
|
'''
|
||||||
|
www.eldiplo.org
|
||||||
|
'''
|
||||||
|
|
||||||
|
from calibre.web.feeds.news import BasicNewsRecipe
|
||||||
from calibre.ptempfile import PersistentTemporaryFile
|
from calibre.ptempfile import PersistentTemporaryFile
|
||||||
from calibre.utils.magick import Image
|
|
||||||
|
|
||||||
|
|
||||||
class ElDiplo_Recipe(BasicNewsRecipe):
|
class ElDiplo2020(BasicNewsRecipe):
|
||||||
title = u'El Diplo'
|
title = 'Le Monde Diplomatique - cono sur'
|
||||||
__author__ = 'Tomas Di Domenico'
|
__author__ = 'Darko Miletic'
|
||||||
description = 'Publicacion mensual de Le Monde Diplomatique, edicion Argentina'
|
description = 'Publicación de Le Monde Diplomatique para el cono sur.'
|
||||||
|
publisher = 'Le Monde Diplomatique'
|
||||||
|
category = 'news, politics, Argentina, Uruguay, Paraguay, South America, World'
|
||||||
|
oldest_article = 31
|
||||||
|
no_stylesheets = True
|
||||||
|
encoding = 'utf8'
|
||||||
|
use_embedded_content = False
|
||||||
language = 'es_AR'
|
language = 'es_AR'
|
||||||
needs_subscription = True
|
remove_empty_feeds = True
|
||||||
|
publication_type = 'magazine'
|
||||||
auto_cleanup = True
|
auto_cleanup = True
|
||||||
|
delay = 1
|
||||||
|
simultaneous_downloads = 1
|
||||||
|
timeout = 8
|
||||||
|
needs_subscription = 'optional'
|
||||||
|
ignore_duplicate_articles = {'url'}
|
||||||
|
articles_are_obfuscated = True
|
||||||
|
temp_files = []
|
||||||
|
fetch_retries = 10
|
||||||
|
handle_gzip = True
|
||||||
|
compress_news_images = True
|
||||||
|
scale_news_images_to_device = True
|
||||||
|
masthead_url = 'https://www.eldiplo.org/wp-content/themes/eldiplo/img/logo.png'
|
||||||
|
INDEX = 'https://www.eldiplo.org/'
|
||||||
|
|
||||||
def get_cover(self, url):
|
extra_css = """
|
||||||
tmp_cover = PersistentTemporaryFile(suffix=".jpg", prefix="eldiplo_")
|
body{font-family: Roboto, sans-serif}
|
||||||
self.cover_url = tmp_cover.name
|
.entry-title{font-family: Spectral, serif}
|
||||||
|
"""
|
||||||
|
|
||||||
with closing(self.browser.open(url)) as r:
|
conversion_options = {
|
||||||
imgdata = r.read()
|
'comment': description, 'tags': category, 'publisher': publisher, 'language': language
|
||||||
|
}
|
||||||
img = Image()
|
|
||||||
img.load(imgdata)
|
|
||||||
img.crop(img.size[0], img.size[1] / 2, 0, 0)
|
|
||||||
|
|
||||||
img.save(tmp_cover.name)
|
|
||||||
|
|
||||||
def get_browser(self):
|
def get_browser(self):
|
||||||
br = BasicNewsRecipe.get_browser(self)
|
br = BasicNewsRecipe.get_browser(self)
|
||||||
|
br.open(self.INDEX)
|
||||||
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://www.eldiplo.org/index.php/login/-/do_login/index.html')
|
br.select_form(id='loginform')
|
||||||
br.select_form(nr=3)
|
br['log'] = self.username
|
||||||
br['uName'] = self.username
|
br['pwd'] = self.password
|
||||||
br['uPassword'] = self.password
|
|
||||||
br.submit()
|
br.submit()
|
||||||
self.browser = br
|
|
||||||
return br
|
return br
|
||||||
|
|
||||||
def parse_index(self):
|
def parse_index(self):
|
||||||
default_sect = 'General'
|
articles = []
|
||||||
articles = {default_sect: []}
|
soup = self.index_to_soup(self.INDEX)
|
||||||
ans = [default_sect]
|
mylink = soup.find('a', {'class':'edicion_cover'})
|
||||||
sectionsmarker = 'DOSSIER_TITLE: '
|
if mylink is None:
|
||||||
sectionsre = re.compile('^' + sectionsmarker)
|
return None
|
||||||
|
self.cover_url = mylink.img['src']
|
||||||
|
indexurl = mylink['href']
|
||||||
|
self.log(indexurl)
|
||||||
|
parts = indexurl.split('www.eldiplo.org/', 1)
|
||||||
|
series = parts[1].split('-', 1)[0]
|
||||||
|
self.conversion_options.update({'series' : self.title})
|
||||||
|
self.conversion_options.update({'series_index' : series})
|
||||||
|
soupindex = self.index_to_soup(indexurl)
|
||||||
|
totalfeeds = []
|
||||||
|
articles = []
|
||||||
|
for article in soupindex.findAll('a', href=True, attrs={'class':'title'}):
|
||||||
|
url = article['href']
|
||||||
|
title = self.tag_to_string(article)
|
||||||
|
articles.append({'title': title, 'url': url, 'description': '', 'date': ''})
|
||||||
|
self.log('title: ', title, ' url: ', url)
|
||||||
|
totalfeeds.append(('Articles',articles))
|
||||||
|
return totalfeeds
|
||||||
|
|
||||||
soup = self.index_to_soup('http://www.eldiplo.org/index.php')
|
def get_obfuscated_article(self, url):
|
||||||
|
result = None
|
||||||
coverdivs = soup.findAll(True, attrs={'id': ['lmd-foto']})
|
count = 0
|
||||||
a = coverdivs[0].find('a', href=True)
|
while (count < self.fetch_retries):
|
||||||
coverurl = a['href'].split("?imagen=")[1]
|
try:
|
||||||
self.get_cover(coverurl)
|
response = self.browser.open(url, timeout=self.timeout)
|
||||||
|
html = response.read()
|
||||||
thedivs = soup.findAll(True, attrs={'class': ['lmd-leermas']})
|
count = self.fetch_retries
|
||||||
for div in thedivs:
|
tfile = PersistentTemporaryFile('_fa.html')
|
||||||
a = div.find('a', href=True)
|
tfile.write(html)
|
||||||
if 'Sumario completo' in self.tag_to_string(a, use_alt=True):
|
tfile.close()
|
||||||
summaryurl = re.sub(r'\?.*', '', a['href'])
|
self.temp_files.append(tfile)
|
||||||
summaryurl = 'http://www.eldiplo.org' + summaryurl
|
result = tfile.name
|
||||||
|
except:
|
||||||
for pagenum in range(1, 10):
|
self.info("Retrying download...")
|
||||||
soup = self.index_to_soup(
|
count += 1
|
||||||
'{0}/?cms1_paging_p_b32={1}'.format(summaryurl, pagenum))
|
return result
|
||||||
thedivs = soup.findAll(True, attrs={'class': ['interna']})
|
|
||||||
|
|
||||||
if len(thedivs) == 0:
|
|
||||||
break
|
|
||||||
|
|
||||||
for div in thedivs:
|
|
||||||
section = div.find(True, text=sectionsre).replace(
|
|
||||||
sectionsmarker, '')
|
|
||||||
if section == '':
|
|
||||||
section = default_sect
|
|
||||||
|
|
||||||
if section not in articles.keys():
|
|
||||||
articles[section] = []
|
|
||||||
ans.append(section)
|
|
||||||
|
|
||||||
nota = div.find(
|
|
||||||
True, attrs={'class': ['lmd-pl-titulo-nota-dossier']})
|
|
||||||
a = nota.find('a', href=True)
|
|
||||||
if not a:
|
|
||||||
continue
|
|
||||||
|
|
||||||
url = re.sub(r'\?.*', '', a['href'])
|
|
||||||
url = 'http://www.eldiplo.org' + url
|
|
||||||
title = self.tag_to_string(a, use_alt=True).strip()
|
|
||||||
|
|
||||||
summary = div.find(
|
|
||||||
True, attrs={'class': 'lmd-sumario-descript'}).find('p')
|
|
||||||
if summary:
|
|
||||||
description = self.tag_to_string(summary, use_alt=False)
|
|
||||||
|
|
||||||
aut = div.find(True, attrs={'class': 'lmd-autor-sumario'})
|
|
||||||
if aut:
|
|
||||||
auth = self.tag_to_string(aut, use_alt=False).strip()
|
|
||||||
|
|
||||||
if section not in articles: # noqa
|
|
||||||
articles[section] = []
|
|
||||||
|
|
||||||
articles[section].append(dict(
|
|
||||||
title=title, author=auth, url=url, date=None, description=description, content=''))
|
|
||||||
|
|
||||||
ans = [(s, articles[s]) for s in ans if s in articles]
|
|
||||||
return ans
|
|
||||||
|
BIN
recipes/icons/el_diplo.png
Normal file
BIN
recipes/icons/el_diplo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 438 B |
Loading…
x
Reference in New Issue
Block a user