From: Edward Delaporte Date: Sun, 29 Mar 2026 15:54:31 +0000 (-0500) Subject: Add missing functions X-Git-Tag: 1.0.0~2 X-Git-Url: https://us-delaporte.pagekite.me/gitweb/matrix-shop-bot.git/commitdiff_plain/d0f8d69f2d4aa2a1af67baae391663d9bb72c729 Add missing functions --- diff --git a/matrix_shop_bot/db.py b/matrix_shop_bot/db.py index 407a12a..0d1f590 100644 --- a/matrix_shop_bot/db.py +++ b/matrix_shop_bot/db.py @@ -94,16 +94,21 @@ class Data(): def clear_list(self, store_id, clear_all=False): with Session(self.engine) as session: store = session.exec(_get_with_id(Store, store_id)).first() - for item in store.items: - if clear_all or item.purchased_date: - item.remove() + for item in store.shopping_list: + if clear_all or item.purchase_date: + session.delete(item) session.commit() + def get_stores(self): + with Session(self.engine) as session: + cmd = select(Store) + return session.exec(cmd).all() + def get_unsorted_list(self): results = [] with Session(self.engine) as session: - cmd = select(Item).where(Item.store == None) + cmd = select(Item).where(Item.stores == None) items = session.exec(cmd).all() if not items: @@ -123,12 +128,12 @@ class Data(): items = store.shopping_list if not items: results.append(f'-- Nothing to shop for at {store.name} --') - - for item in items: - if(item.purchase_date): - results.append(f' - [x] {item}') - else: - results.append(f' - [ ] {item}') + else: + for item in items: + if(item.purchase_date): + results.append(f' - [x] {item}') + else: + results.append(f' - [ ] {item}') return results def get_engine(self): diff --git a/matrix_shop_bot/tasks.py b/matrix_shop_bot/tasks.py index 966e2cf..1fbc3fb 100644 --- a/matrix_shop_bot/tasks.py +++ b/matrix_shop_bot/tasks.py @@ -17,6 +17,10 @@ def add_store(c, name): result = Data().add_store(name) print(result) +@task +def buy(c, item_id): + result = Data().purchase_item(item_id) + print(result) @task def list(c, store_id): @@ -24,10 +28,23 @@ def list(c, store_id): for item in items: print(item) +@task +def list_stores(c): + items = Data().get_stores() + for item in items: + print(item) + +@task +def clear_list(c, store_id): + Data().clear_list(store_id) + +@task +def clear_all(c, store_id): + Data().clear_list(store_id, clear_all=True) @task -def list_unsorted(c, store_id): - items = Data().list_unsorted() +def list_unsorted(c): + items = Data().get_unsorted_list() for item in items: print(item) @@ -36,3 +53,4 @@ def assign(c, store_id, item_id): result = Data().assign_store(store_id, item_id) print(result) +