From 8790e64458b6c36ec6a4a5667f963e1f58398ee4 Mon Sep 17 00:00:00 2001 From: unkn0w7n <51942695+unkn0w7n@users.noreply.github.com> Date: Sat, 22 Jul 2023 15:21:29 +0530 Subject: [PATCH] Update bloomberg-business-week.recipe --- recipes/bloomberg-business-week.recipe | 123 ++++++++++++++++++++----- 1 file changed, 102 insertions(+), 21 deletions(-) diff --git a/recipes/bloomberg-business-week.recipe b/recipes/bloomberg-business-week.recipe index 55a3623f5e..41f3fa41ae 100644 --- a/recipes/bloomberg-business-week.recipe +++ b/recipes/bloomberg-business-week.recipe @@ -17,9 +17,10 @@ class Bloomberg(BasicNewsRecipe): masthead_url = 'https://assets.bwbx.io/s3/javelin/public/hub/images/BW-Logo-Black-cc9035fbb3.svg' # delay = 7 # seconds - # simultaneous_downloads = 1 + simultaneous_downloads = 3 extra_css = ''' + #bold {font-weight:bold;} #auth {font-size:small; font-weight:bold;} #time, .chart {font-size:small;} #subhead {font-style:italic; color:#404040;} @@ -94,37 +95,31 @@ class Bloomberg(BasicNewsRecipe): cat = subhead = lede = auth = caption = '' - if 'primaryCategory' in data: - if data['primaryCategory'] is not None: + if 'primaryCategory' in data and data['primaryCategory'] is not None: cat = '
' + data['primaryCategory'] + '
' - if len(data['abstract']) != 0: - if len(data['abstract']) == 2: + if len(data['abstract']) != 0 and len(data['abstract']) == 2: subhead = '' + data['abstract'][0] + '
' + data['abstract'][1] + '
' + data['summary'] + '
'.format(data['ledeImageUrl'])
- if 'ledeDescription' in data:
- if data['ledeDescription'] is not None:
+ if 'ledeDescription' in data and data['ledeDescription'] is not None:
caption = '' + data['ledeDescription'] + ''
else:
- if 'lede' in data:
- if data['lede'] is not None:
- if 'alt' in data['lede']:
- if data['lede']['alt'] is not None:
+ if 'lede' in data and data['lede'] is not None:
+ if 'alt' in data['lede'] and data['lede']['alt'] is not None:
caption = '' + data['lede']['alt'] + ''
if m:
+ time.sleep(3)
body = data['body']
else:
body = ''
@@ -132,7 +127,7 @@ class Bloomberg(BasicNewsRecipe):
for objects in body_data:
- pause = random.choice((0.5, 1, 1.25, 1.5))
+ pause = random.choice((0.5, 1, 1.25))
time.sleep(pause)
if objects['type'] == 'media' and objects['subType'] == 'photo':
@@ -142,8 +137,10 @@ class Bloomberg(BasicNewsRecipe):
if objects['data'] and objects['data']['chart']:
body += '
'.format(objects['data']['chart']['fallback'])
- if objects['type'] == 'paragraph' or 'heading': # lists are missed :(
+ if objects['type'] == 'paragraph':
body += '
' + if 'value' in objects: + body += objects['value'] if 'content' not in objects: continue @@ -154,21 +151,59 @@ class Bloomberg(BasicNewsRecipe): body += item['value'] if item['type'] == 'link' and item['data']: - if 'href' not in item['data']: - continue if item['content'] and item['content'][0] and item['content'][0]['value']: - body += '' + item['content'][0]['value'] + '' - + if 'href' in item['data']: + body += '' + item['content'][0]['value'] + '' + else: + body += '' + item['content'][0]['value'] + '' + if item['type'] == 'entity': if item['content'] and item['content'][0] and item['content'][0]['value']: if item['subType'] == 'story': if item['data'] and item['data']['link'] and item['data']['link']['destination']: if 'web' in item['data']['link']['destination']: body += '' + item['content'][0]['value'] + '' + else: + body += '' + item['content'][0]['value'] + '' + + elif item['subType'] == 'person' or 'security': + body += item['content'][0]['value'] + + if objects['type'] == 'heading': + body += '
' + if 'value' in objects: + body += objects['value'] + + if 'content' not in objects: + continue + + for item in objects['content']: + + if item['type'] == 'text' and item['value']: + body += item['value'] + + if item['type'] == 'link' and item['data']: + if item['content'] and item['content'][0] and item['content'][0]['value']: + if 'href' in item['data']: + body += '' + item['content'][0]['value'] + '' + else: + body += '' + item['content'][0]['value'] + '' + + if item['type'] == 'entity': + if item['content'] and item['content'][0] and item['content'][0]['value']: + if item['subType'] == 'story': + if item['data'] and item['data']['link'] and item['data']['link']['destination']: + if 'web' in item['data']['link']['destination']: + body += '' + item['content'][0]['value'] + '' + else: + body += '' + item['content'][0]['value'] + '' + elif item['subType'] == 'person' or 'security': body += item['content'][0]['value'] if objects['type'] == 'quote': + if 'value' in objects: + body +='
' + objects['value'] + '' if 'content' not in objects: continue for item in objects['content']: @@ -177,6 +212,52 @@ class Bloomberg(BasicNewsRecipe): continue body += '
' + item['content'][0]['value'] + '' + if objects['type'] == 'list': + if 'content' not in objects: + continue + body += '
' + if 'value' in objects: + body += objects['value'] + if not 'content' in objects: + continue + for content in objects['content']: + if 'value' in content: + body += content['value'] + elif 'content' in content: + for cont1 in content['content']: + if 'value' in cont1: + body += cont1['value'] + elif 'content' in val_cont: + for cont2 in val_cont['content']: + if 'value' in cont2: + body += cont2['value'] + elif 'content' in cont2: + for cont3 in cont2['content']: + if 'value' in cont3: + body += cont3['value'] + elif 'content' in cont3: + for cont4 in cont3['content']: + if 'value' in cont4: + body += cont4['value'] + html = '
' + cat + title + subhead + auth + lede + caption + '