mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update New York Review of Books
This commit is contained in:
parent
8e73b8efef
commit
38fd76c21b
@ -13,6 +13,11 @@ from calibre.web.feeds.news import BasicNewsRecipe
|
|||||||
def find_header(tag):
|
def find_header(tag):
|
||||||
return tag.name == 'header' and tag.parent['class'] == 'article'
|
return tag.name == 'header' and tag.parent['class'] == 'article'
|
||||||
|
|
||||||
|
def absurl(url):
|
||||||
|
if url.startswith('/'):
|
||||||
|
url = 'http://www.nybooks.com' + url
|
||||||
|
return url
|
||||||
|
|
||||||
class NewYorkReviewOfBooks(BasicNewsRecipe):
|
class NewYorkReviewOfBooks(BasicNewsRecipe):
|
||||||
|
|
||||||
title = u'New York Review of Books'
|
title = u'New York Review of Books'
|
||||||
@ -64,7 +69,7 @@ class NewYorkReviewOfBooks(BasicNewsRecipe):
|
|||||||
sidebar = soup.find('div', attrs={'class':'issue_cover'})
|
sidebar = soup.find('div', attrs={'class':'issue_cover'})
|
||||||
if sidebar is not None:
|
if sidebar is not None:
|
||||||
img = sidebar.find('img', src=True)
|
img = sidebar.find('img', src=True)
|
||||||
self.cover_url = 'http://www.nybooks.com' + img['src']
|
self.cover_url = absurl(img['src'])
|
||||||
self.log('Found cover at:', self.cover_url)
|
self.log('Found cover at:', self.cover_url)
|
||||||
|
|
||||||
# Find date
|
# Find date
|
||||||
@ -84,7 +89,7 @@ class NewYorkReviewOfBooks(BasicNewsRecipe):
|
|||||||
title = self.tag_to_string(h2).strip()
|
title = self.tag_to_string(h2).strip()
|
||||||
author = self.tag_to_string(div.find('div', attrs={'class':'author'})).strip()
|
author = self.tag_to_string(div.find('div', attrs={'class':'author'})).strip()
|
||||||
title = title + u' (%s)'%author
|
title = title + u' (%s)'%author
|
||||||
url = 'http://www.nybooks.com' + h2.find('a', href=True)['href']
|
url = absurl(h2.find('a', href=True)['href'])
|
||||||
desc = ''
|
desc = ''
|
||||||
for p in div.findAll('p', attrs={'class':lambda x: x and 'quiet' in x}):
|
for p in div.findAll('p', attrs={'class':lambda x: x and 'quiet' in x}):
|
||||||
desc += self.tag_to_string(p)
|
desc += self.tag_to_string(p)
|
||||||
@ -95,4 +100,3 @@ class NewYorkReviewOfBooks(BasicNewsRecipe):
|
|||||||
'description':desc})
|
'description':desc})
|
||||||
|
|
||||||
return [('Current Issue', articles)]
|
return [('Current Issue', articles)]
|
||||||
|
|
||||||
|
@ -13,6 +13,11 @@ from calibre.web.feeds.news import BasicNewsRecipe
|
|||||||
def find_header(tag):
|
def find_header(tag):
|
||||||
return tag.name == 'header' and tag.parent['class'] == 'article'
|
return tag.name == 'header' and tag.parent['class'] == 'article'
|
||||||
|
|
||||||
|
def absurl(url):
|
||||||
|
if url.startswith('/'):
|
||||||
|
url = 'http://www.nybooks.com' + url
|
||||||
|
return url
|
||||||
|
|
||||||
class NewYorkReviewOfBooks(BasicNewsRecipe):
|
class NewYorkReviewOfBooks(BasicNewsRecipe):
|
||||||
|
|
||||||
title = u'New York Review of Books (no subscription)'
|
title = u'New York Review of Books (no subscription)'
|
||||||
@ -52,7 +57,7 @@ class NewYorkReviewOfBooks(BasicNewsRecipe):
|
|||||||
sidebar = soup.find('div', attrs={'class':'issue_cover'})
|
sidebar = soup.find('div', attrs={'class':'issue_cover'})
|
||||||
if sidebar is not None:
|
if sidebar is not None:
|
||||||
img = sidebar.find('img', src=True)
|
img = sidebar.find('img', src=True)
|
||||||
self.cover_url = 'http://www.nybooks.com' + img['src']
|
self.cover_url = absurl(img['src'])
|
||||||
self.log('Found cover at:', self.cover_url)
|
self.log('Found cover at:', self.cover_url)
|
||||||
|
|
||||||
# Find date
|
# Find date
|
||||||
@ -72,7 +77,7 @@ class NewYorkReviewOfBooks(BasicNewsRecipe):
|
|||||||
title = self.tag_to_string(h2).strip()
|
title = self.tag_to_string(h2).strip()
|
||||||
author = self.tag_to_string(div.find('div', attrs={'class':'author'})).strip()
|
author = self.tag_to_string(div.find('div', attrs={'class':'author'})).strip()
|
||||||
title = title + u' (%s)'%author
|
title = title + u' (%s)'%author
|
||||||
url = 'http://www.nybooks.com' + h2.find('a', href=True)['href']
|
url = absurl(h2.find('a', href=True)['href'])
|
||||||
desc = ''
|
desc = ''
|
||||||
for p in div.findAll('p', attrs={'class':lambda x: x and 'quiet' in x}):
|
for p in div.findAll('p', attrs={'class':lambda x: x and 'quiet' in x}):
|
||||||
desc += self.tag_to_string(p)
|
desc += self.tag_to_string(p)
|
||||||
@ -83,4 +88,3 @@ class NewYorkReviewOfBooks(BasicNewsRecipe):
|
|||||||
'description':desc})
|
'description':desc})
|
||||||
|
|
||||||
return [('Current Issue', articles)]
|
return [('Current Issue', articles)]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user