Skip to content

Commit

Permalink
Update BBC News for changes in website
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Sep 7, 2021
1 parent b63efc2 commit fed594a
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions recipes/bbc.recipe
Expand Up @@ -12,18 +12,20 @@ from calibre.web.feeds.recipes import BasicNewsRecipe
def serialize_image(block):
yield '<div>'
block = block['model']
media = block['media']
alt = prepare_string_for_xml(media.get('alt') or '', True)
img = block['image']
alt = prepare_string_for_xml(img.get('alt') or '', True)
for q in ('originalSrc', 'src'):
if q in media:
src = prepare_string_for_xml(media[q])
if q in img:
src = prepare_string_for_xml(img[q])
break
else:
raise ValueError('No src found in media block: {}'.format(media))
raise ValueError('No src found in img block: {}'.format(img))
yield '<img src="{}" alt="{}"/>'.format(src, alt)
caption = block.get('caption')
if caption:
yield '<div>{}</div>'.format(prepare_string_for_xml(caption))
if caption and caption.get('type') == 'text':
yield '<div>'
yield from serialize_paragraph(caption)
yield '</div>'
yield '</div>'


Expand Down Expand Up @@ -102,7 +104,7 @@ def parse_article_json(root, abort_article):
lines.append('<h1>{}</h1>'.format(prepare_string_for_xml(article['headline'])))
if article.get('contributor'):
lines.extend(serialize_contributor(article['contributor']))
for block in article['blocks']:
for block in article['content']['model']['blocks']:
bt = block.get('type')
if bt == 'image':
lines.extend(serialize_image(block))
Expand Down

0 comments on commit fed594a

Please sign in to comment.