mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update Ambito and Ambito Financiero
Fix #1784857 [Updated recipe for Ambito.com and Ambito financiero](https://bugs.launchpad.net/calibre/+bug/1784857)
This commit is contained in:
parent
bab192fa6c
commit
2d263573cb
@ -2,7 +2,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008-2016, Darko Miletic <darko.miletic at gmail.com>'
|
__copyright__ = '2008-2018, Darko Miletic <darko.miletic at gmail.com>'
|
||||||
'''
|
'''
|
||||||
ambito.com
|
ambito.com
|
||||||
'''
|
'''
|
||||||
@ -39,6 +39,7 @@ class Ambito(BasicNewsRecipe):
|
|||||||
dict(name='h6', attrs={'class': lambda x: x and 'bajada' in x.split()})
|
dict(name='h6', attrs={'class': lambda x: x and 'bajada' in x.split()})
|
||||||
,dict(name='span', attrs={'class': lambda x: x and 'dia' in x.split()})
|
,dict(name='span', attrs={'class': lambda x: x and 'dia' in x.split()})
|
||||||
,dict(attrs={'class': lambda x: x and 'titulo-noticia' in x.split()})
|
,dict(attrs={'class': lambda x: x and 'titulo-noticia' in x.split()})
|
||||||
|
,dict(attrs={'class': lambda x: x and 'foto-perfil-columnista' in x.split()})
|
||||||
,dict(attrs={'class': lambda x: x and 'despliegue-noticia' in x.split()})
|
,dict(attrs={'class': lambda x: x and 'despliegue-noticia' in x.split()})
|
||||||
]
|
]
|
||||||
remove_tags = [dict(name=['object','link','embed','iframe','meta','link'])]
|
remove_tags = [dict(name=['object','link','embed','iframe','meta','link'])]
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2011 - 2016, Darko Miletic <darko.miletic at gmail.com>'
|
__copyright__ = '2011 - 2018, Darko Miletic <darko.miletic at gmail.com>'
|
||||||
'''
|
'''
|
||||||
ambito.com/diario
|
ambito.com/diario
|
||||||
'''
|
'''
|
||||||
@ -17,50 +17,59 @@ from calibre.ebooks.BeautifulSoup import BeautifulSoup
|
|||||||
|
|
||||||
|
|
||||||
class Ambito_Financiero(BasicNewsRecipe):
|
class Ambito_Financiero(BasicNewsRecipe):
|
||||||
title = 'Ambito Financiero'
|
title = 'Ambito Financiero'
|
||||||
__author__ = 'Darko Miletic'
|
__author__ = 'Darko Miletic'
|
||||||
description = 'Informacion Libre las 24 horas'
|
description = 'Informacion Libre las 24 horas'
|
||||||
publisher = 'Editorial Nefir S.A.'
|
publisher = 'Editorial Nefir S.A.'
|
||||||
category = 'news, politics, economy, Argentina'
|
category = 'news, politics, economy, Argentina'
|
||||||
no_stylesheets = True
|
no_stylesheets = True
|
||||||
encoding = 'utf8'
|
encoding = 'utf8'
|
||||||
publication_type = 'newspaper'
|
publication_type = 'newspaper'
|
||||||
needs_subscription = True
|
needs_subscription = True
|
||||||
use_embedded_content = False
|
use_embedded_content = False
|
||||||
language = 'es_AR'
|
language = 'es_AR'
|
||||||
delay = 1
|
delay = 1
|
||||||
session_id = None
|
session_id = None
|
||||||
PREFIX = 'http://www.ambito.com'
|
PREFIX = 'http://www.ambito.com'
|
||||||
PREFIXDIARIO = PREFIX + '/diario'
|
PREFIXDIARIO = PREFIX + '/diario'
|
||||||
INDEX = PREFIX + '/diario/index.asp'
|
INDEX = PREFIX + '/diario/index.asp'
|
||||||
LOGIN = PREFIX + '/login/login_cabezal.asp'
|
LOGIN = PREFIX + '/login/login_cabezal.asp'
|
||||||
extra_css = """
|
extra_css = """
|
||||||
body{font-family: Roboto,sans-serif}
|
body{font-family: Roboto,sans-serif}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
conversion_options = {
|
conversion_options = {
|
||||||
'comment' : description,
|
'comment': description,
|
||||||
'tags' : category,
|
'tags': category,
|
||||||
'publisher': publisher,
|
'publisher': publisher,
|
||||||
'language' : language
|
'language': language
|
||||||
}
|
}
|
||||||
|
|
||||||
keep_only_tags = [
|
keep_only_tags = [
|
||||||
dict(name='h6', attrs={'class': lambda x: x and 'bajada' in x.split()})
|
dict(name='h6', attrs={'class': lambda x: x and 'bajada' in x.split()}),
|
||||||
,dict(name='span', attrs={'class': lambda x: x and 'dia' in x.split()})
|
dict(name='span', attrs={'class': lambda x: x and 'dia' in x.split()}),
|
||||||
,dict(attrs={'class': lambda x: x and 'titulo-noticia' in x.split()})
|
dict(attrs={'class': lambda x: x and 'titulo-noticia' in x.split()}),
|
||||||
,dict(attrs={'class': lambda x: x and 'despliegue-noticia' in x.split()})
|
dict(attrs={'class': lambda x: x and 'foto-perfil-columnista' in x.split()}),
|
||||||
]
|
dict(attrs={'class': lambda x: x and 'despliegue-noticia' in x.split()})
|
||||||
remove_tags = [dict(name=['object','link','embed','iframe','meta','link'])]
|
]
|
||||||
|
remove_tags = [dict(name=['object', 'link', 'embed', 'iframe', 'meta', 'link'])]
|
||||||
|
|
||||||
def get_browser(self):
|
def get_browser(self):
|
||||||
br = BasicNewsRecipe.get_browser(self)
|
br = BasicNewsRecipe.get_browser(self)
|
||||||
br.open(self.INDEX)
|
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:
|
||||||
data = urllib.urlencode({'txtUser':self.username, 'txtPassword':self.password})
|
data = urllib.urlencode({
|
||||||
response = br.open('http://www.ambito.com/diario/no-cache/login/x_login_cabezal.asp', data)
|
'txtUser': self.username,
|
||||||
|
'txtPassword': self.password
|
||||||
|
})
|
||||||
|
response = br.open(
|
||||||
|
'http://www.ambito.com/diario/no-cache/login/x_login_cabezal.asp',
|
||||||
|
data
|
||||||
|
)
|
||||||
sessiondata = response.read()
|
sessiondata = response.read()
|
||||||
prog = re.compile(r"^(?P<status>\d+?),(?P<session_id>.+?),(?P<username>.+?),.*?")
|
prog = re.compile(
|
||||||
|
r"^(?P<status>\d+?),(?P<session_id>.+?),(?P<username>.+?),.*?"
|
||||||
|
)
|
||||||
m = prog.match(sessiondata)
|
m = prog.match(sessiondata)
|
||||||
if m:
|
if m:
|
||||||
self.session_id = m.group('session_id')
|
self.session_id = m.group('session_id')
|
||||||
@ -70,7 +79,7 @@ class Ambito_Financiero(BasicNewsRecipe):
|
|||||||
soup = self.index_to_soup(self.INDEX)
|
soup = self.index_to_soup(self.INDEX)
|
||||||
articles = []
|
articles = []
|
||||||
checker = []
|
checker = []
|
||||||
rootitem = soup.find(attrs={'class':'ei-dropdown'})
|
rootitem = soup.find(attrs={'class': 'ei-dropdown'})
|
||||||
for feed_link in rootitem.findAll('a', href=True):
|
for feed_link in rootitem.findAll('a', href=True):
|
||||||
url = self.PREFIXDIARIO + feed_link['href']
|
url = self.PREFIXDIARIO + feed_link['href']
|
||||||
title = self.tag_to_string(feed_link)
|
title = self.tag_to_string(feed_link)
|
||||||
@ -78,7 +87,10 @@ class Ambito_Financiero(BasicNewsRecipe):
|
|||||||
if url not in checker:
|
if url not in checker:
|
||||||
checker.append(url)
|
checker.append(url)
|
||||||
articles.append({
|
articles.append({
|
||||||
'title': title, 'date': date, 'url': url, 'description': u''
|
'title': title,
|
||||||
|
'date': date,
|
||||||
|
'url': url,
|
||||||
|
'description': u''
|
||||||
})
|
})
|
||||||
return [(self.title, articles)]
|
return [(self.title, articles)]
|
||||||
|
|
||||||
@ -86,17 +98,24 @@ class Ambito_Financiero(BasicNewsRecipe):
|
|||||||
if self.session_id:
|
if self.session_id:
|
||||||
l, s, r = url.rpartition('/')
|
l, s, r = url.rpartition('/')
|
||||||
artid, s1, r1 = r.partition('-')
|
artid, s1, r1 = r.partition('-')
|
||||||
data = urllib.urlencode({'id':artid, 'id_session':self.session_id})
|
data = urllib.urlencode({'id': artid, 'id_session': self.session_id})
|
||||||
response = self.browser.open('http://data.ambito.com/diario/cuerpo_noticia.asp', data)
|
response = self.browser.open(
|
||||||
|
'http://data.ambito.com/diario/cuerpo_noticia.asp', data
|
||||||
|
)
|
||||||
soup = BeautifulSoup(raw_html)
|
soup = BeautifulSoup(raw_html)
|
||||||
p = soup.find('p', id="cuerpo_noticia")
|
p = soup.find('p', id="cuerpo_noticia")
|
||||||
if p:
|
if p:
|
||||||
p.append(response.read())
|
smallsoup = BeautifulSoup(response.read())
|
||||||
|
cfind = smallsoup.find('div', id="contenido_data")
|
||||||
|
if cfind:
|
||||||
|
p.append(cfind)
|
||||||
return unicode(soup)
|
return unicode(soup)
|
||||||
return raw_html
|
return raw_html
|
||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
if self.session_id is not None:
|
if self.session_id is not None:
|
||||||
data = urllib.urlencode({'session_id':self.session_id})
|
data = urllib.urlencode({'session_id': self.session_id})
|
||||||
self.browser.open('http://www.ambito.com/diario/no-cache/login/x_logout.asp', data)
|
self.browser.open(
|
||||||
|
'http://www.ambito.com/diario/no-cache/login/x_logout.asp', data
|
||||||
|
)
|
||||||
self.session_id = None
|
self.session_id = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user