diff --git a/main.py b/main.py index 70990fd..f9a0dce 100644 --- a/main.py +++ b/main.py @@ -11,6 +11,7 @@ import yaml import config.exit_codes as ec from pipeline.pipeline_main import pipeline_main +logger = logging.getLogger("data_pipeline_for_ynab") def set_up_logging(): try: @@ -26,23 +27,21 @@ def set_up_logging(): queue_handler.listener.start() atexit.register(queue_handler.listener.stop) -def load_config(): +def load_config(logger): try: with open('config/config.yaml', 'r') as file: config = yaml.safe_load(file) return config except FileNotFoundError: - logging.error('config.yaml file not found') + logger.error('config.yaml file not found') sys.exit(ec.MISSING_CONFIG_FILE) except yaml.YAMLError as e: - logging.error(f'Error loading config.yaml: {e}') + logger.error(f'Error loading config.yaml: {e}') sys.exit(ec.CORRUPTED_CONFIG_FILE) -logger = logging.getLogger("data_pipeline_for_ynab") os.makedirs('logs', exist_ok=True) set_up_logging() -# Load environment variables dotenv.load_dotenv() API_TOKEN = os.getenv('API_TOKEN') @@ -53,13 +52,12 @@ if not API_TOKEN or not BUDGET_ID: sys.exit(ec.MISSING_ENV_VARS) if __name__ == '__main__': - config = load_config() + config = load_config(logger) config['API_TOKEN'] = API_TOKEN config['BUDGET_ID'] = BUDGET_ID try: pipeline_main(config, logger) - # Check if the data was successfully created data_exists = os.path.exists('data/processed') and os.listdir('data/processed') if data_exists: logger.info('Processing Successful')