From 7dfbd50d9524cf49dde2050990cd5d15e8e1ff23 Mon Sep 17 00:00:00 2001 From: Igor Chubin Date: Thu, 31 Jan 2019 00:32:09 +0000 Subject: [PATCH] debug starting mode (with env variables) --- bin/srv.py | 8 ++++++-- lib/get_answer.py | 8 +++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/bin/srv.py b/bin/srv.py index 20a4e65..2c8499b 100644 --- a/bin/srv.py +++ b/bin/srv.py @@ -206,5 +206,9 @@ def answer(topic=None): return result return Response(result, mimetype='text/plain') -SRV = WSGIServer((SERVER_ADDRESS, SERVER_PORT), app) # log=None) -SRV.serve_forever() +if 'CHEATSH_PORT' in os.environ: + SRV = WSGIServer((SERVER_ADDRESS, int(os.environ.get('CHEATSH_PORT'))), app) # log=None) + SRV.serve_forever() +else: + SRV = WSGIServer((SERVER_ADDRESS, SERVER_PORT), app) # log=None) + SRV.serve_forever() diff --git a/lib/get_answer.py b/lib/get_answer.py index 2ed3e92..fb4c1df 100644 --- a/lib/get_answer.py +++ b/lib/get_answer.py @@ -471,7 +471,8 @@ def get_answer(topic, keyword, options="", request_options=None): # pylint: disa topic = "q:" + topic needs_beautification = True - answer = REDIS.get(topic) + if REDIS: + answer = REDIS.get(topic) if answer: answer = answer.decode('utf-8') @@ -488,8 +489,9 @@ def get_answer(topic, keyword, options="", request_options=None): # pylint: disa answer = _get_unknown(topic) # saving answers in the cache - if topic_type not in ["search", "internal", "unknown"]: - REDIS.set(topic, answer) + if REDIS: + if topic_type not in ["search", "internal", "unknown"]: + REDIS.set(topic, answer) if needs_beautification: filetype = 'bash'