This commit is contained in:
Kovid Goyal 2024-07-19 11:18:46 +05:30
commit 77d7f829cf
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 35 additions and 11 deletions

View File

@ -31,6 +31,19 @@ class PsychologyToday(BasicNewsRecipe):
encoding = 'UTF-8' encoding = 'UTF-8'
no_stylesheets = True no_stylesheets = True
publication_type = 'magazine' 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'})] keep_only_tags = [dict(attrs={'id': 'block-pt-content'})]
remove_tags = [classes('pt-social-media')] remove_tags = [classes('pt-social-media')]
@ -38,9 +51,15 @@ class PsychologyToday(BasicNewsRecipe):
def parse_index(self): def parse_index(self):
soup = self.index_to_soup('https://www.psychologytoday.com/us/magazine/archive') soup = self.index_to_soup('https://www.psychologytoday.com/us/magazine/archive')
a = soup.find(**classes('magazine-thumbnail')).a a = soup.find(**classes('magazine-thumbnail')).a
self.timefmt = ' [%s]' % a['title'] url = a['href']
self.cover_url = absurl(a.img['src']) past_edition = self.recipe_specific_options.get('date')
soup = self.index_to_soup(absurl(a['href'])) 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 = [] articles = []
for article in soup.findAll('div', attrs={'class':'article-text'}): for article in soup.findAll('div', attrs={'class':'article-text'}):
title = self.tag_to_string(article.find(attrs={'class':['h2','h3']})).strip() title = self.tag_to_string(article.find(attrs={'class':['h2','h3']})).strip()
@ -53,4 +72,4 @@ class PsychologyToday(BasicNewsRecipe):
else: else:
desc = '' desc = ''
articles.append({'title': title, 'url': url, 'description': desc, 'author': author}) articles.append({'title': title, 'url': url, 'description': desc, 'author': author})
return [('Current Issue', articles)] return [('Articles', articles)]

View File

@ -6,11 +6,6 @@ from itertools import zip_longest
from calibre.ebooks.BeautifulSoup import BeautifulSoup from calibre.ebooks.BeautifulSoup import BeautifulSoup
from calibre.web.feeds.news import BasicNewsRecipe, classes 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): def media_bucket(x):
if x.get('type', '') == 'image': if x.get('type', '') == 'image':
if x.get('subtype', '') == 'graphic' or 'images.wsj.net' not in x['manifest-url']: 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'] remove_attributes = ['style', 'height', 'width']
resolve_internal_links = True 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 = ''' extra_css = '''
#subhed, em { font-style:italic; color:#202020; } #subhed, em { font-style:italic; color:#202020; }
#byline, #time-to-read, #orig-pubdate-string, .article-byline, time, #flashline { font-size:small; } #byline, #time-to-read, #orig-pubdate-string, .article-byline, time, #flashline { font-size:small; }
@ -103,8 +105,8 @@ class WSJ(BasicNewsRecipe):
pan.name = 'div' pan.name = 'div'
return soup return soup
if not past_edition: def _download_cover(self):
def _download_cover(self): if not self.recipe_specific_options.get('date'):
import os import os
from contextlib import closing 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)) 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:] edit = [itm['key'][10:] for itm in catalog['items'] if itm['type'] == 'ITPNEXTGEN'][1:]
self.log('**Past Editions available :', ', '.join(edit)) self.log('**Past Editions available :', ', '.join(edit))
past_edition = self.recipe_specific_options.get('date')
for itm in catalog['items']: for itm in catalog['items']:
if past_edition: if past_edition:
if itm['key'] == 'ITPNEXTGEN' + past_edition: if itm['key'] == 'ITPNEXTGEN' + past_edition: