calibre/recipes/chicago_tribune.recipe
2019-01-17 10:08:43 +05:30

59 lines
1.9 KiB
Plaintext

from __future__ import with_statement
__license__ = 'GPL 3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
from calibre.web.feeds.news import BasicNewsRecipe
def classes(classes):
q = frozenset(classes.split(' '))
return dict(attrs={
'class': lambda x: x and frozenset(x.split()).intersection(q)})
class ChicagoTribune(BasicNewsRecipe):
title = 'Chicago Tribune'
__author__ = 'Kovid Goyal'
description = 'Politics, local and business news from Chicago'
language = 'en'
use_embedded_content = False
no_stylesheets = True
remove_javascript = True
keep_only_tags = [
dict(name='h1'),
dict(attrs={'data-content-size': 'leadart'}),
dict(itemprop='articleBody'),
]
remove_tags = [
classes('trb_ar_cont trb_ar_main_ad trb_em_r_cc'),
]
feeds = [
('Breaking news', 'https://www.chicagotribune.com/news/local/breaking/rss2.0.xml'),
('Trending news', 'https://www.chicagotribune.com/news/trending/rss2.0.xml'),
('Opinion', 'https://www.chicagotribune.com/news/opinion/rss2.0.xml'),
('Business news', 'https://www.chicagotribune.com/business/rss2.0.xml'),
('Sports', 'https://www.chicagotribune.com/sports/rss2.0.xml'),
('Arts and Entertainment',
'https://www.chicagotribune.com/entertainment/rss2.0.xml'),
('Life & Style',
'https://www.chicagotribune.com/lifestyles/rss2.0.xml'),
]
def preprocess_html(self, soup):
for img in soup.findAll('img', attrs={'data-baseurl': True}):
img['src'] = img['data-baseurl']
return soup
def skip_ad_pages(self, soup):
text = soup.find(text='click here to continue to article')
if text:
a = text.parent
url = a.get('href')
if url:
return self.index_to_soup(url, raw=True)