| 1 |
#!/usr/bin/env python |
| 2 |
# vim:fileencoding=utf-8 |
| 3 |
|
| 4 |
import datetime |
| 5 |
import re |
| 6 |
|
| 7 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 8 |
|
| 9 |
|
| 10 |
class FSP(BasicNewsRecipe): |
| 11 |
title = 'Folha de S\xe3o Paulo' |
| 12 |
__author__ = 'Joao Eduardo Bertacchi - lc_addicted, 2020 Leonardo Amaral - leleobhz' |
| 13 |
description = ( |
| 14 |
'Printed edition contents. Folha subscription required (UOL subscription currently not supported).' |
| 15 |
' [Conte\xfado completo da edi\xe7\xe3o impressa. Somente para assinantes Folha. N\xe3o suporta assinantes UOL]' |
| 16 |
) |
| 17 |
|
| 18 |
today = datetime.date.today() |
| 19 |
|
| 20 |
masthead_url = 'http://f.i.uol.com.br/fsp/furniture/images/lgo-fsp-430x50-ffffff.gif' |
| 21 |
|
| 22 |
language = 'pt_BR' |
| 23 |
no_stylesheets = True |
| 24 |
max_articles_per_feed = 100 |
| 25 |
remove_javascript = True |
| 26 |
needs_subscription = True |
| 27 |
|
| 28 |
keep_only_tags = [ |
| 29 |
dict(name='div', id='articleNew'), |
| 30 |
dict(name='table', attrs={'class': 'articleGraphic'}), |
| 31 |
dict(name='article', id='news'), |
| 32 |
] |
| 33 |
|
| 34 |
publication_type = 'newspaper' |
| 35 |
simultaneous_downloads = 5 |
| 36 |
|
| 37 |
remove_attributes = ['height', 'width'] |
| 38 |
|
| 39 |
# The following is an attempt to fix the problem with the section names, |
| 40 |
# but whenever new sections are added it can generate accentuation |
| 41 |
# problems still |
| 42 |
section_dict = { |
| 43 |
'cotidian': 'cotidiano', |
| 44 |
'ilustrad': 'ilustrada', |
| 45 |
'quadrin': 'quadrinhos', |
| 46 |
'opiniao': 'opini\xe3o', |
| 47 |
'ciencia': 'cincia', |
| 48 |
'saude': 'sa\xfade', |
| 49 |
'ribeirao': 'ribeir\xe3o', |
| 50 |
'equilibrio': 'equil\xedbrio', |
| 51 |
'imoveis': 'im\xf3veis', |
| 52 |
'negocios': 'neg\xf3cios', |
| 53 |
'veiculos': 've\xedculos', |
| 54 |
'corrida': 'folha corrida', |
| 55 |
'turismo': 'turismo', |
| 56 |
} |
| 57 |
|
| 58 |
# this solves the problem with truncated content in Kindle |
| 59 |
conversion_options = {'linearize_tables': True} |
| 60 |
|
| 61 |
extra_css = ''' |
| 62 |
#articleNew { font: 18px Times New Roman,verdana,arial; } |
| 63 |
img { background: none !important; float: none; margin: 0px; } |
| 64 |
.newstexts { list-style-type: none; height: 20px; margin: 15px 0 10px 0; } |
| 65 |
.newstexts.last { border-top: 1px solid #ccc; margin: 5px 0 15px 0; padding-top: 15px; } |
| 66 |
.newstexts li { display: inline; padding: 0 5px; } |
| 67 |
.newstexts li.prev { float: left; } |
| 68 |
.newstexts li.next { float: right; } |
| 69 |
.newstexts li span { width: 12px; height: 15px; display: inline-block; } |
| 70 |
.newstexts li.prev span { background-position: -818px -46px; } |
| 71 |
.newstexts li.next span { background-position: -832px -46px; } |
| 72 |
.newstexts li a { font: bold 12px arial, verdana, sans-serif; text-transform: uppercase; color: #999; text-decoration: none !important; } |
| 73 |
.newstexts li a:hover { text-decoration: underline !important } |
| 74 |
.headerart { font-weight: bold; } |
| 75 |
.title { font: bold 39px Times New Roman,verdana,arial; margin-bottom: 15px; margin-top: 10px; } |
| 76 |
.creditart, .origin { font: bold 12px arial, verdana, sans-serif; color: #999; margin: 0px; display: block; } |
| 77 |
.headerart p, .fine_line p { margin: 0 !important; } |
| 78 |
.fine_line { font: bold 18px Times New Roman,verdana,arial; } |
| 79 |
.fine_line p { margin-bottom: 18px !important; } |
| 80 |
.fine_line p:first-child { font-weight: normal; font-style: italic; font-size: 20px !important; } |
| 81 |
.eye { display: block; width: 317px; border-top: 2px solid #666; padding: 7px 0 7px; border-bottom: 2px solid #666; font-style: italic; font-weight: bold; } |
| 82 |
.kicker { font-weight: bold; text-transform: uppercase; font-size: 18px; font-family: Times New Roman,verdana,arial !important; } |
| 83 |
.blue { color: #000080; } |
| 84 |
.red { color: #F00; } |
| 85 |
.blue { color: #000080; } |
| 86 |
.green { color: #006400; } |
| 87 |
.orange { color: #FFA042; } |
| 88 |
.violet { color: #8A2BE2; } |
| 89 |
.text_footer { font-size: 15px; } |
| 90 |
.title_end { font-size: 23px; font-weight: bold; } |
| 91 |
.divisor { text-indent: -9999px; border-bottom: 1px solid #ccc; height: 1px; margin: 0; } |
| 92 |
.star { background: none !important; height: 15px; } |
| 93 |
.articleGraphic { margin-bottom: 20px; } |
| 94 |
''' |
| 95 |
|
| 96 |
# This is the code for login, here a mini browser is called and id entered |
| 97 |
def get_browser(self): |
| 98 |
br = BasicNewsRecipe.get_browser(self) |
| 99 |
if self.username is not None and self.password is not None: |
| 100 |
br.open('https://login.folha.com.br/login') |
| 101 |
br.select_form(action='https://login.folha.com.br/login') |
| 102 |
br['email'] = self.username |
| 103 |
br['password'] = self.password |
| 104 |
br.submit() |
| 105 |
return br |
| 106 |
|
| 107 |
# Parsing the index webpage |
| 108 |
def parse_index(self): |
| 109 |
|
| 110 |
# In the last version, the index page has become simpler: |
| 111 |
INDEX = 'https://www1.folha.uol.com.br/fsp/' |
| 112 |
self.log('--> INDEX set ', INDEX) |
| 113 |
soup = self.index_to_soup(INDEX) |
| 114 |
|
| 115 |
feeds = [] |
| 116 |
articles = [] |
| 117 |
section_title = 'Primeira p\xe1gina' |
| 118 |
|
| 119 |
for post in soup.findAll('a'): |
| 120 |
strpost = str(post) |
| 121 |
if re.match(r'<a href="https://www1.folha.uol.com.br/.*/"><svg aria-hidden="true" class="icon icon--star"', strpost): |
| 122 |
if articles: |
| 123 |
feeds.append((section_title, articles)) |
| 124 |
self.log() |
| 125 |
self.log('--> new section found, creating old section feed: ', section_title) |
| 126 |
# section_title = post['name'] |
| 127 |
section_title = self.tag_to_string(post) |
| 128 |
if section_title in self.section_dict: |
| 129 |
section_title = self.section_dict[section_title] |
| 130 |
articles = [] |
| 131 |
self.log('--> new section title: ', section_title) |
| 132 |
elif strpost.startswith('<a href="/fsp/cp'): |
| 133 |
break |
| 134 |
elif strpost.startswith('<a href'): |
| 135 |
url = post['href'] |
| 136 |
if url.startswith(('http://www1.folha.uol.com.br/', 'https://www1.folha.uol.com.br/')): |
| 137 |
title = self.tag_to_string(post) |
| 138 |
self.log() |
| 139 |
self.log('--> post: ', post) |
| 140 |
self.log('--> url: ', url) |
| 141 |
self.log('--> title: ', title) |
| 142 |
articles.append({'title': title, 'url': url}) |
| 143 |
|
| 144 |
if articles: |
| 145 |
feeds.append((section_title, articles)) |
| 146 |
|
| 147 |
del feeds[0] |
| 148 |
|
| 149 |
return feeds |