mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Merge branch 'master' of https://github.com/unkn0w7n/calibre
This commit is contained in:
commit
77d7f829cf
@ -31,6 +31,19 @@ class PsychologyToday(BasicNewsRecipe):
|
||||
encoding = 'UTF-8'
|
||||
no_stylesheets = True
|
||||
publication_type = 'magazine'
|
||||
remove_attributes = ['style', 'height', 'width']
|
||||
extra_css = '''
|
||||
.image-article_inline_full, .image-article-inline-half { text-align:center; font-size:small; }
|
||||
em, blockquote { color:#202020; }
|
||||
.blog-entry__date--full { font-size:small; }
|
||||
'''
|
||||
|
||||
recipe_specific_options = {
|
||||
'date': {
|
||||
'short': 'The date of the Past Edition to download (YYYY/MM format)',
|
||||
'long': 'For example, 2024/07'
|
||||
}
|
||||
}
|
||||
|
||||
keep_only_tags = [dict(attrs={'id': 'block-pt-content'})]
|
||||
remove_tags = [classes('pt-social-media')]
|
||||
@ -38,9 +51,15 @@ class PsychologyToday(BasicNewsRecipe):
|
||||
def parse_index(self):
|
||||
soup = self.index_to_soup('https://www.psychologytoday.com/us/magazine/archive')
|
||||
a = soup.find(**classes('magazine-thumbnail')).a
|
||||
self.timefmt = ' [%s]' % a['title']
|
||||
self.cover_url = absurl(a.img['src'])
|
||||
soup = self.index_to_soup(absurl(a['href']))
|
||||
url = a['href']
|
||||
past_edition = self.recipe_specific_options.get('date')
|
||||
if past_edition:
|
||||
url = '/us/magazine/archive/' + past_edition
|
||||
soup = self.index_to_soup(absurl(url))
|
||||
cov = soup.find(**classes('content-header--cover-image'))
|
||||
if cov:
|
||||
self.cover_url = cov.img['src']
|
||||
self.timefmt = ' [%s]' % cov.img['alt'].replace(' magazine cover', '')
|
||||
articles = []
|
||||
for article in soup.findAll('div', attrs={'class':'article-text'}):
|
||||
title = self.tag_to_string(article.find(attrs={'class':['h2','h3']})).strip()
|
||||
@ -53,4 +72,4 @@ class PsychologyToday(BasicNewsRecipe):
|
||||
else:
|
||||
desc = ''
|
||||
articles.append({'title': title, 'url': url, 'description': desc, 'author': author})
|
||||
return [('Current Issue', articles)]
|
||||
return [('Articles', articles)]
|
||||
|
@ -6,11 +6,6 @@ from itertools import zip_longest
|
||||
from calibre.ebooks.BeautifulSoup import BeautifulSoup
|
||||
from calibre.web.feeds.news import BasicNewsRecipe, classes
|
||||
|
||||
# Past 6 editions are available for download.
|
||||
# For available past editions see log and set date to, for example, '20240513'.
|
||||
past_edition = None
|
||||
|
||||
|
||||
def media_bucket(x):
|
||||
if x.get('type', '') == 'image':
|
||||
if x.get('subtype', '') == 'graphic' or 'images.wsj.net' not in x['manifest-url']:
|
||||
@ -41,6 +36,13 @@ class WSJ(BasicNewsRecipe):
|
||||
remove_attributes = ['style', 'height', 'width']
|
||||
resolve_internal_links = True
|
||||
|
||||
recipe_specific_options = {
|
||||
'date': {
|
||||
'short': 'The date of the edition to download (YYYYMMDD format)\nOnly the past 6 editions will be available ',
|
||||
'long': 'For example, 20240513'
|
||||
}
|
||||
}
|
||||
|
||||
extra_css = '''
|
||||
#subhed, em { font-style:italic; color:#202020; }
|
||||
#byline, #time-to-read, #orig-pubdate-string, .article-byline, time, #flashline { font-size:small; }
|
||||
@ -103,8 +105,8 @@ class WSJ(BasicNewsRecipe):
|
||||
pan.name = 'div'
|
||||
return soup
|
||||
|
||||
if not past_edition:
|
||||
def _download_cover(self):
|
||||
def _download_cover(self):
|
||||
if not self.recipe_specific_options.get('date'):
|
||||
import os
|
||||
from contextlib import closing
|
||||
|
||||
@ -136,6 +138,9 @@ class WSJ(BasicNewsRecipe):
|
||||
catalog = json.loads(self.index_to_soup(index + '/catalogs/v1/wsj/us/catalog.json', raw=True))
|
||||
edit = [itm['key'][10:] for itm in catalog['items'] if itm['type'] == 'ITPNEXTGEN'][1:]
|
||||
self.log('**Past Editions available :', ', '.join(edit))
|
||||
|
||||
past_edition = self.recipe_specific_options.get('date')
|
||||
|
||||
for itm in catalog['items']:
|
||||
if past_edition:
|
||||
if itm['key'] == 'ITPNEXTGEN' + past_edition:
|
||||
|
Loading…
x
Reference in New Issue
Block a user