From fb9b0c56a5a5771816f3c2cb62a727e6392fbbbb Mon Sep 17 00:00:00 2001 From: unkn0w7n <51942695+unkn0w7n@users.noreply.github.com> Date: Sat, 21 Sep 2024 10:49:10 +0530 Subject: [PATCH] Update nytfeeds.recipe --- recipes/nytfeeds.recipe | 42 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/recipes/nytfeeds.recipe b/recipes/nytfeeds.recipe index c803ae7ec8..e7e6a8ab31 100644 --- a/recipes/nytfeeds.recipe +++ b/recipes/nytfeeds.recipe @@ -13,7 +13,10 @@ def extract_json(raw): return js['initialData']['data']['article']['sprinkledBody']['content'] def parse_image(i): - yield '
'.format(i['crops'][0]['renditions'][0]['url']) + if i.get('crops'): + yield '
'.format(i['crops'][0]['renditions'][0]['url']) + elif i.get('spanImageCrops'): + yield '
'.format(i['spanImageCrops'][0]['renditions'][0]['url']) if i.get('caption'): yield '
' + ''.join(parse_types(i['caption'])) if i.get('credit'): @@ -23,13 +26,36 @@ def parse_image(i): def parse_img_grid(g): for grd in g.get('gridMedia', {}): - yield ''.join(parse_image(grd)) + yield '
'.join(parse_image(grd)) if g.get('caption'): yield '
{}'.format(g['caption']) if g.get('credit'): yield ' ' + g['credit'] + '' yield '
' +def parse_vid(v): + if v.get('promotionalMedia'): + if v.get('headline'): + if v.get('url'): + yield '
Video: '.format(v['url'])\ + + v['headline'].get('default', '') + '
' + elif v['headline'].get('default'): + yield '
' + v['headline']['default'] + '
' + yield ''.join(parse_types(v['promotionalMedia'])) + if v.get('promotionalSummary'): + yield '
' + v['promotionalSummary'] + '
' + +def parse_emb(e): + if e.get('html') and 'datawrapper.dwcdn.net' in e['html']: + dw = re.search(r'datawrapper.dwcdn.net/(.{5})', e['html']).group(1) + yield '
'.format('https://datawrapper.dwcdn.net/' + dw + '/full.png') + '
' + elif e.get('promotionalMedia'): + if e.get('headline'): + yield '
' + e['headline']['default'] + '
' + yield ''.join(parse_types(e['promotionalMedia'])) + if e.get('note'): + yield '
' + e['note'] + '
' + def parse_byline(byl): for b in byl.get('bylines', {}): yield '
' + b['renderedRepresentation'] + '
' @@ -116,6 +142,16 @@ def parse_types(x): elif x.get('__typename', '') == 'GridBlock': yield ''.join(parse_img_grid(x)) + elif x.get('__typename', '') == 'VideoBlock': + yield ''.join(parse_types(x['media'])) + elif x.get('__typename', '') == 'Video': + yield ''.join(parse_vid(x)) + + elif x.get('__typename', '') == 'InteractiveBlock': + yield ''.join(parse_types(x['media'])) + elif x.get('__typename', '') == 'EmbeddedInteractive': + yield ''.join(parse_emb(x)) + elif x.get('__typename', '') == 'ListBlock': yield '
    ' + ''.join(parse_cnt(x)) + '
' elif x.get('__typename', '') == 'ListItemBlock': @@ -181,7 +217,7 @@ class nytFeeds(BasicNewsRecipe): }, 'res': { 'short': 'For hi-res images, select a resolution from the following\noptions: popup, jumbo, mobileMasterAt3x, superJumbo', - 'long': 'This is useful for non e-ink devices, and for a lower file size\nthan the default(articleLarge), use articleInline.', + 'long': 'This is useful for non e-ink devices, and for a lower file size\nthan the default, use articleInline.', } }