Update scientific_american.recipe

This commit is contained in:
unkn0w7n 2024-09-27 14:04:29 +05:30
parent 2f242b8c42
commit fa9ab403b8

View File

@ -47,6 +47,12 @@ class ScientificAmerican(BasicNewsRecipe):
for fig in soup.findAll('figcaption'): for fig in soup.findAll('figcaption'):
for p in fig.findAll(['p', 'div']): for p in fig.findAll(['p', 'div']):
p.name = 'span' 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 return soup
def get_browser(self, *args): def get_browser(self, *args):
@ -66,6 +72,11 @@ class ScientificAmerican(BasicNewsRecipe):
'For example, https://www.scientificamerican.com/issue/sa/2024/07-01/' '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.' '\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}]" self.timefmt = f" [{edition_date:%B %Y}]"
feeds = {} feeds = {}
for section in ("featured", "departments"): for section in issue_info.get("article_previews", {}):
for article in issue_info.get("article_previews", {}).get(section, []): for article in issue_info.get("article_previews", {}).get(section, []):
self.log('\t', article["title"]) self.log('\t', article["title"])
if section == "featured": if section.startswith('featur'):
feed_name = "Features" feed_name = section.capitalize()
else: else:
feed_name = article["category"] feed_name = article["category"]
if feed_name not in feeds: if feed_name not in feeds:
@ -121,5 +132,5 @@ class ScientificAmerican(BasicNewsRecipe):
"description": article["summary"], "description": article["summary"],
} }
) )
sorted_feeds = dict(sorted(feeds.items(), key=lambda x: (not x[0].startswith('Featur'), x[0])))
return feeds.items() return sorted_feeds.items()