mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update economist
This commit is contained in:
parent
1df7047633
commit
89440f77c3
@ -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 '<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' \
|
||||
+ '</em></article></body></html>'
|
||||
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 <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'):
|
||||
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:
|
||||
|
@ -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;}
|
||||
|
Loading…
x
Reference in New Issue
Block a user