From d2cc85b697cde929014290bdcfb8b0ea9c0fd350 Mon Sep 17 00:00:00 2001 From: Eric Case Date: Thu, 28 Mar 2019 15:58:45 -0700 Subject: [PATCH] Support loading config via env var In addition to loading the config via a `config.json` file, this change allows it to be loaded via an environment variable called `CZDS_CONFIG`. This makes it straightforward to deploy to services like Heroku, which tend to use env vars for config. See https://12factor.net/ for details. --- download.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/download.py b/download.py index ce1268b..d90e6f9 100644 --- a/download.py +++ b/download.py @@ -12,9 +12,13 @@ from do_http_get import do_get ############################################################################################################## try: - config_file = open("config.json", "r") - config = json.load(config_file) - config_file.close() + if 'CZDS_CONFIG' in os.environ: + config_data = os.environ['CZDS_CONFIG'] + config = json.loads(config_data) + else: + config_file = open("config.json", "r") + config = json.load(config_file) + config_file.close() except: sys.stderr.write("Error loading config.json file.\n") exit(1)