From: Edward Delaporte Date: Tue, 14 Apr 2026 04:41:09 +0000 (-0500) Subject: Fixup X-Git-Url: https://apps.delaporte.us/gitweb/matrix-fridge-bot.git/commitdiff_plain/352468b3659be839c23529e0a341b5a026c28e0e?ds=inline Fixup --- diff --git a/Makefile b/Makefile index a73de66..a8d44c2 100644 --- 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) diff --git a/matrix_fridge_bot/bot.py b/matrix_fridge_bot/bot.py index 2484c46..3afcf91 100644 --- a/matrix_fridge_bot/bot.py +++ b/matrix_fridge_bot/bot.py @@ -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__] diff --git a/matrix_fridge_bot/db.py b/matrix_fridge_bot/db.py index f938a48..85513c1 100644 --- a/matrix_fridge_bot/db.py +++ b/matrix_fridge_bot/db.py @@ -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') diff --git a/matrix_fridge_bot/tasks.py b/matrix_fridge_bot/tasks.py index 74bb304..c51eca1 100644 --- a/matrix_fridge_bot/tasks.py +++ b/matrix_fridge_bot/tasks.py @@ -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}')