reuse query params when exporting to immoweb and allow filtering from available date
This commit is contained in:
parent
a23a5ae192
commit
11315359d2
6 changed files with 10207 additions and 42335 deletions
|
|
@ -1,8 +1,11 @@
|
|||
# from diskcache import Cache
|
||||
import asyncio
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
import enum
|
||||
from typing import Any
|
||||
import aiohttp
|
||||
from data_access import Listing
|
||||
|
||||
|
||||
class ListingType(enum.StrEnum):
|
||||
|
|
@ -16,6 +19,57 @@ class FurnishType(enum.StrEnum):
|
|||
PART_FURNISHED = "partFurnished"
|
||||
|
||||
|
||||
@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 = 14
|
||||
|
||||
|
||||
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 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
|
||||
filtered_listings.append(listing)
|
||||
|
||||
return filtered_listings
|
||||
|
||||
|
||||
headers = {
|
||||
"Host": "api.rightmove.co.uk",
|
||||
# 'Accept-Encoding': 'gzip, deflate, br',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue