From 89440f77c3d7f98ea47ba618c100d26114cad59f Mon Sep 17 00:00:00 2001 From: unkn0w7n <51942695+unkn0w7n@users.noreply.github.com> Date: Sun, 21 Apr 2024 22:47:32 +0530 Subject: [PATCH] Update economist --- recipes/economist.recipe | 50 ++++++++++++++++------------------------ recipes/el_correo.recipe | 2 ++ 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/recipes/economist.recipe b/recipes/economist.recipe index e6dcd3acb8..c9243f4cc6 100644 --- a/recipes/economist.recipe +++ b/recipes/economist.recipe @@ -64,10 +64,13 @@ def load_article_from_json(raw, root): for child in tuple(body): body.remove(child) article = E(body, 'article') - E(article, 'h4', data['subheadline'], style='color: red; margin: 0') - E(article, 'h1', data['headline'], style='font-size: x-large') - E(article, 'div', data['description'], style='font-style: italic') - E(article, 'div', (data['datePublishedString'] or '') + ' | ' + (data['dateline'] or ''), style='color: gray; margin: 1em') + E(article, 'div', data['subheadline'] , style='color: red; font-size:small; font-weight:bold;') + E(article, 'h1', data['headline']) + E(article, 'div', data['description'], style='font-style: italic; color:#202020;') + if data['dateline'] is None: + E(article, 'p', (data['datePublishedString'] or ''), style='color: gray; font-size:small;') + else: + E(article, 'p', (data['datePublishedString'] or '') + ' | ' + (data['dateline']), style='color: gray; font-size:small;') main_image_url = safe_dict(data, 'image', 'main', 'url').get('canonical') if main_image_url: div = E(article, 'div') @@ -129,31 +132,9 @@ class Economist(BasicNewsRecipe): ' perspective. Best downloaded on Friday mornings (GMT)' ) extra_css = ''' - .headline {font-size: x-large;} - h2 { font-size: small; } - h1 { font-size: medium; } - em.Bold {font-weight:bold;font-style:normal;} - em.Italic {font-style:italic;} - p.xhead {font-weight:bold;} - .pullquote { - float: right; - font-size: larger; - font-weight: bold; - font-style: italic; - page-break-inside:avoid; - border-bottom: 3px solid black; - border-top: 3px solid black; - width: 228px; - margin: 0px 0px 10px 15px; - padding: 7px 0px 9px; - } - .flytitle-and-title__flytitle { - display: block; - font-size: smaller; - color: red; - } + em { color:#202020; } img {display:block; margin:0 auto;} - ''' + ''' oldest_article = 7.0 resolve_internal_links = True remove_tags = [ @@ -206,7 +187,7 @@ class Economist(BasicNewsRecipe): # open('/t/raw.html', 'wb').write(raw.encode('utf-8')) root = parse(raw) if '/interactive/' in url: - return '

' + root.xpath('//h1')[0].text + '

' \ + return '

' + root.xpath('//h1')[0].text + '

' \ + 'This article is supposed to be read in a browser' \ + '
' script = root.xpath('//script[@id="__NEXT_DATA__"]') @@ -227,11 +208,15 @@ class Economist(BasicNewsRecipe): for x in root.xpath('//*[name()="script" or name()="style" or name()="source" or name()="meta"]'): x.getparent().remove(x) # the economist uses for small caps with a custom font + for init in root.xpath('//span[@data-caps="initial"]'): + init.set('style', 'font-weight:bold;') for x in root.xpath('//small'): if x.text and len(x) == 0: x.text = x.text.upper() x.tag = 'span' x.set('style', 'font-variant: small-caps') + for h2 in root.xpath('//h2'): + h2.tag = 'h4' for x in root.xpath('//figcaption'): x.set('style', 'text-align:center; font-size:small;') for x in root.xpath('//cite'): @@ -281,7 +266,7 @@ class Economist(BasicNewsRecipe): if script_tag is not None: data = json.loads(script_tag.string) # open('/t/raw.json', 'w').write(json.dumps(data, indent=2, sort_keys=True)) - # self.title = 'The Economist | ' + safe_dict(data, "props", "pageProps", "content", "image", "main", "headline") + self.description = safe_dict(data, "props", "pageProps", "content", "image", "main", "headline") self.timefmt = ' [' + safe_dict(data, "props", "pageProps", "content", "datePublishedString") + ']' self.cover_url = safe_dict(data, "props", "pageProps", "content", "image", "main", "url", "canonical") self.log('Got cover:', self.cover_url) @@ -303,6 +288,11 @@ class Economist(BasicNewsRecipe): else: return [] + def print_version(self, url): + if '/the-americas/' in url or '/china/' in url: + return 'https://webcache.googleusercontent.com/search?q=cache:' + url + return url + def eco_find_image_tables(self, soup): for x in soup.findAll('table', align=['right', 'center']): if len(x.findAll('font')) in (1, 2) and len(x.findAll('img')) == 1: diff --git a/recipes/el_correo.recipe b/recipes/el_correo.recipe index 4f03835d46..f83ee410df 100644 --- a/recipes/el_correo.recipe +++ b/recipes/el_correo.recipe @@ -19,6 +19,8 @@ class elcorreo(BasicNewsRecipe): encoding = 'utf-8' remove_empty_feeds = True resolve_internal_links = True + max_articles_per_feed = 25 # articles + compress_news_images = True extra_css = ''' .v-mdl-ath__inf, .v-mdl-ath__p--2, .v-mdl-ath__p {font-size:small; color:#404040;}