updates to main for logger
This commit is contained in:
@@ -11,6 +11,7 @@ import yaml
|
|||||||
import config.exit_codes as ec
|
import config.exit_codes as ec
|
||||||
from pipeline.pipeline_main import pipeline_main
|
from pipeline.pipeline_main import pipeline_main
|
||||||
|
|
||||||
|
logger = logging.getLogger("data_pipeline_for_ynab")
|
||||||
|
|
||||||
def set_up_logging():
|
def set_up_logging():
|
||||||
try:
|
try:
|
||||||
@@ -26,23 +27,21 @@ def set_up_logging():
|
|||||||
queue_handler.listener.start()
|
queue_handler.listener.start()
|
||||||
atexit.register(queue_handler.listener.stop)
|
atexit.register(queue_handler.listener.stop)
|
||||||
|
|
||||||
def load_config():
|
def load_config(logger):
|
||||||
try:
|
try:
|
||||||
with open('config/config.yaml', 'r') as file:
|
with open('config/config.yaml', 'r') as file:
|
||||||
config = yaml.safe_load(file)
|
config = yaml.safe_load(file)
|
||||||
return config
|
return config
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
logging.error('config.yaml file not found')
|
logger.error('config.yaml file not found')
|
||||||
sys.exit(ec.MISSING_CONFIG_FILE)
|
sys.exit(ec.MISSING_CONFIG_FILE)
|
||||||
except yaml.YAMLError as e:
|
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)
|
sys.exit(ec.CORRUPTED_CONFIG_FILE)
|
||||||
|
|
||||||
logger = logging.getLogger("data_pipeline_for_ynab")
|
|
||||||
os.makedirs('logs', exist_ok=True)
|
os.makedirs('logs', exist_ok=True)
|
||||||
set_up_logging()
|
set_up_logging()
|
||||||
|
|
||||||
# Load environment variables
|
|
||||||
dotenv.load_dotenv()
|
dotenv.load_dotenv()
|
||||||
|
|
||||||
API_TOKEN = os.getenv('API_TOKEN')
|
API_TOKEN = os.getenv('API_TOKEN')
|
||||||
@@ -53,13 +52,12 @@ if not API_TOKEN or not BUDGET_ID:
|
|||||||
sys.exit(ec.MISSING_ENV_VARS)
|
sys.exit(ec.MISSING_ENV_VARS)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
config = load_config()
|
config = load_config(logger)
|
||||||
config['API_TOKEN'] = API_TOKEN
|
config['API_TOKEN'] = API_TOKEN
|
||||||
config['BUDGET_ID'] = BUDGET_ID
|
config['BUDGET_ID'] = BUDGET_ID
|
||||||
try:
|
try:
|
||||||
pipeline_main(config, logger)
|
pipeline_main(config, logger)
|
||||||
|
|
||||||
# Check if the data was successfully created
|
|
||||||
data_exists = os.path.exists('data/processed') and os.listdir('data/processed')
|
data_exists = os.path.exists('data/processed') and os.listdir('data/processed')
|
||||||
if data_exists:
|
if data_exists:
|
||||||
logger.info('Processing Successful')
|
logger.info('Processing Successful')
|
||||||
|
|||||||
Reference in New Issue
Block a user