| 1 |
#!/usr/bin/env python |
| 2 |
## |
| 3 |
# Title: Il Post recipe for calibre |
| 4 |
# Author: Marco Scirea, based on a recipe by frafra |
| 5 |
# Contact: marco.prolog at gmail.com |
| 6 |
## |
| 7 |
# License: GNU General Public License v3 - http://www.gnu.org/copyleft/gpl.html |
| 8 |
# Copyright: Copyright 2019 Marco Scirea |
| 9 |
## |
| 10 |
|
| 11 |
from __future__ import absolute_import, division, print_function, unicode_literals |
| 12 |
|
| 13 |
from datetime import date, timedelta |
| 14 |
|
| 15 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 16 |
|
| 17 |
dates = [date.today().strftime('%Y/%m/%d'), (date.today() - timedelta(1)).strftime('%Y/%m/%d')] |
| 18 |
|
| 19 |
# ----------- CUSTOMIZATION OPTIONS START ----------- |
| 20 |
|
| 21 |
# Comment (add # in front) to disable the sections you are not interested in |
| 22 |
# Commenta (aggiungi # davanti alla riga) per disabilitare le sezioni che non vuoi scaricare |
| 23 |
sections = [ |
| 24 |
('Italia', 'https://www.ilpost.it/italia/'), |
| 25 |
('Mondo', 'https://www.ilpost.it/mondo/'), |
| 26 |
('Politica', 'https://www.ilpost.it/politica/'), |
| 27 |
('Tecnologia', 'https://www.ilpost.it/tecnologia/'), |
| 28 |
('Internet', 'https://www.ilpost.it/internet/'), |
| 29 |
('Scienza', 'https://www.ilpost.it/scienza/'), |
| 30 |
('Cultura', 'https://www.ilpost.it/cultura/'), |
| 31 |
('Economia', 'https://www.ilpost.it/economia/'), |
| 32 |
('Sport', 'https://www.ilpost.it/sport/'), |
| 33 |
('Media', 'https://www.ilpost.it/media/'), |
| 34 |
('Moda', 'https://www.ilpost.it/moda/'), |
| 35 |
('Libri', 'https://www.ilpost.it/libri/'), |
| 36 |
('Auto', 'https://www.ilpost.it/auto/'), |
| 37 |
('Konrad', 'https://www.ilpost.it/europa/'), |
| 38 |
] |
| 39 |
|
| 40 |
# ----------- CUSTOMIZATION OPTIONS OVER ----------- |
| 41 |
|
| 42 |
|
| 43 |
class IlPost(BasicNewsRecipe): |
| 44 |
__author__ = 'Marco Scirea, unkn0wn' |
| 45 |
__license__ = 'GPL v3' |
| 46 |
__copyright__ = '2019, Marco Scirea <marco.prolog at gmail.com>' |
| 47 |
|
| 48 |
title = 'Il Post' |
| 49 |
language = 'it' |
| 50 |
description = ( |
| 51 |
'Puoi decidere quali sezioni scaricare modificando la ricetta.' |
| 52 |
' Di default le immagini sono convertite in scala di grigio per risparmiare spazio,' |
| 53 |
" la ricetta puo' essere configurata per tenerle a colori" |
| 54 |
) |
| 55 |
tags = 'news' |
| 56 |
masthead_url = 'https://www.ilpost.it/error/images/ilpost.svg' |
| 57 |
ignore_duplicate_articles = {'title', 'url'} |
| 58 |
no_stylesheets = True |
| 59 |
extra_css = ' .wp-caption-text { font-size:small; } ' |
| 60 |
keep_only_tags = [dict(name='main', attrs={'id': lambda x: x and x.startswith('index_main-content__')})] |
| 61 |
remove_tags_before = [dict(name='article')] |
| 62 |
remove_tags_after = [dict(name='article')] |
| 63 |
remove_tags = [ |
| 64 |
dict(attrs={'class': lambda x: x and x.startswith(('index_actions__', 'index_il-post-comments___', 'index_art_tag__'))}), |
| 65 |
dict(attrs={'id': 'audioPlayerArticle'}), |
| 66 |
] |
| 67 |
|
| 68 |
def parse_page(self, name, url): |
| 69 |
self.log.debug(url) |
| 70 |
soup = self.index_to_soup(url) |
| 71 |
entries = [] |
| 72 |
for article in soup.findAll('article'): |
| 73 |
for link in article.findAll('a', href=True): |
| 74 |
if not any(x in link['href'] for x in dates): |
| 75 |
continue |
| 76 |
title = self.tag_to_string(link.h2) |
| 77 |
desc = self.tag_to_string(link.p) |
| 78 |
if not title: |
| 79 |
continue |
| 80 |
self.log('\t', title) |
| 81 |
entries.append({'url': link['href'], 'title': title, 'description': desc}) |
| 82 |
return name, entries |
| 83 |
|
| 84 |
def parse_index(self): |
| 85 |
feeds = [] |
| 86 |
for section in sections: |
| 87 |
feeds.append(self.parse_page(section[0], section[1])) |
| 88 |
return feeds |