mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update Jacobin
This commit is contained in:
parent
0d2fb54475
commit
f64dfddd40
@ -11,6 +11,12 @@ www.jacobinmag.com
|
|||||||
from calibre.web.feeds.news import BasicNewsRecipe
|
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 Jacobinmag(BasicNewsRecipe):
|
class Jacobinmag(BasicNewsRecipe):
|
||||||
title = 'Jacobin'
|
title = 'Jacobin'
|
||||||
__author__ = 'Darko Miletic'
|
__author__ = 'Darko Miletic'
|
||||||
@ -29,7 +35,6 @@ class Jacobinmag(BasicNewsRecipe):
|
|||||||
issue_url = None
|
issue_url = None
|
||||||
PREFIX = 'https://www.jacobinmag.com'
|
PREFIX = 'https://www.jacobinmag.com'
|
||||||
LOGIN = 'https://auth.jacobinmag.com/mini_profile?redirect=https%3A%2F%2Fwww.jacobinmag.com%2F'
|
LOGIN = 'https://auth.jacobinmag.com/mini_profile?redirect=https%3A%2F%2Fwww.jacobinmag.com%2F'
|
||||||
masthead_url = 'https://www.jacobinmag.com/wp-content/themes/boukman/images/banner/type.svg'
|
|
||||||
extra_css = """
|
extra_css = """
|
||||||
body{font-family: Antwerp, 'Times New Roman', Times, serif}
|
body{font-family: Antwerp, 'Times New Roman', Times, serif}
|
||||||
img{margin-top:1em; margin-bottom: 1em; display:block}
|
img{margin-top:1em; margin-bottom: 1em; display:block}
|
||||||
@ -44,55 +49,49 @@ class Jacobinmag(BasicNewsRecipe):
|
|||||||
}
|
}
|
||||||
|
|
||||||
remove_tags = [
|
remove_tags = [
|
||||||
dict(name=['meta', 'link']),
|
dict(id=['post-header-share', 'post-print']),
|
||||||
dict(name='div', attrs={'class': 'entry-bottom'}),
|
dict(name='form'),
|
||||||
dict(name='div', attrs={'data-app': 'share_buttons'}),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
keep_only_tags = [dict(attrs={'class': ['entry-header', 'entry-content']})]
|
keep_only_tags = [
|
||||||
|
classes('po__article')
|
||||||
|
]
|
||||||
|
|
||||||
def parse_index(self):
|
def parse_index(self):
|
||||||
ans = []
|
ans = []
|
||||||
articles = []
|
articles = []
|
||||||
lurl = self.get_issue()
|
soup = self.index_to_soup('https://www.jacobinmag.com/store/issues')
|
||||||
if lurl:
|
lurl = 'https://jacobinmag.com' + soup.find('a', text='View Issue')['href']
|
||||||
|
feedtitle = 'Articles'
|
||||||
|
self.log('Loading issue from', lurl)
|
||||||
soup = self.index_to_soup(lurl)
|
soup = self.index_to_soup(lurl)
|
||||||
|
|
||||||
# Find cover url
|
# Find cover url
|
||||||
myimg = soup.find('img', attrs={'id': 'front-cover'})
|
di = soup.find('figure', attrs={'class': lambda x: x and '__cover' in x})
|
||||||
if myimg:
|
img = di.find('img')
|
||||||
self.cover_url = self.image_url_processor(None, myimg['src'])
|
self.cover_url = img['src']
|
||||||
# End find cover url
|
# End find cover url
|
||||||
|
|
||||||
# Configure series
|
|
||||||
self.conversion_options.update({'series': 'Jacobin'})
|
|
||||||
|
|
||||||
# Get series title
|
# Get series title
|
||||||
feedtitle = 'Articles'
|
title = soup.find('h1', attrs={'class': lambda x: x and '__heading' in x})
|
||||||
title = soup.find('div', attrs={'id': 'iss-title-name'})
|
|
||||||
if title:
|
|
||||||
feedtitle = self.tag_to_string(title)
|
feedtitle = self.tag_to_string(title)
|
||||||
|
|
||||||
# Scrape article links
|
# Scrape article links
|
||||||
for section in soup.findAll('div', attrs={'class': 'section-articles'}):
|
for section in soup.findAll('div', attrs={'class': lambda x: x and '__content' in x}):
|
||||||
for art in section.findAll('article'):
|
for art in section.findAll('article'):
|
||||||
urlbase = art.find('h3', attrs={'class': 'iss-hed'})
|
h1 = art.find('h1')
|
||||||
if urlbase and urlbase.a[
|
a = h1.find('a')
|
||||||
'href'
|
title = self.tag_to_string(a)
|
||||||
] != 'https://www.jacobinmag.com/subscribe/':
|
url = 'https://jacobinmag.com' + a['href']
|
||||||
url = urlbase.a['href']
|
|
||||||
title = self.tag_to_string(urlbase)
|
|
||||||
desc = ''
|
desc = ''
|
||||||
descbase = urlbase = art.find(
|
p = art.find('p')
|
||||||
'p', attrs={'class': 'iss-dek'}
|
if p:
|
||||||
)
|
desc = self.tag_to_string(p)
|
||||||
if descbase:
|
articles.append({'title': title, 'url': url, 'description': desc})
|
||||||
desc = self.tag_to_string(descbase)
|
self.log(title, 'at', url)
|
||||||
articles.append({
|
if desc:
|
||||||
'title': title,
|
self.log('\t', desc)
|
||||||
'url': url,
|
if articles:
|
||||||
'description': desc
|
|
||||||
})
|
|
||||||
ans.append((feedtitle, articles))
|
ans.append((feedtitle, articles))
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
@ -111,11 +110,3 @@ class Jacobinmag(BasicNewsRecipe):
|
|||||||
if div:
|
if div:
|
||||||
br.open(div['data-redirect'])
|
br.open(div['data-redirect'])
|
||||||
return br
|
return br
|
||||||
|
|
||||||
def get_issue(self):
|
|
||||||
issue = None
|
|
||||||
soup = self.index_to_soup(self.PREFIX)
|
|
||||||
mag = soup.find('li', attrs={'class': 'magazine'})
|
|
||||||
if mag:
|
|
||||||
issue = mag.a['href']
|
|
||||||
return issue
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user