33 lines
953 B
Python
33 lines
953 B
Python
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
|