Update Chicago Tribune

This commit is contained in:
Kovid Goyal 2019-07-25 13:53:52 +05:30
parent 219bcc3864
commit 29615f2a69
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -12,6 +12,13 @@ def classes(classes):
'class': lambda x: x and frozenset(x.split()).intersection(q)}) 'class': lambda x: x and frozenset(x.split()).intersection(q)})
def absolutize(x):
x = x.lstrip('/')
if not x.startswith('https:'):
x = 'https://www.chicagotribune.com/' + x
return x
class ChicagoTribune(BasicNewsRecipe): class ChicagoTribune(BasicNewsRecipe):
title = 'Chicago Tribune' title = 'Chicago Tribune'
@ -26,25 +33,45 @@ class ChicagoTribune(BasicNewsRecipe):
keep_only_tags = [ keep_only_tags = [
dict(name='h1'), dict(name='h1'),
dict(attrs={'data-content-size': 'leadart'}), classes('byline-container pb-f-utilities-lead-art pb-f-article-gallery'),
dict(itemprop='articleBody'), dict(attrs={'data-type': 'text'}),
] ]
remove_tags = [ remove_tags = [
classes('trb_ar_cont trb_ar_main_ad trb_em_r_cc'), classes('trb_ar_cont trb_ar_main_ad trb_em_r_cc'),
] ]
feeds = [ def ct_articles(self, slug):
('Breaking news', 'https://www.chicagotribune.com/news/local/breaking/rss2.0.xml'), url = absolutize(slug)
('Trending news', 'https://www.chicagotribune.com/news/trending/rss2.0.xml'), soup = self.index_to_soup(url)
('Opinion', 'https://www.chicagotribune.com/news/opinion/rss2.0.xml'), for div in soup.findAll(**classes('pb-f-homepage-story pb-f-homepage-story-feed')):
('Business news', 'https://www.chicagotribune.com/business/rss2.0.xml'), h = div.find(('h1', 'h2', 'h3', 'h4', 'h5', 'h6'))
('Sports', 'https://www.chicagotribune.com/sports/rss2.0.xml'), a = h.find('a', href=True)
('Arts and Entertainment', title = self.tag_to_string(a)
'https://www.chicagotribune.com/entertainment/rss2.0.xml'), url = absolutize(a['href'])
('Life & Style', self.log('\t', title, url)
'https://www.chicagotribune.com/lifestyles/rss2.0.xml'), desc = ''
] p = div.find(**classes('preview-text'))
if p:
desc = self.tag_to_string(p)
self.log('\t\t', desc)
yield {'title': title, 'description': desc, 'url': url}
def parse_index(self):
feed = []
for slug, title in (
('news/breaking', 'Breaking News'),
('sports', 'Sports'),
('business', 'Business'),
('entertainment', 'Entertainment'),
('dining', 'Chicago Dinining'),
('columns', 'Tribune Voices'),
):
self.log('Found section:', title)
articles = list(self.ct_articles(slug))
if articles:
feed.append((title, articles))
return feed
def preprocess_html(self, soup): def preprocess_html(self, soup):
for img in soup.findAll('img', attrs={'data-baseurl': True}): for img in soup.findAll('img', attrs={'data-baseurl': True}):