Update economist

This commit is contained in:
unkn0w7n 2024-04-21 22:47:32 +05:30
parent 1df7047633
commit 89440f77c3
2 changed files with 22 additions and 30 deletions

View File

@ -64,10 +64,13 @@ def load_article_from_json(raw, root):
for child in tuple(body): for child in tuple(body):
body.remove(child) body.remove(child)
article = E(body, 'article') article = E(body, 'article')
E(article, 'h4', data['subheadline'], style='color: red; margin: 0') E(article, 'div', data['subheadline'] , style='color: red; font-size:small; font-weight:bold;')
E(article, 'h1', data['headline'], style='font-size: x-large') E(article, 'h1', data['headline'])
E(article, 'div', data['description'], style='font-style: italic') E(article, 'div', data['description'], style='font-style: italic; color:#202020;')
E(article, 'div', (data['datePublishedString'] or '') + ' | ' + (data['dateline'] or ''), style='color: gray; margin: 1em') 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') main_image_url = safe_dict(data, 'image', 'main', 'url').get('canonical')
if main_image_url: if main_image_url:
div = E(article, 'div') div = E(article, 'div')
@ -129,31 +132,9 @@ class Economist(BasicNewsRecipe):
' perspective. Best downloaded on Friday mornings (GMT)' ' perspective. Best downloaded on Friday mornings (GMT)'
) )
extra_css = ''' extra_css = '''
.headline {font-size: x-large;} em { color:#202020; }
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;
}
img {display:block; margin:0 auto;} img {display:block; margin:0 auto;}
''' '''
oldest_article = 7.0 oldest_article = 7.0
resolve_internal_links = True resolve_internal_links = True
remove_tags = [ remove_tags = [
@ -206,7 +187,7 @@ class Economist(BasicNewsRecipe):
# open('/t/raw.html', 'wb').write(raw.encode('utf-8')) # open('/t/raw.html', 'wb').write(raw.encode('utf-8'))
root = parse(raw) root = parse(raw)
if '/interactive/' in url: if '/interactive/' in url:
return '<html><body><article><h1 class="headline">' + root.xpath('//h1')[0].text + '</h1><em>' \ return '<html><body><article><h1>' + root.xpath('//h1')[0].text + '</h1><em>' \
+ 'This article is supposed to be read in a browser' \ + 'This article is supposed to be read in a browser' \
+ '</em></article></body></html>' + '</em></article></body></html>'
script = root.xpath('//script[@id="__NEXT_DATA__"]') 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"]'): for x in root.xpath('//*[name()="script" or name()="style" or name()="source" or name()="meta"]'):
x.getparent().remove(x) x.getparent().remove(x)
# the economist uses <small> for small caps with a custom font # the economist uses <small> 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'): for x in root.xpath('//small'):
if x.text and len(x) == 0: if x.text and len(x) == 0:
x.text = x.text.upper() x.text = x.text.upper()
x.tag = 'span' x.tag = 'span'
x.set('style', 'font-variant: small-caps') x.set('style', 'font-variant: small-caps')
for h2 in root.xpath('//h2'):
h2.tag = 'h4'
for x in root.xpath('//figcaption'): for x in root.xpath('//figcaption'):
x.set('style', 'text-align:center; font-size:small;') x.set('style', 'text-align:center; font-size:small;')
for x in root.xpath('//cite'): for x in root.xpath('//cite'):
@ -281,7 +266,7 @@ class Economist(BasicNewsRecipe):
if script_tag is not None: if script_tag is not None:
data = json.loads(script_tag.string) data = json.loads(script_tag.string)
# open('/t/raw.json', 'w').write(json.dumps(data, indent=2, sort_keys=True)) # 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.timefmt = ' [' + safe_dict(data, "props", "pageProps", "content", "datePublishedString") + ']'
self.cover_url = safe_dict(data, "props", "pageProps", "content", "image", "main", "url", "canonical") self.cover_url = safe_dict(data, "props", "pageProps", "content", "image", "main", "url", "canonical")
self.log('Got cover:', self.cover_url) self.log('Got cover:', self.cover_url)
@ -303,6 +288,11 @@ class Economist(BasicNewsRecipe):
else: else:
return [] 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): def eco_find_image_tables(self, soup):
for x in soup.findAll('table', align=['right', 'center']): for x in soup.findAll('table', align=['right', 'center']):
if len(x.findAll('font')) in (1, 2) and len(x.findAll('img')) == 1: if len(x.findAll('font')) in (1, 2) and len(x.findAll('img')) == 1:

View File

@ -19,6 +19,8 @@ class elcorreo(BasicNewsRecipe):
encoding = 'utf-8' encoding = 'utf-8'
remove_empty_feeds = True remove_empty_feeds = True
resolve_internal_links = True resolve_internal_links = True
max_articles_per_feed = 25 # articles
compress_news_images = True
extra_css = ''' extra_css = '''
.v-mdl-ath__inf, .v-mdl-ath__p--2, .v-mdl-ath__p {font-size:small; color:#404040;} .v-mdl-ath__inf, .v-mdl-ath__p--2, .v-mdl-ath__p {font-size:small; color:#404040;}