forked from kovidgoyal/calibre
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathambito_financiero.recipe
91 lines (82 loc) · 3 KB
/
ambito_financiero.recipe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python
# -*- mode: python -*-
# -*- coding: utf-8 -*-
__license__ = 'GPL v3'
__copyright__ = '2011 - 2021, Darko Miletic <darko.miletic at gmail.com>'
'''
https://www.ambito.com/contenidos/edicion-impresa.html
'''
import time
from calibre import strftime
from calibre.web.feeds.news import BasicNewsRecipe
class Ambito_Financiero(BasicNewsRecipe):
title = 'Ambito Financiero'
__author__ = 'Darko Miletic'
description = 'Informacion Libre las 24 horas'
publisher = 'Editorial Nefir S.A.'
category = 'news, politics, economy, Argentina'
no_stylesheets = True
encoding = 'utf8'
publication_type = 'newspaper'
needs_subscription = True
use_embedded_content = False
language = 'es_AR'
fetch_retries = 10
delay = 1
timeout = 8
ignore_duplicate_articles = {'url'}
INDEX = 'https://www.ambito.com/contenidos/edicion-impresa.html'
LOGIN = 'https://usuarios.ambito.com/singup'
LOGOUT = 'https://usuarios.ambito.com/logout'
extra_css = """
body{font-family: Roboto, "Helvetica Neue", Arial, sans-serif;}
.title{font-family: "IBM Plex Sans", "Helvetica Neue", Arial, sans-serif}
"""
conversion_options = {
'comment': description,
'tags': category,
'publisher': publisher,
'language': language
}
keep_only_tags = [
dict(name='div', attrs={'class': 'detail-header-wrapper'}),
dict(attrs={'class': lambda x: x and 'detail-body' in x.split()}),
]
remove_tags = [
dict(name=['object', 'link', 'embed', 'iframe', 'meta', 'link', 'img']),
dict(attrs={"class": lambda x: x and 'detail-gallery' in x.split()})
]
def get_browser(self):
br = BasicNewsRecipe.get_browser(self)
br.open(self.INDEX)
br.open(self.LOGIN)
if self.username is not None and self.password is not None:
br.select_form(name='td_login')
br['login_user'] = self.username
br['login_pass'] = self.password
br.submit()
return br
def parse_index(self):
soup = self.index_to_soup(self.INDEX)
articles = []
checker = []
printed = soup.find('div', attrs={"class":"view-printed-edition"})
if printed:
dimg = printed.find('img', attrs={"class":"lightbox"})
if dimg:
self.cover_url = dimg['src']
for feed_link in soup.find_all('h2', attrs={"class": "title"}):
url = feed_link.a['href']
title = self.tag_to_string(feed_link.a)
date = strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())
if url not in checker:
checker.append(url)
articles.append({
'title': title,
'date': date,
'url': url,
'description': u''
})
return [(self.title, articles)]
def cleanup(self):
self.browser.open(self.LOGOUT)