X-Git-Url: https://apps.delaporte.us/gitweb/matrix-chore-bot.git/blobdiff_plain/67be6c948b582842dcb0e0a24b0c6eacde226bfa..HEAD:/matrix_chore_bot/db.py?ds=sidebyside diff --git a/matrix_chore_bot/db.py b/matrix_chore_bot/db.py index c2735e4..a0eae22 100644 --- a/matrix_chore_bot/db.py +++ b/matrix_chore_bot/db.py @@ -8,14 +8,11 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select, text # - [ ] add Vision FK # - [ ] add notes to each chore -CHORE_DB = os.environ.get('CHORE_DB') - DATE_FORMAT = '%Y-%m-%d' def today(): return dt.now().strftime(DATE_FORMAT) - logger = logging.getLogger(__name__) logging.basicConfig(filename='chore.log', encoding='utf-8', level=logging.DEBUG) @@ -38,10 +35,14 @@ def get_chore(session, chore_id): return session.exec(cmd).first() class Data(): - def __init__(self, db_file = CHORE_DB): + def __init__(self, db_file): + self.file = db_file self.engine = self.get_engine() + def get_db_file(self): + return self.file + def get_engine(self): return create_engine(f"sqlite:///{self.file}") @@ -84,12 +85,23 @@ class Data(): cmd = select(Chore) chores = session.exec(cmd).all() if(not chores): - retuls.append('None Found') + results.append('None Found') for chore in chores: results.append(Data.check_chore(session, chore.id)) return results + def filter(self, term): + results = [] + for item in self.list(): + if term in item: + results.append(item) + + return results + + + + def add(self, name): try: with Session(self.engine) as session: