From 9e99695611527ec31c9a7c8660397f5230d5b7ba Mon Sep 17 00:00:00 2001 From: Parker Date: Sun, 3 Nov 2024 21:14:42 -0600 Subject: Update config loading/validation --- var.py | 59 ----------------------------------------------------------- 1 file changed, 59 deletions(-) delete mode 100644 var.py (limited to 'var.py') diff --git a/var.py b/var.py deleted file mode 100644 index e444629..0000000 --- a/var.py +++ /dev/null @@ -1,59 +0,0 @@ -import configparser -import logging -import os -from colorlog import ColoredFormatter - - -log_level = logging.DEBUG -log_format = "%(log_color)s%(levelname)-8s%(reset)s %(log_color)s%(message)s%(reset)s" - -logging.root.setLevel(log_level) -formatter = ColoredFormatter(log_format) - -stream = logging.StreamHandler() -stream.setLevel(log_level) -stream.setFormatter(formatter) - -LOG = logging.getLogger("pythonConfig") -LOG.setLevel(log_level) -LOG.addHandler(stream) - - -# If the app is running in Docker -if "BASE_URL" in os.environ or "IP_TO_LOCATION" in os.environ: - BASE_URL = os.environ["BASE_URL"] - IP_TO_LOCATION = ( - True if os.environ["IP_TO_LOCATION"].upper() in ["TRUE", "T"] else False - ) - if IP_TO_LOCATION: - API_KEY = os.environ["API_KEY"] - else: - API_KEY = None - -# Otherwise, the app is running on bare metal -try: - with open("config.ini", "r") as f: - config = configparser.ConfigParser() - config.read_string(f.read()) - - BASE_URL = config["CONFIG"]["BASE_URL"] - IP_TO_LOCATION = ( - True - if config["CONFIG"]["IP_TO_LOCATION"].upper() in ["TRUE", "T"] - else False - ) - if IP_TO_LOCATION: - API_KEY = config["CONFIG"]["API_KEY"] - else: - API_KEY = None -except FileNotFoundError: - config = configparser.ConfigParser() - config["CONFIG"] = {"BASE_URL": "", "IP_TO_LOCATION": "", "API_KEY": ""} - - with open("config.ini", "w") as configfile: - config.write(configfile) - - LOG.error( - "`config.ini` has been created. Fill out the necessary information then re-run." - ) - exit() -- cgit v1.2.3-70-g09d2