From 27197b381d7bfc42fd5e3e865a0c2e3147b0c276 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Fri, 25 Aug 2017 23:53:10 +0200 Subject: [PATCH] tools/web: new option to remove callback from JSON files --- nemubot/tools/web.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nemubot/tools/web.py b/nemubot/tools/web.py index 164f5da..c3ba42a 100644 --- a/nemubot/tools/web.py +++ b/nemubot/tools/web.py @@ -193,7 +193,7 @@ def getXML(*args, **kwargs): return parseString(cnt) -def getJSON(*args, **kwargs): +def getJSON(*args, remove_callback=False, **kwargs): """Get content page and return JSON content Arguments: same as getURLContent @@ -204,6 +204,9 @@ def getJSON(*args, **kwargs): return None else: import json + if remove_callback: + import re + cnt = re.sub(r"^[^(]+\((.*)\)$", r"\1", cnt) return json.loads(cnt)