From fa9ab403b8cbf78b0fbf6feab988a10a1e669132 Mon Sep 17 00:00:00 2001 From: unkn0w7n <51942695+unkn0w7n@users.noreply.github.com> Date: Fri, 27 Sep 2024 14:04:29 +0530 Subject: [PATCH] Update scientific_american.recipe --- recipes/scientific_american.recipe | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/recipes/scientific_american.recipe b/recipes/scientific_american.recipe index 10ffc5bb1d..72f2985313 100644 --- a/recipes/scientific_american.recipe +++ b/recipes/scientific_american.recipe @@ -47,6 +47,12 @@ class ScientificAmerican(BasicNewsRecipe): for fig in soup.findAll('figcaption'): for p in fig.findAll(['p', 'div']): p.name = 'span' + res = '?w=600' + w = self.recipe_specific_options.get('res') + if w and isinstance(w, str): + res = '?w=' + w + for img in soup.findAll('img', src=True): + img['src'] = img['src'].split('?')[0] + res return soup def get_browser(self, *args): @@ -66,6 +72,11 @@ class ScientificAmerican(BasicNewsRecipe): 'For example, https://www.scientificamerican.com/issue/sa/2024/07-01/' '\nYou can also download special-editions, physics, health, mind magazines by pasting the URL here.' ) + }, + 'res': { + 'short': 'For hi-res images, select a resolution from the\nfollowing options: 800, 1000, 1200 or 1500', + 'long': 'This is useful for non e-ink devices, and for a lower file size\nthan the default, use 400 or 300.', + 'default': '600' } } @@ -102,11 +113,11 @@ class ScientificAmerican(BasicNewsRecipe): self.timefmt = f" [{edition_date:%B %Y}]" feeds = {} - for section in ("featured", "departments"): + for section in issue_info.get("article_previews", {}): for article in issue_info.get("article_previews", {}).get(section, []): self.log('\t', article["title"]) - if section == "featured": - feed_name = "Features" + if section.startswith('featur'): + feed_name = section.capitalize() else: feed_name = article["category"] if feed_name not in feeds: @@ -121,5 +132,5 @@ class ScientificAmerican(BasicNewsRecipe): "description": article["summary"], } ) - - return feeds.items() + sorted_feeds = dict(sorted(feeds.items(), key=lambda x: (not x[0].startswith('Featur'), x[0]))) + return sorted_feeds.items()