This commit is contained in:
Kovid Goyal 2024-09-12 13:36:03 +05:30
commit b4713b3020
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 22 additions and 4 deletions

View File

@ -202,6 +202,11 @@ class Economist(BasicNewsRecipe):
'date': {
'short': 'The date of the edition to download (YYYY-MM-DD format)',
'long': 'For example, 2024-07-19\nThis seems to work only for a couple of past editions.'
},
'res': {
'short': 'For hi-res images, select a resolution from the\nfollowing options: 834, 960, 1096, 1280, 1424',
'long': 'This is useful for non e-ink devices, and for a lower file size\nthan the default, use from 480, 384, 360, 256.',
'default': '600'
}
}
@ -318,9 +323,13 @@ class Economist(BasicNewsRecipe):
article.url = soup.find('h1')['title']
def preprocess_html(self, soup):
width = '600'
w = self.recipe_specific_options.get('res')
if w and isinstance(w, str):
width = w
for img in soup.findAll('img', src=True):
img['src'] = img['src'].replace('economist.com/',
'economist.com/cdn-cgi/image/width=600,quality=80,format=auto/')
qua = 'economist.com/cdn-cgi/image/width=' + width + ',quality=80,format=auto/'
img['src'] = img['src'].replace('economist.com/', qua)
return soup
else: # Load articles from individual article pages {{{

View File

@ -202,6 +202,11 @@ class Economist(BasicNewsRecipe):
'date': {
'short': 'The date of the edition to download (YYYY-MM-DD format)',
'long': 'For example, 2024-07-19\nThis seems to work only for a couple of past editions.'
},
'res': {
'short': 'For hi-res images, select a resolution from the\nfollowing options: 834, 960, 1096, 1280, 1424',
'long': 'This is useful for non e-ink devices, and for a lower file size\nthan the default, use from 480, 384, 360, 256.',
'default': '600'
}
}
@ -318,9 +323,13 @@ class Economist(BasicNewsRecipe):
article.url = soup.find('h1')['title']
def preprocess_html(self, soup):
width = '600'
w = self.recipe_specific_options.get('res')
if w and isinstance(w, str):
width = w
for img in soup.findAll('img', src=True):
img['src'] = img['src'].replace('economist.com/',
'economist.com/cdn-cgi/image/width=600,quality=80,format=auto/')
qua = 'economist.com/cdn-cgi/image/width=' + width + ',quality=80,format=auto/'
img['src'] = img['src'].replace('economist.com/', qua)
return soup
else: # Load articles from individual article pages {{{