mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-09-29 15:31:08 -04:00
51 lines
2.0 KiB
Plaintext
51 lines
2.0 KiB
Plaintext
from calibre.web.feeds.news import BasicNewsRecipe
|
|
|
|
class NewYorkTimesBookReview(BasicNewsRecipe):
|
|
title = u'New York Times Book Review'
|
|
language = 'en'
|
|
description = 'The New York Times Sunday Book Review'
|
|
__author__ = 'Kovid Goyal'
|
|
|
|
no_stylesheets = True
|
|
no_javascript = True
|
|
ignore_duplicate_articles = {'title', 'url'}
|
|
encoding = 'utf-8'
|
|
|
|
keep_only_tags = [
|
|
dict(id=['story-heading', 'story-meta-footer']),
|
|
dict(itemprop=['associatedMedia', 'articleBody', 'reviewBody']),
|
|
]
|
|
|
|
def parse_index(self):
|
|
soup = self.index_to_soup('http://www.nytimes.com/pages/books/review/index.html')
|
|
|
|
# Find TOC
|
|
toc = soup.find('div', attrs={'class':'rank'})
|
|
main_articles, articles = [], []
|
|
feeds = [('Features', main_articles), ('Latest', articles)]
|
|
for h2 in toc.findAll('h2', attrs={'class':'headline'}):
|
|
a = h2.find('a', href=True)
|
|
if a is not None:
|
|
title = self.tag_to_string(a)
|
|
url = a['href']
|
|
desc = ''
|
|
p = h2.findNextSibling('p', attrs={'class':'summary'})
|
|
if p:
|
|
desc = self.tag_to_string(p)
|
|
main_articles.append({'title':title, 'url':url, 'description':desc})
|
|
self.log('Found:', title, 'at', url)
|
|
if desc:
|
|
self.log('\t', desc)
|
|
for li in soup.find(id='latest-panel').find('ol').findAll('li'):
|
|
a = li.find('a', attrs={'class':'story-link'}, href=True)
|
|
url = a['href']
|
|
m = a.find(attrs={'class':'story-meta'})
|
|
title = self.tag_to_string(m.find('h2'))
|
|
desc = self.tag_to_string(m.find(attrs={'class':'summary'}))
|
|
articles.append({'title':title, 'url':url, 'description':desc})
|
|
self.log('Found:', title, 'at', url)
|
|
if desc:
|
|
self.log('\t', desc)
|
|
|
|
return feeds
|