From 921d82e63f11f11f63088ed9cf66ceee1c66cb9d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 7 Sep 2025 18:46:39 +0530 Subject: [PATCH] Update NYTimes Now they apparently are incapable of generating valid JSON even. Sigh. --- recipes/nytimes.recipe | 2 +- recipes/nytimes_sub.recipe | 2 +- recipes/nytimesbook.recipe | 2 +- src/calibre/web/site_parsers/nytimes.py | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/recipes/nytimes.recipe b/recipes/nytimes.recipe index c59b2b90bf..9cd65b207a 100644 --- a/recipes/nytimes.recipe +++ b/recipes/nytimes.recipe @@ -267,7 +267,7 @@ def preloaded_data(soup): raw = clean_js_json(raw) # with open('/t/raw.json', 'w') as f: # f.write(raw) - return json.loads(raw)['initialState'] + return json.JSONDecoder(strict=False).raw_decode(raw)[0]['initialState'] def asset_to_article(asset): diff --git a/recipes/nytimes_sub.recipe b/recipes/nytimes_sub.recipe index c31bf5c466..1b953f4a26 100644 --- a/recipes/nytimes_sub.recipe +++ b/recipes/nytimes_sub.recipe @@ -267,7 +267,7 @@ def preloaded_data(soup): raw = clean_js_json(raw) # with open('/t/raw.json', 'w') as f: # f.write(raw) - return json.loads(raw)['initialState'] + return json.JSONDecoder(strict=False).raw_decode(raw)[0]['initialState'] def asset_to_article(asset): diff --git a/recipes/nytimesbook.recipe b/recipes/nytimesbook.recipe index 3b6a8f70a3..9161a55ff5 100644 --- a/recipes/nytimesbook.recipe +++ b/recipes/nytimesbook.recipe @@ -132,7 +132,7 @@ def preloaded_data(soup): script = str(script) raw = script[script.find('{') : script.rfind(';')].strip().rstrip(';') # } raw = clean_js_json(raw) - return json.loads(raw)['initialState'] + return json.JSONDecoder(strict=False).raw_decode(raw)[0]['initialState'] def parse_toc(soup): diff --git a/src/calibre/web/site_parsers/nytimes.py b/src/calibre/web/site_parsers/nytimes.py index c4321c29ef..e4f9f8ca4c 100644 --- a/src/calibre/web/site_parsers/nytimes.py +++ b/src/calibre/web/site_parsers/nytimes.py @@ -9,7 +9,7 @@ from xml.sax.saxutils import escape, quoteattr from calibre.utils.iso8601 import parse_iso8601 -module_version = 13 # needed for live updates +module_version = 14 # needed for live updates pprint @@ -207,7 +207,7 @@ def clean_js_json(text): def json_to_html(raw): - data = json.loads(clean_js_json(raw)) + data = json.JSONDecoder(strict=False).raw_decode(raw)[0] # open('/t/raw.json', 'w').write(json.dumps(data, indent=2)) try: data = data['initialData']['data']