diff --git a/recipes/atlantic.recipe b/recipes/atlantic.recipe index 9e90dcce68..9766ed9ae3 100644 --- a/recipes/atlantic.recipe +++ b/recipes/atlantic.recipe @@ -199,7 +199,7 @@ class TheAtlantic(BasicNewsRecipe): self.cover_url = img['src'] current_section, current_articles = 'Cover Story', [] feeds = [] - for x in soup.findAll(**prefix_classes('TocFeaturedSection_heading__ TocSection_heading__ TocHeroGridItem_hedLink___ TocGridItem_hedLink__')): + for x in soup.findAll(**prefix_classes('TocFeaturedSection_heading__ TocSection_heading__ TocHeroGridItem_hedLink__ TocGridItem_hedLink__')): cls = x['class'] if not isinstance(cls, str): cls = ' '.join(cls) diff --git a/recipes/hindu.recipe b/recipes/hindu.recipe index feaade23ce..616e123cdd 100644 --- a/recipes/hindu.recipe +++ b/recipes/hindu.recipe @@ -11,23 +11,6 @@ def absurl(url): url = 'https://www.thehindu.com' + url return url -# Chennai is default edition, for other editions use 'th_hyderabad', 'th_bangalore', 'th_delhi', 'th_kolkata' etc -local_edition = None - -# For past editions, set date to, for example, '2023-01-28' -past_edition = None - -is_monday = date.today().weekday() == 0 -is_friday = date.today().weekday() == 4 -is_saturday = date.today().weekday() == 5 -is_sunday = date.today().weekday() == 6 - -if past_edition: - year, month, day = (int(x) for x in past_edition.split('-')) - dt = date(year, month, day) - is_monday = dt.weekday() == 0 - is_saturday = dt.weekday() == 5 - is_sunday = dt.weekday() == 6 class TheHindu(BasicNewsRecipe): title = 'The Hindu' @@ -46,6 +29,17 @@ class TheHindu(BasicNewsRecipe): .italic, .sub-title {font-style:italic; color:#202020;} ''' + recipe_specific_options = { + 'location': { + 'short': 'The name of the local edition', + 'long': 'If The Hindu is available in your local town/city,\nset this to your location, for example, hyderabad' + }, + 'date': { + 'short': 'The date of the edition to download (YYYY-MM-DD format)', + 'long': 'For example, 2023-01-28' + } + } + ignore_duplicate_articles = {'url'} keep_only_tags = [ @@ -65,17 +59,24 @@ class TheHindu(BasicNewsRecipe): h3.name = 'p' return soup - def __init__(self, *args, **kwargs): - BasicNewsRecipe.__init__(self, *args, **kwargs) - if self.output_profile.short_name.startswith('kindle'): - if not past_edition: - self.title = 'The Hindu ' + date.today().strftime('%b %d, %Y') - else: - self.title = 'The Hindu ' + dt.strftime('%b %d, %Y') - def parse_index(self): mag_url = None - global local_edition + local_edition = self.recipe_specific_options.get('location') + if local_edition: + local_edition = 'th_' + local_edition + past_edition = self.recipe_specific_options.get('date') + + dt = date.today() + if past_edition: + year, month, day = (int(x) for x in past_edition.split('-')) + dt = date(year, month, day) + + is_monday = dt.weekday() == 0 + is_friday = dt.weekday() == 4 + is_saturday = dt.weekday() == 5 + is_sunday = dt.weekday() == 6 + + if local_edition or past_edition: if local_edition is None: local_edition = 'th_chennai' diff --git a/recipes/psych.recipe b/recipes/psych.recipe index 757621f108..5cad8e823b 100644 --- a/recipes/psych.recipe +++ b/recipes/psych.recipe @@ -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)] diff --git a/recipes/wsj.recipe b/recipes/wsj.recipe index 4c69702b3c..a5d910e9f6 100644 --- a/recipes/wsj.recipe +++ b/recipes/wsj.recipe @@ -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: