diff --git a/.env.example b/.env.example index 59b4c30..63619af 100644 --- a/.env.example +++ b/.env.example @@ -8,7 +8,7 @@ MATRIX_DEALS_ROOM_ID=!roomid:example.com ITAD_API_KEY= # Deal filtering -MIN_DEAL_RATING=80 +MIN_DEAL_RATING=8.0 MIN_DISCOUNT_PERCENT=50 MAX_PRICE_USD=20 diff --git a/README.md b/README.md index eb50c8d..567f7e2 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ All configuration is via environment variables (see `.env.example`): | `MATRIX_BOT_ACCESS_TOKEN` | Yes | — | Bot's access token | | `MATRIX_DEALS_ROOM_ID` | Yes | — | Room ID to post deals in | | `ITAD_API_KEY` | No | — | IsThereAnyDeal API key for historical low detection | -| `MIN_DEAL_RATING` | No | 80 | Minimum CheapShark deal rating (0-100) | +| `MIN_DEAL_RATING` | No | 8.0 | Minimum CheapShark deal rating (0-10) | | `MIN_DISCOUNT_PERCENT` | No | 50 | Minimum discount percentage | | `MAX_PRICE_USD` | No | 20 | Maximum sale price in USD | | `DATABASE_PATH` | No | deals.db | Path to SQLite database file | diff --git a/gaming_deals_bot/__main__.py b/gaming_deals_bot/__main__.py index c6dd4e4..93c6525 100644 --- a/gaming_deals_bot/__main__.py +++ b/gaming_deals_bot/__main__.py @@ -13,17 +13,22 @@ from .config import Config from .preflight import run_preflight -def setup_logging(): +def setup_logging(*, debug: bool = False): logging.basicConfig( - level=logging.INFO, + level=logging.DEBUG if debug else logging.INFO, format="%(asctime)s [%(levelname)s] %(name)s: %(message)s", stream=sys.stdout, ) + if not debug: + # Keep noisy third-party loggers quiet even in debug mode + logging.getLogger("httpx").setLevel(logging.WARNING) + logging.getLogger("httpcore").setLevel(logging.WARNING) async def main(): load_dotenv() - setup_logging() + debug_mode = "--debug" in sys.argv + setup_logging(debug=debug_mode) logger = logging.getLogger("gaming_deals_bot") check_mode = "--check" in sys.argv diff --git a/gaming_deals_bot/cheapshark.py b/gaming_deals_bot/cheapshark.py index a60e983..4062cb3 100644 --- a/gaming_deals_bot/cheapshark.py +++ b/gaming_deals_bot/cheapshark.py @@ -68,14 +68,21 @@ async def fetch_deals( logger.error("CheapShark API error: %s", exc) return [] + logger.info( + "CheapShark returned %d raw deals (before filtering)", len(raw_deals), + ) + deals = [] for d in raw_deals: savings = float(d.get("savings", 0)) rating = float(d.get("dealRating", 0)) + title = d.get("title", "?") if savings < min_discount: + logger.debug("Filtered out %s: savings %.1f%% < %.1f%%", title, savings, min_discount) continue - if rating * 10 < min_rating: # dealRating is 0-10, config is 0-100 + if rating < min_rating: + logger.debug("Filtered out %s: rating %.1f < %.1f", title, rating, min_rating) continue steam_app_id = d.get("steamAppID") or None diff --git a/gaming_deals_bot/config.py b/gaming_deals_bot/config.py index 1db6d35..4c25a9e 100644 --- a/gaming_deals_bot/config.py +++ b/gaming_deals_bot/config.py @@ -15,7 +15,7 @@ class Config: self.itad_api_key = os.environ.get("ITAD_API_KEY", "") # Deal filtering - self.min_deal_rating = int(os.environ.get("MIN_DEAL_RATING", "80")) + self.min_deal_rating = float(os.environ.get("MIN_DEAL_RATING", "8.0")) self.min_discount_percent = int(os.environ.get("MIN_DISCOUNT_PERCENT", "50")) self.max_price_usd = float(os.environ.get("MAX_PRICE_USD", "20"))