use query params to filter out models; also make csv exporter work with models
This commit is contained in:
parent
80c335ba04
commit
e317d2ec54
5 changed files with 72 additions and 113 deletions
|
|
@ -6,70 +6,7 @@ import enum
|
|||
from typing import Any
|
||||
import aiohttp
|
||||
from data_access import Listing
|
||||
from models.listing import FurnishType
|
||||
|
||||
|
||||
class ListingType(enum.StrEnum):
|
||||
BUY = "BUY"
|
||||
RENT = "RENT"
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class QueryParameters:
|
||||
listing_type: ListingType
|
||||
min_bedrooms: int
|
||||
max_bedrooms: int
|
||||
min_price: int
|
||||
max_price: int
|
||||
district_names: set[str]
|
||||
radius: float = 0
|
||||
page_size: int = 500 # items per page
|
||||
max_days_since_added: int = 30
|
||||
furnish_types: list[FurnishType] | None = None
|
||||
# The values below are not supported by rightmove
|
||||
# hence we apply them after fetching
|
||||
# available from; council tax
|
||||
let_date_available_from: datetime | None = None
|
||||
last_seen_days: int | None = None
|
||||
min_sqm: int | None = None
|
||||
|
||||
|
||||
async def filter_listings(
|
||||
listings: list[Listing],
|
||||
query_parameters: QueryParameters,
|
||||
) -> list[Listing]:
|
||||
"""
|
||||
Filter listings based on the provided query parameters.
|
||||
"""
|
||||
filtered_listings = []
|
||||
for listing in listings:
|
||||
if (
|
||||
listing.bedrooms > query_parameters.max_bedrooms
|
||||
or listing.bedrooms < query_parameters.min_bedrooms
|
||||
):
|
||||
continue
|
||||
if (
|
||||
listing.price < query_parameters.min_price
|
||||
or listing.price > query_parameters.max_price
|
||||
):
|
||||
continue
|
||||
if (
|
||||
query_parameters.last_seen_days is not None
|
||||
and listing.last_seen > query_parameters.last_seen_days
|
||||
):
|
||||
continue
|
||||
if (
|
||||
listing.letDateAvailable is not None
|
||||
and query_parameters.let_date_available_from is not None
|
||||
and listing.letDateAvailable < query_parameters.let_date_available_from
|
||||
):
|
||||
continue
|
||||
sqm_ocr = await listing.sqm_ocr() or 0
|
||||
if query_parameters.min_sqm is not None and sqm_ocr < query_parameters.min_sqm:
|
||||
continue
|
||||
filtered_listings.append(listing)
|
||||
|
||||
return filtered_listings
|
||||
from models.listing import FurnishType, ListingType, QueryParameters
|
||||
|
||||
|
||||
headers = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue