mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-11 09:13:57 -04:00
Fix The Economist recipe NoneType is not iterable error
the "image" value could be null, for example: https://www.economist.com/special-report/2022/04/20/sources-and-acknowledgments
This commit is contained in:
parent
4f83016d30
commit
700fdb7ef9
@ -59,15 +59,14 @@ def load_article_from_json(raw, root):
|
||||
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')
|
||||
images = data['image']
|
||||
if 'main' in images:
|
||||
main_image_url = data.get('image', {}).get('main', {}).get('url', {}).get('canonical')
|
||||
if main_image_url:
|
||||
div = E(article, 'div')
|
||||
try:
|
||||
E(div, 'img', src=images['main']['url']['canonical'])
|
||||
E(div, 'img', src=main_image_url)
|
||||
except Exception:
|
||||
pass
|
||||
text = data['text']
|
||||
for node in text:
|
||||
for node in data.get('text', []):
|
||||
process_node(node, article)
|
||||
|
||||
|
||||
|
@ -59,15 +59,14 @@ def load_article_from_json(raw, root):
|
||||
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')
|
||||
images = data['image']
|
||||
if 'main' in images:
|
||||
main_image_url = data.get('image', {}).get('main', {}).get('url', {}).get('canonical')
|
||||
if main_image_url:
|
||||
div = E(article, 'div')
|
||||
try:
|
||||
E(div, 'img', src=images['main']['url']['canonical'])
|
||||
E(div, 'img', src=main_image_url)
|
||||
except Exception:
|
||||
pass
|
||||
text = data['text']
|
||||
for node in text:
|
||||
for node in data.get('text', []):
|
||||
process_node(node, article)
|
||||
|
||||
|
||||
@ -236,7 +235,7 @@ class Economist(BasicNewsRecipe):
|
||||
|
||||
def parse_index(self):
|
||||
# return [('Articles', [{'title':'test',
|
||||
# 'url':'file:///t/raw.html'
|
||||
# 'url':'https://www.economist.com/briefing/2021/09/11/how-america-wasted-its-unipolar-moment'
|
||||
# }])]
|
||||
if edition_date:
|
||||
url = 'https://www.economist.com/weeklyedition/' + edition_date
|
||||
|
Loading…
x
Reference in New Issue
Block a user