import os
from pathlib import Path

from app import MyApp
from dotenv import load_dotenv
from sqlmodel import Session, SQLModel, create_engine

load_dotenv()

MOVIES_PATH = Path(os.getenv("MOVIES_FILEPATH", None))

dbfile = Path("database.db")
engine = create_engine("sqlite:///database.db", echo=False)


def create_db_and_tables():
    SQLModel.metadata.create_all(engine)


def main():
    if not dbfile.exists():
        create_db_and_tables()

    with Session(engine) as session:
        MyApp.run(
            title="Media Organizer",
            log="textual.log",
            path=str(MOVIES_PATH.absolute()),
            session=session,
        )


if __name__ == "__main__":
    main()

sqlmodel.SQLModel.metadata.create_all dotenv.load_dotenv pathlib.Path sqlmodel.Session os.getenv sqlmodel.create_engine
[((144, 157), 'dotenv.load_dotenv', 'load_dotenv', ([], {}), '()\n', (155, 157), False, 'from dotenv import load_dotenv\n'), ((224, 243), 'pathlib.Path', 'Path', (['"""database.db"""'], {}), "('database.db')\n", (228, 243), False, 'from pathlib import Path\n'), ((253, 303), 'sqlmodel.create_engine', 'create_engine', (['"""sqlite:///database.db"""'], {'echo': '(False)'}), "('sqlite:///database.db', echo=False)\n", (266, 303), False, 'from sqlmodel import Session, SQLModel, create_engine\n'), ((178, 212), 'os.getenv', 'os.getenv', (['"""MOVIES_FILEPATH"""', 'None'], {}), "('MOVIES_FILEPATH', None)\n", (187, 212), False, 'import os\n'), ((338, 374), 'sqlmodel.SQLModel.metadata.create_all', 'SQLModel.metadata.create_all', (['engine'], {}), '(engine)\n', (366, 374), False, 'from sqlmodel import Session, SQLModel, create_engine\n'), ((458, 473), 'sqlmodel.Session', 'Session', (['engine'], {}), '(engine)\n', (465, 473), False, 'from sqlmodel import Session, SQLModel, create_engine\n')]