From 93addfe147fcf6f9b8131d0f41d09505eb523753 Mon Sep 17 00:00:00 2001 From: unkn0w7n <51942695+unkn0w7n@users.noreply.github.com> Date: Wed, 17 Jul 2024 12:16:21 +0530 Subject: [PATCH] Update Bloomberg --- recipes/bloomberg-business-week.recipe | 37 +++++++++++++++++--------- recipes/bloomberg.recipe | 37 +++++++++++++++++--------- 2 files changed, 49 insertions(+), 25 deletions(-) diff --git a/recipes/bloomberg-business-week.recipe b/recipes/bloomberg-business-week.recipe index e7a47d28f6..46cee92c1f 100644 --- a/recipes/bloomberg-business-week.recipe +++ b/recipes/bloomberg-business-week.recipe @@ -3,7 +3,7 @@ import time from datetime import datetime, timedelta from calibre.ebooks.BeautifulSoup import BeautifulSoup -from calibre.web.feeds.news import BasicNewsRecipe +from calibre.web.feeds.news import BasicNewsRecipe, classes # https://www.bloomberg.com/magazine/businessweek/24_12 @@ -61,6 +61,13 @@ class Bloomberg(BasicNewsRecipe): ) remove_empty_feeds = True + remove_tags = [ + dict(name=['button', 'svg', 'meta']), + dict(name='div', attrs={'id':['bb-that', 'bb-nav']}), + dict(attrs={'data-image-type':'audio'}), + classes('twitter-logo bb-global-footer __sticky__audio__bar__portal__ css--social-wrapper-outer') + ] + extra_css = ''' .auth { font-size:small; font-weight:bold; } .subhead, .cap span { font-style:italic; color:#202020; } @@ -99,7 +106,7 @@ class Bloomberg(BasicNewsRecipe): feeds.append((section, articles)) return feeds - def preprocess_raw_html(self, raw, *a): + def preprocess_raw_html(self, raw, url): data = json.loads(raw) title = '
' + 'By ' + data['byline'] + ' | Updated on ' + dt.strftime('%b %d, %Y at %I:%M %p') + '
' - if 'ledeImage' in data and data['ledeImage'] is not None: - x = data['ledeImage'] - lede = '' + 'This is an interactive article, which is supposed to be read in a browser.' + '
' - body_data = data['components'] - for x in body_data: - body += get_contents(x) + # body_data = data['components'] + # for x in body_data: + # body += get_contents(x) + + b_data = self.index_to_soup('https://cdn-mobapi.bloomberg.com/wssmobile/v1/bw/news/stories/' + url.split('/')[-1], raw=True) + body += json.loads(b_data)['html'] + + if 'ledeImage' in data and data['ledeImage'] is not None: + x = data['ledeImage'] + if x['imageURLs']['default'].rsplit('/', 1)[0] not in body: + lede = '' + 'By ' + data['byline'] + ' | Updated on ' + dt.strftime('%b %d, %Y at %I:%M %p') + '
' - if 'ledeImage' in data and data['ledeImage'] is not None: - x = data['ledeImage'] - lede = '' + 'This is an interactive article, which is supposed to be read in a browser.' + '
' - body_data = data['components'] - for x in body_data: - body += get_contents(x) + # body_data = data['components'] + # for x in body_data: + # body += get_contents(x) + + b_data = self.index_to_soup('https://cdn-mobapi.bloomberg.com/wssmobile/v1/bw/news/stories/' + url.split('/')[-1], raw=True) + body += json.loads(b_data)['html'] + + if 'ledeImage' in data and data['ledeImage'] is not None: + x = data['ledeImage'] + if x['imageURLs']['default'].rsplit('/', 1)[0] not in body: + lede = '