From: Edward Delaporte Date: Sun, 7 Jun 2026 01:07:20 +0000 (-0500) Subject: Show unique items from past 90 days when requested X-Git-Url: https://us-delaporte.pagekite.me/gitweb/matrix-shop-bot.git/commitdiff_plain/b0d59de8e794c84f2089515e3adf3a68703c96b8?ds=inline Show unique items from past 90 days when requested --- diff --git a/matrix_shop_bot/db.py b/matrix_shop_bot/db.py index 007e758..6cacc33 100644 --- a/matrix_shop_bot/db.py +++ b/matrix_shop_bot/db.py @@ -1,6 +1,7 @@ import logging import os from datetime import datetime as dt +from datetime import timedelta from decimal import Decimal from typing import List @@ -191,9 +192,13 @@ class Data(): def list_purchases(self, store_name): with Session(self.engine) as session: - cmd = select(PurchaseRecord).where(func.lower(PurchaseRecord.store) == func.lower(store_name)) + recent = dt.now() - timedelta(days=90) + cmd = select(PurchaseRecord).where(func.lower(PurchaseRecord.store) == func.lower(store_name)).where(PurchaseRecord.purchase_date > recent) records = session.exec(cmd).all() - return records + bought = set() + for item in records: + bought.add(item.name) + return list(bought) def purchase_items(self, item_ids): results = []