]> us-delaporte.pagekite.me Git - matrix-chore-bot.git/blobdiff - matrix_chore_bot/db.py
Add ability to run with separate prefix and database file
[matrix-chore-bot.git] / matrix_chore_bot / db.py
index c2735e4a79f110c7c27c92f657d2204101ff0f86..536c9c08fb7640e056271763ab69d6bfb35acdfb 100644 (file)
@@ -8,13 +8,13 @@ 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)
 
+DEFAULT_DB_FILE = os.path.join(os.environ.get('MATRIX_DATA_DIR', ''), 'chores.db')
+DB_FILE = os.environ.get('MATRIX_CHORE_DB_FILE', DEFAULT_DB_FILE)
 
 logger = logging.getLogger(__name__)
 logging.basicConfig(filename='chore.log', encoding='utf-8', level=logging.DEBUG)
@@ -38,7 +38,11 @@ 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=None):
+
+        if not db_file:
+            db_file = DB_FILE
+
         self.file = db_file
         self.engine = self.get_engine()
 
@@ -84,7 +88,7 @@ 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))