From c465dfe08ff721ff558da03eba0cb02b934d0026 Mon Sep 17 00:00:00 2001 From: Igor Chubin Date: Sun, 25 Aug 2019 20:31:46 +0200 Subject: [PATCH] initial json support (fixes #331) --- lib/wttr_line.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/wttr_line.py b/lib/wttr_line.py index e189087..fc26c5d 100644 --- a/lib/wttr_line.py +++ b/lib/wttr_line.py @@ -212,7 +212,16 @@ def render_line(line, data, query): return re.sub(r'%[^%]*[a-zA-Z]', render_symbol, line) -def format_weather_data(format_line, location, override_location, data, query): +def render_json(data): + output = json.dumps(data, indent=4, sort_keys=True) + + output = "\n".join( + re.sub('"[^"]*worldweatheronline[^"]*"', '""', line) if "worldweatheronline" in line else line + for line in output.splitlines()) + "\n" + + return output + +def format_weather_data(format_line, location, override_location, full_address, data, query): """ Format information about current weather `data` for `location` with specified in `format_line` format