]> apps.delaporte.us Git - matrix-fridge-bot.git/commitdiff
Fixup
authorEdward Delaporte <edward@delaporte.us>
Tue, 14 Apr 2026 04:41:09 +0000 (23:41 -0500)
committerEdward Delaporte <edward@delaporte.us>
Tue, 14 Apr 2026 04:41:09 +0000 (23:41 -0500)
Makefile
matrix_fridge_bot/bot.py
matrix_fridge_bot/db.py
matrix_fridge_bot/tasks.py

index a73de668f0e338952bebd8b553453417c190fb9c..a8d44c2ef6df7ba5e00e6d4c3a76a00c55195b28 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
-.PHONY: serve test strict
+.PHONY: serve tail test strict
 
-MODULE=goals
+MODULE=fridge
 
 .venv:
        python -m venv .venv
@@ -13,6 +13,9 @@ clean:
        rm -rf .venv
        rm session.txt  # Reset session
 
+tail:
+       tail -f matrix-$(MODULE)-bot.log
+
 test: .venv
        .venv/bin/pip install .[test]
        .venv/bin/mypy -m $(MODULE)
index 2484c462ba6f6ec7ec642393b6c3efe05b6e7a66..3afcf91c2686cc3999f331f1f76642a375f384fa 100644 (file)
@@ -1,17 +1,15 @@
 '''
-Prefix: !chore
+Prefix: !fridge
 
 Synax:
-!chore COMMAND ARGS
+!fridge COMMAND ARGS
 
 Commands:
-help - show this help
-add - add a chore 
-check - check status of a chore
-done - mark a chore as done
-list - print the chore list
-filter TERM - list all chores that include TERM
-undo - mark a chore as undone
+add - add an item
+list - print the list of fresh items
+remove - remove an item
+to.toss - print the list of items to toss
+filter TERM - list all items that include TERM
 '''
 
 from datetime import datetime as dt
@@ -20,25 +18,27 @@ import os
 
 import simplematrixbotlib as botlib
 
-from .db import Data as ChoreData
+from .db import Data 
 
 logger = logging.getLogger(__name__)
 logging.getLogger('nio').setLevel(logging.WARNING)
 
-class ChoreBot():
+MODULE='fridge'
+
+class FridgeBot():
     def __init__(self, matrix_server,
                  bot_name,
                  bot_pwd,
                  db_file=None,
-                 bot_prefix='!chore'):
+                 bot_prefix='!fridge'):
 
-    logging.basicConfig(filename='matrix-chore-bot.log', encoding='utf-8', level=logging.DEBUG)
+        logging.basicConfig(filename=f'matrix-{MODULE}-bot.log', encoding='utf-8', level=logging.DEBUG)
 
 
         creds = botlib.Creds(matrix_server, bot_name, bot_pwd)
         self.bot = botlib.Bot(creds)
         self.prefix = bot_prefix
-        self.data = ChoreData(db_file=db_file)
+        self.data = Data(db_file=db_file)
 
     def run(self):
         self.bot.run()
@@ -64,12 +64,21 @@ class ChoreBot():
     async def _handle_match(self, match):
 
         if match.command('list'):
-            results = ['## Listing all...']
+            results = ['## Listing fresh items...']
             for item in self.data.list():
                 results.append(item)
             results.append('-- End of List --')
             return results
 
+
+        if match.command('toss'):
+            results = ['## Listing items to toss...']
+            for item in self.data.to_toss():
+                results.append(item)
+            results.append('-- End of List --')
+            return results
+
+
         if match.command('filter'):
             term = ' '.join(match.args()[1:])
             results = [f'## List matching {term}']
@@ -80,37 +89,20 @@ class ChoreBot():
         
         if match.command('setup'):
             results = []
-            results.append('Doing chore setup...')
+            results.append('Doing fridge setup...')
             result = self.data.setup()
             results.append(str(result))
             return results
 
         if match.command('add'):
-            new_chore = ' '.join(match.args()[1:])
-            result = self.data.add(new_chore)
+            new_fridge = ' '.join(match.args()[1:])
+            result = self.data.add(new_fridge)
             return [result]
 
-        if match.command('check'):
-            chore_id = match.args()[1]
-            result = self.data.check(chore_id)
-            return [result]
-
-        if match.command('done'):
-            ids = match.args()[1:]
-            results = []
-            for chore_id in ids:
-                result = self.data.done(chore_id)
-                results.append(result)
-            return results
-
-        if match.command('undo'):
-            chore_id = match.args()[1]
-            result = self.data.undo(chore_id)
-            return [result]
 
         if match.command('remove'):
-            chore_id = match.args()[1]
-            result = self.data.remove(chore_id)
+            fridge_id = match.args()[1]
+            result = self.data.remove(fridge_id)
             return [result]
 
         return [__doc__]
index f938a483896c5ceae23a58715834838a1a3446a4..85513c1836694bc8296c837b22226a7c0c2daa4f 100644 (file)
@@ -1,6 +1,7 @@
 import logging
 import os
 from datetime import datetime as dt
+from datetime import timedelta
 
 from sqlmodel import Field, Session, SQLModel, create_engine, select, text
 
@@ -18,7 +19,7 @@ def today():
     return dt.now().strftime(DATE_FORMAT)
 
 logger = logging.getLogger(__name__)
-logging.basicConfig(filename=f'{MODULE}.log', encoding='utf-8', level=logging.DEBUG)
+logging.basicConfig(filename=f'matrix-{MODULE}-bot.log', encoding='utf-8', level=logging.DEBUG)
 
 class Food(SQLModel, table=True):
     id: int | None = Field(default=None, primary_key=True)
@@ -46,14 +47,17 @@ class Data():
 
     @staticmethod
     def get_stale():
-        return dt.now() - dt.timedelta(STALE_DAYS)
+        stale = dt.now() - timedelta(STALE_DAYS)
+        logger.debug(f'Stale date is {stale}')
+        return stale
 
     def list(self):
         results = []
         with Session(self.engine) as session:
             stale_dt = Data.get_stale()
-            cmd = select(Food).where(Food.added_date < stale_dt)
+            cmd = select(Food).where(Food.added_date > stale_dt)
             results = session.exec(cmd).all()
+            logger.debug(f'List restuls are {str(results)}')
             if(not results):
                 results.append('Nothing Found')
 
@@ -63,7 +67,7 @@ class Data():
         results = []
         with Session(self.engine) as session:
             stale_dt = Data.get_stale()
-            cmd = select(Food).where(Food.added_date >= stale_dt)
+            cmd = select(Food).where(Food.added_date <= stale_dt)
             results = session.exec(cmd).all()
             if(not results):
                 results.append('Nothing Found')
index 74bb3048ad7d6a5b03d0672e2bb7ae8fe47610aa..c51eca161a09e6a00e65bdd9ec1678b982efb7f4 100644 (file)
@@ -18,6 +18,13 @@ def add(c, task):
     result = DATA.add(task)
     print(result)
 
+@task
+def setup(c):
+    '''One time database setup.'''
+    result = DATA.setup()
+    print(result)
+
+
 
 @task
 def list(c):
@@ -28,7 +35,7 @@ def list(c):
 
 
 @task
-def to_toss(c):
+def toss(c):
     result = DATA.to_toss()
     for item in result:
         print(f'{item}')