import logging
from sqlmodel import SQLModel, create_engine
import json
from dataclasses import dataclass
from etl.stores import run as etl_stores
from etl.sales import run as etl_sales
from etl.products import run as etl_products

# config to define variables
@dataclass
class Config:
    stores_url: str
    stores_filepath: str
    db_conn_uri: str
    log_level: str

# TODO convert this to a DAG or a pipeline
if __name__ == '__main__':
    # load the config
    config_dict = {}
    with open('config.json', 'r') as f:
        config_dict = json.load(f)
    if config_dict['log_level'] == 'DEBUG':    
        config_dict['log_level'] = logging.DEBUG
    else:
        config_dict['log_level'] = logging.INFO

    # create the config object
    config = Config(**config_dict)

    # setup logging
    logging.basicConfig()
    logging.getLogger().setLevel(config.log_level)

    # create the database engine
    engine = create_engine(config.db_conn_uri)

    # create the sqlmodel metadata for the engine
    SQLModel.metadata.create_all(engine)

    # handle stores
    etl_stores(config.stores_filepath, config.stores_url, engine)

    # handle products
    etl_products(engine)

    # handle sales data   
    etl_sales(engine)


json.load etl.stores.run sqlmodel.create_engine logging.basicConfig sqlmodel.SQLModel.metadata.create_all etl.products.run etl.sales.run logging.getLogger
[((807, 828), 'logging.basicConfig', 'logging.basicConfig', ([], {}), '()\n', (826, 828), False, 'import logging\n'), ((927, 960), 'sqlmodel.create_engine', 'create_engine', (['config.db_conn_uri'], {}), '(config.db_conn_uri)\n', (940, 960), False, 'from sqlmodel import SQLModel, create_engine\n'), ((1016, 1052), 'sqlmodel.SQLModel.metadata.create_all', 'SQLModel.metadata.create_all', (['engine'], {}), '(engine)\n', (1044, 1052), False, 'from sqlmodel import SQLModel, create_engine\n'), ((1078, 1139), 'etl.stores.run', 'etl_stores', (['config.stores_filepath', 'config.stores_url', 'engine'], {}), '(config.stores_filepath, config.stores_url, engine)\n', (1088, 1139), True, 'from etl.stores import run as etl_stores\n'), ((1167, 1187), 'etl.products.run', 'etl_products', (['engine'], {}), '(engine)\n', (1179, 1187), True, 'from etl.products import run as etl_products\n'), ((1220, 1237), 'etl.sales.run', 'etl_sales', (['engine'], {}), '(engine)\n', (1229, 1237), True, 'from etl.sales import run as etl_sales\n'), ((547, 559), 'json.load', 'json.load', (['f'], {}), '(f)\n', (556, 559), False, 'import json\n'), ((833, 852), 'logging.getLogger', 'logging.getLogger', ([], {}), '()\n', (850, 852), False, 'import logging\n')]