From b2550c9441b01f2af8fe548bebf316cf3d1e77e9 Mon Sep 17 00:00:00 2001 From: Igor Chubin Date: Fri, 1 May 2020 17:49:41 +0200 Subject: [PATCH] bin/proxy.py: minor fixes --- bin/proxy.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bin/proxy.py b/bin/proxy.py index 88bff95..7ec909a 100644 --- a/bin/proxy.py +++ b/bin/proxy.py @@ -116,7 +116,7 @@ def _save_content_and_headers(path, query, content, headers): if not os.path.exists(cache_dir): os.makedirs(cache_dir) open(cache_file + ".headers", 'w').write(json.dumps(headers)) - open(cache_file, 'w').write(content) + open(cache_file, 'wb').write(content) def translate(text, lang): """ @@ -141,13 +141,18 @@ def add_translations(content, lang): Add `lang` translation to `content` (JSON) returned by the data source """ + + if content is "{}": + return {} + languages_to_translate = TRANSLATIONS.keys() try: d = json.loads(content) # pylint: disable=invalid-name - except ValueError as exception: + except (ValueError, TypeError) as exception: print("---") print(exception) print("---") + return {} try: weather_condition = d['data']['current_condition'][0]['weatherDesc'][0]['value'] @@ -233,6 +238,7 @@ def proxy(path): headers = {} headers['Content-Type'] = response.headers['content-type'] _save_content_and_headers(path, query_string, response.content, headers) + content = response.content else: content = "{}"