All good
This commit is contained in:
parent
6ea544a0f6
commit
6cc7288126
45 changed files with 929 additions and 1043 deletions
|
|
@ -10,15 +10,6 @@ from constants import (
|
|||
TYPEAHEAD_URL,
|
||||
)
|
||||
from http_client import fetch_with_retry
|
||||
from listing_filters import (
|
||||
BUY_ALLOWED_BATHROOMS,
|
||||
BUY_MAX_BEDROOMS,
|
||||
BUY_MAX_FLOOR_AREA_SQFT,
|
||||
BUY_MAX_PRICE,
|
||||
BUY_MIN_BEDROOMS,
|
||||
BUY_MIN_FLOOR_AREA_SQFT,
|
||||
matches_strict_buy_listing_filter,
|
||||
)
|
||||
from spatial import PostcodeSpatialIndex
|
||||
from transform import transform_property
|
||||
|
||||
|
|
@ -31,24 +22,6 @@ outcode_cache: dict[str, str] = {}
|
|||
# Requesting index >= 1008 returns HTTP 400.
|
||||
_MAX_INDEX = 1008
|
||||
|
||||
_BASE_BUY_SEARCH_PARAMS = {
|
||||
"propertyTypes": "flat",
|
||||
"minBedrooms": str(BUY_MIN_BEDROOMS),
|
||||
"maxBedrooms": str(BUY_MAX_BEDROOMS),
|
||||
"minBathrooms": str(min(BUY_ALLOWED_BATHROOMS)),
|
||||
"maxBathrooms": str(max(BUY_ALLOWED_BATHROOMS)),
|
||||
"minSize": str(BUY_MIN_FLOOR_AREA_SQFT),
|
||||
"maxSize": str(BUY_MAX_FLOOR_AREA_SQFT),
|
||||
"maxPrice": str(BUY_MAX_PRICE - 1),
|
||||
}
|
||||
|
||||
|
||||
def _buy_search_params(extra_params: dict | None = None) -> dict:
|
||||
params = dict(_BASE_BUY_SEARCH_PARAMS)
|
||||
if extra_params:
|
||||
params.update(extra_params)
|
||||
return params
|
||||
|
||||
|
||||
def resolve_outcode_id(client: httpx.Client, outcode: str) -> str | None:
|
||||
"""Look up Rightmove's internal ID for an outcode via typeahead API."""
|
||||
|
|
@ -77,7 +50,6 @@ def _paginate(
|
|||
outcode: str,
|
||||
channel_cfg: dict,
|
||||
pc_index: PostcodeSpatialIndex,
|
||||
extra_params: dict | None = None,
|
||||
max_properties: int | None = None,
|
||||
) -> tuple[list[dict], int]:
|
||||
"""Paginate through search results. Returns (properties, result_count)."""
|
||||
|
|
@ -94,9 +66,6 @@ def _paginate(
|
|||
"channel": channel_cfg["channel"],
|
||||
"transactionType": channel_cfg["transactionType"],
|
||||
}
|
||||
if extra_params:
|
||||
params.update(extra_params)
|
||||
|
||||
data = fetch_with_retry(client, SEARCH_URL, params)
|
||||
if not data:
|
||||
log.warning(
|
||||
|
|
@ -123,7 +92,7 @@ def _paginate(
|
|||
exc,
|
||||
)
|
||||
continue
|
||||
if transformed and matches_strict_buy_listing_filter(transformed):
|
||||
if transformed:
|
||||
properties.append(transformed)
|
||||
if max_properties is not None and len(properties) >= max_properties:
|
||||
return properties, result_count
|
||||
|
|
@ -137,7 +106,7 @@ def _paginate(
|
|||
break
|
||||
if index >= _MAX_INDEX:
|
||||
log.warning(
|
||||
"%s/%s: %d filtered results exceed Rightmove's %d-result page cap",
|
||||
"%s/%s: %d results exceed Rightmove's %d-result page cap",
|
||||
outcode,
|
||||
channel_cfg["channel"],
|
||||
result_count,
|
||||
|
|
@ -158,18 +127,13 @@ def search_outcode(
|
|||
pc_index: PostcodeSpatialIndex,
|
||||
max_properties: int | None = None,
|
||||
) -> list[dict]:
|
||||
"""Paginate through search results for one outcode+channel. Returns transformed properties.
|
||||
|
||||
Search requests set the supported Rightmove filters directly: flats,
|
||||
2-5 bedrooms, 2-3 bathrooms, 969-1830 sq ft, and asking price below £1m.
|
||||
"""
|
||||
"""Paginate through unfiltered sale results for one outcode+channel."""
|
||||
properties, _ = _paginate(
|
||||
client,
|
||||
outcode_id,
|
||||
outcode,
|
||||
channel_cfg,
|
||||
pc_index,
|
||||
extra_params=_buy_search_params(),
|
||||
max_properties=max_properties,
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue