mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
26bb850d62
commit
cd56b74115
@ -121,7 +121,7 @@ def process_url(url):
|
||||
|
||||
class EconomistNews(BasicNewsRecipe):
|
||||
title = 'The Economist News'
|
||||
language = 'en'
|
||||
language = 'en_GB'
|
||||
encoding = 'utf-8'
|
||||
masthead_url = 'https://www.livemint.com/lm-img/dev/economist-logo-oneline.png'
|
||||
|
||||
|
@ -12,13 +12,23 @@ from calibre.ebooks.BeautifulSoup import NavigableString, Tag
|
||||
from calibre.web.feeds.news import BasicNewsRecipe
|
||||
|
||||
|
||||
def process_list(li_node):
|
||||
li_html = ''
|
||||
for li in li_node['items']:
|
||||
if li.get('textHtml'):
|
||||
li_html += f'<li>{li.get("textHtml")}</li>'
|
||||
else:
|
||||
li_html += f'<li>{li.get("text", "")}</li>'
|
||||
return li_html
|
||||
|
||||
|
||||
def process_node(node):
|
||||
ntype = node.get('type', '')
|
||||
if ntype == 'CROSSHEAD':
|
||||
if node.get('textHtml'):
|
||||
return f'<h4>{node.get("textHtml")}</h4>'
|
||||
return f'<h4>{node.get("text", "")}</h4>'
|
||||
elif ntype == 'PARAGRAPH':
|
||||
elif ntype in ['PARAGRAPH', 'BOOK_INFO']:
|
||||
if node.get('textHtml'):
|
||||
return f'<p>{node.get("textHtml")}</p>'
|
||||
return f'<p>{node.get("text", "")}</p>'
|
||||
@ -35,9 +45,15 @@ def process_node(node):
|
||||
return f'<blockquote>{node.get("text", "")}</blockquote>'
|
||||
elif ntype == 'DIVIDER':
|
||||
return '<hr>'
|
||||
elif ntype == 'INFOGRAPHIC':
|
||||
if node.get('fallback'):
|
||||
return process_node(node['fallback'])
|
||||
elif ntype == 'INFOBOX':
|
||||
for x in safe_dict(node, 'components'):
|
||||
return f'<blockquote>{process_node(x)}</blockquote>'
|
||||
elif ntype == 'UNORDERED_LIST':
|
||||
if node.get('items'):
|
||||
return process_list(node)
|
||||
elif ntype:
|
||||
print('** ', ntype)
|
||||
return ''
|
||||
@ -57,7 +73,10 @@ class JSONHasNoContent(ValueError):
|
||||
def load_article_from_json(raw):
|
||||
# open('/t/raw.json', 'w').write(raw)
|
||||
body = ''
|
||||
data = json.loads(raw)['props']['pageProps']['cp2Content']
|
||||
try:
|
||||
data = json.loads(raw)['props']['pageProps']['cp2Content']
|
||||
except Exception:
|
||||
data = json.loads(raw)['props']['pageProps']['content']
|
||||
body += f'<div style="color: red; font-size:small; font-weight:bold;">{data.get("flyTitle", "")}</div>'
|
||||
body += f'<h1>{data["headline"]}</h1>'
|
||||
body += f'<div style="font-style: italic; color:#202020;">{data.get("rubric", "")}</div>'
|
||||
@ -114,7 +133,7 @@ def process_url(url):
|
||||
|
||||
class econ_search(BasicNewsRecipe):
|
||||
title = 'The Economist - Search'
|
||||
language = 'en'
|
||||
language = 'en_GB'
|
||||
encoding = 'utf-8'
|
||||
__author__ = 'unkn0wn'
|
||||
description = (
|
||||
|
Loading…
x
Reference in New Issue
Block a user