first commit
This commit is contained in:
32
app/filters.py
Normal file
32
app/filters.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from app.models import Offer
|
||||
|
||||
|
||||
def get_offer_skip_reason(
|
||||
offer: Offer,
|
||||
include_keywords: list[str],
|
||||
exclude_keywords: list[str],
|
||||
min_price_amount: int | None,
|
||||
) -> str | None:
|
||||
haystack = f"{offer.title}\n{offer.description}".lower()
|
||||
|
||||
if exclude_keywords and any(keyword in haystack for keyword in exclude_keywords):
|
||||
return "exclude_keyword"
|
||||
|
||||
if min_price_amount is not None and (offer.price_amount is None or offer.price_amount < min_price_amount):
|
||||
return "min_price_amount"
|
||||
|
||||
if include_keywords and not any(keyword in haystack for keyword in include_keywords):
|
||||
return "include_keyword"
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def is_relevant_offer(
|
||||
offer: Offer,
|
||||
include_keywords: list[str],
|
||||
exclude_keywords: list[str],
|
||||
min_price_amount: int | None,
|
||||
) -> bool:
|
||||
return get_offer_skip_reason(offer, include_keywords, exclude_keywords, min_price_amount) is None
|
||||
Reference in New Issue
Block a user