mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Nicer way to get the current SciAm issue
This commit is contained in:
parent
4e66140e8a
commit
041ebc3edf
@ -2,7 +2,6 @@
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
|
|
||||||
from calibre.web.feeds.news import BasicNewsRecipe
|
from calibre.web.feeds.news import BasicNewsRecipe
|
||||||
from calibre.utils.date import now
|
|
||||||
from css_selectors import Select
|
from css_selectors import Select
|
||||||
|
|
||||||
|
|
||||||
@ -11,6 +10,7 @@ def absurl(url):
|
|||||||
url = 'http://www.scientificamerican.com' + url
|
url = 'http://www.scientificamerican.com' + url
|
||||||
return url
|
return url
|
||||||
|
|
||||||
|
|
||||||
keep_classes = {'article-header', 'article-content',
|
keep_classes = {'article-header', 'article-content',
|
||||||
'article-media', 'article-author', 'article-text'}
|
'article-media', 'article-author', 'article-text'}
|
||||||
remove_classes = {'aside-banner', 'moreToExplore', 'article-footer'}
|
remove_classes = {'aside-banner', 'moreToExplore', 'article-footer'}
|
||||||
@ -55,18 +55,8 @@ class ScientificAmerican(BasicNewsRecipe):
|
|||||||
root = self.index_to_soup(
|
root = self.index_to_soup(
|
||||||
'http://www.scientificamerican.com/sciammag/', as_tree=True)
|
'http://www.scientificamerican.com/sciammag/', as_tree=True)
|
||||||
select = Select(root)
|
select = Select(root)
|
||||||
for a in select('#sa_body .store-listing__img a[href]'):
|
url = [x.get('content', '') for x in select('html > head meta') if x.get('property',None) == "og:url"][0]
|
||||||
url = absurl(a.get('href'))
|
self.cover_url = [x.get('src', '') for x in select('main .product-detail__image picture img')][0]
|
||||||
month = int(filter(None, url.split('/'))[-1].partition('-')[0])
|
|
||||||
if month > now().month:
|
|
||||||
continue
|
|
||||||
for source in a.xpath('descendant::source'):
|
|
||||||
self.cover_url = absurl(source.get('srcset').split()[0])
|
|
||||||
break
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
raise ValueError(
|
|
||||||
'The Scientific American website has changed, this recipe needs to be updated')
|
|
||||||
|
|
||||||
# Now parse the actual issue to get the list of articles
|
# Now parse the actual issue to get the list of articles
|
||||||
select = Select(self.index_to_soup(url, as_tree=True))
|
select = Select(self.index_to_soup(url, as_tree=True))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user