From ff8e3422693f9cbf34e67da64c9c46ddc2940430 Mon Sep 17 00:00:00 2001 From: unkn0w7n <51942695+unkn0w7n@users.noreply.github.com> Date: Mon, 10 Feb 2025 09:37:39 +0530 Subject: [PATCH] Update barrons.recipe --- recipes/barrons.recipe | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/recipes/barrons.recipe b/recipes/barrons.recipe index 22fb561ea7..580adff4f3 100644 --- a/recipes/barrons.recipe +++ b/recipes/barrons.recipe @@ -8,6 +8,28 @@ import re from calibre.web.feeds.news import BasicNewsRecipe +def make_hlinks(zx): + txt = zx['body']['text'] + if zx['body'].get('additions'): + for ad in zx['body']['additions']: + if ad.get('type', '') == 'link': + strt = ad['rangeStart'] + end = ad['rangeLength'] + n_txt = txt[strt : (strt + end)] + lnk = ad['value'] + lnk_txt = f'{n_txt}' + txt = txt[:strt] + lnk_txt + txt[(strt + end) :] + if zx['body'].get('inlineTextStyles'): + for sty in zx['body']['inlineTextStyles']: + if 'Italic' in sty['textStyle']['fontName']: + estrt = sty['rangeStart'] + eend = sty['rangeLength'] + etxt = txt[estrt : (estrt + eend)] + em_txt = f'{etxt}' + txt = txt[:estrt] + em_txt + txt[(estrt + eend) :] + return txt + + def make_html(a): typ = a.get('type', '') if typ == 'byline': @@ -20,14 +42,14 @@ def make_html(a): if typ == 'body': if 'body-h' in a['body'].get('textStyleID', ''): return f'

{a["body"]["text"]}

' - return f'

{a["body"]["text"]}

' + return f'

{make_hlinks(a)}

' if typ == 'image': return f'' if typ == 'caption': st = ' style="font-size:small; text-align: center;"' return f'
{a["caption"]["text"]}
' if typ == 'listelement': - return f'
  • {a["body"]["text"]}
  • ' + return f'
  • {make_hlinks(a)}
  • ' if typ == 'dynamicinset': if 'datawrapper-chart-' in a['webview']['value']: dw = re.search(r'datawrapper-chart-(.{5})', a['webview']['value']).group(1) @@ -115,7 +137,7 @@ class Barrons(BasicNewsRecipe): body = '' for x in rdata['screens'][0]['frames']: body += '\n' + make_html(x) - return '' + body + '' + return '' + body.replace(' _', '') + '' def get_browser(self, *args, **kw): kw['user_agent'] = 'okhttp/4.12.0'