| 1 |
from __future__ import print_function |
| 2 |
|
| 3 |
from calibre.web.feeds.recipes import BasicNewsRecipe |
| 4 |
|
| 5 |
|
| 6 |
class RevistaElCultural(BasicNewsRecipe): |
| 7 |
title = 'Revista El Cultural' |
| 8 |
__author__ = 'Jefferson Frantz' |
| 9 |
description = 'Revista de cultura' |
| 10 |
timefmt = ' [%d %b, %Y]' |
| 11 |
language = 'es' |
| 12 |
|
| 13 |
no_stylesheets = True |
| 14 |
remove_javascript = True |
| 15 |
|
| 16 |
extra_css = 'h1{ font-family: sans-serif; font-size: large; font-weight: bolder; text-align: justify } h2{ font-family: sans-serif; font-size: small; font-weight: 500; text-align: justify } h3{ font-family: sans-serif; font-size: small; font-weight: 500; text-align: justify } h4{ font-family: sans-serif; font-weight: lighter; font-size: medium; font-style: italic; text-align: justify } .rtsArticuloFirma{ font-family: sans-serif; font-size: small; text-align: justify } .column span-13 last{ font-family: sans-serif; font-size: medium; text-align: justify } .rtsImgArticulo{font-family: serif; font-size: small; color: #000000; text-align: justify}' # noqa: E501 |
| 17 |
|
| 18 |
def preprocess_html(self, soup): |
| 19 |
for item in soup.findAll(style=True): |
| 20 |
del item['style'] |
| 21 |
|
| 22 |
return soup |
| 23 |
|
| 24 |
keep_only_tags = [dict(name='div', attrs={'class': ['column span-13 last']}), dict(name='div', attrs={'class': ['rtsImgArticulo']})] |
| 25 |
|
| 26 |
remove_tags = [dict(name=['object', 'link', 'script', 'ul']), dict(name='div', attrs={'class': ['rtsRating']})] |
| 27 |
|
| 28 |
# TO GET ARTICLES IN SECTION |
| 29 |
def ec_parse_section(self, url, titleSection): |
| 30 |
print('Section: ' + titleSection) |
| 31 |
soup = self.index_to_soup(url) |
| 32 |
div = soup.find(attrs={'id': 'gallery'}) |
| 33 |
current_articles = [] |
| 34 |
|
| 35 |
for a in div.findAllNext('a', href=True): |
| 36 |
if a is None: |
| 37 |
continue |
| 38 |
title = self.tag_to_string(a) |
| 39 |
|
| 40 |
url = a.get('href', False) |
| 41 |
if not url or not title: |
| 42 |
continue |
| 43 |
|
| 44 |
if not url.startswith('/version_papel/' + titleSection + '/'): |
| 45 |
if len(current_articles) > 0 and not url.startswith('/secciones/'): |
| 46 |
break |
| 47 |
continue |
| 48 |
|
| 49 |
if url.startswith('/version_papel/' + titleSection + '/'): |
| 50 |
url = 'http://www.elcultural.es' + url |
| 51 |
|
| 52 |
self.log('\t\tFound article:', title[0 : title.find('|') - 1]) |
| 53 |
self.log('\t\t\t', url) |
| 54 |
current_articles.append({'title': title[0 : title.find('|') - 1], 'url': url, 'description': '', 'date': ''}) |
| 55 |
|
| 56 |
return current_articles |
| 57 |
|
| 58 |
# To GET SECTIONS |
| 59 |
def parse_index(self): |
| 60 |
feeds = [] |
| 61 |
for title, url in [ |
| 62 |
('LETRAS', 'http://www.elcultural.es/pdf_sumario/cultural/Sumario_El_Cultural_en_PDF'), |
| 63 |
('ARTE', 'http://www.elcultural.es/pdf_sumario/cultural/Sumario_El_Cultural_en_PDF'), |
| 64 |
('CINE', 'http://www.elcultural.es/pdf_sumario/cultural/Sumario_El_Cultural_en_PDF'), |
| 65 |
('CIENCIA', 'http://www.elcultural.es/pdf_sumario/cultural/Sumario_El_Cultural_en_PDF'), |
| 66 |
# ('OPINION', |
| 67 |
# 'http://www.elcultural.es/pdf_sumario/cultural/Sumario_El_Cultural_en_PDF'), |
| 68 |
('ESCENARIOS', 'http://www.elcultural.es/pdf_sumario/cultural/Sumario_El_Cultural_en_PDF'), |
| 69 |
]: |
| 70 |
articles = self.ec_parse_section(url, title) |
| 71 |
if articles: |
| 72 |
feeds.append((title, articles)) |
| 73 |
|
| 74 |
return feeds |