add option to filter for min sqm per listing
This commit is contained in:
parent
1c77c78518
commit
0acd417d34
3 changed files with 16 additions and 2 deletions
|
|
@ -158,7 +158,7 @@ class Listing:
|
||||||
json.dump(objs, f)
|
json.dump(objs, f)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def sqm_model(self, recalculate=True):
|
def sqm_model(self, recalculate=True) -> float:
|
||||||
if not self.path_floorplan_model_json().exists() or recalculate:
|
if not self.path_floorplan_model_json().exists() or recalculate:
|
||||||
self.calculate_sqm_model()
|
self.calculate_sqm_model()
|
||||||
|
|
||||||
|
|
@ -193,7 +193,7 @@ class Listing:
|
||||||
with open(self.path_floorplan_ocr_json(), "w") as f:
|
with open(self.path_floorplan_ocr_json(), "w") as f:
|
||||||
json.dump(objs, f)
|
json.dump(objs, f)
|
||||||
|
|
||||||
async def sqm_ocr(self, recalculate=False):
|
async def sqm_ocr(self, recalculate=False) -> float | None:
|
||||||
if not self.path_floorplan_ocr_json().exists() or recalculate:
|
if not self.path_floorplan_ocr_json().exists() or recalculate:
|
||||||
await self.calculate_sqm_ocr()
|
await self.calculate_sqm_ocr()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,12 @@ def listing_filter_options(func):
|
||||||
default=14,
|
default=14,
|
||||||
type=int,
|
type=int,
|
||||||
)
|
)
|
||||||
|
@click.option(
|
||||||
|
"--min-sqm",
|
||||||
|
help="Minimum square meters for the listing",
|
||||||
|
default=None,
|
||||||
|
type=int,
|
||||||
|
)
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
|
|
@ -128,6 +134,7 @@ def dump_listings(
|
||||||
furnish_types: list[str],
|
furnish_types: list[str],
|
||||||
available_from: datetime | None,
|
available_from: datetime | None,
|
||||||
last_seen_days: int,
|
last_seen_days: int,
|
||||||
|
min_sqm: int | None = None,
|
||||||
):
|
):
|
||||||
data_dir: str = ctx.obj["data_dir"]
|
data_dir: str = ctx.obj["data_dir"]
|
||||||
query_parameters = QueryParameters(
|
query_parameters = QueryParameters(
|
||||||
|
|
@ -140,6 +147,7 @@ def dump_listings(
|
||||||
furnish_types=[FurnishType[furnish_type] for furnish_type in furnish_types],
|
furnish_types=[FurnishType[furnish_type] for furnish_type in furnish_types],
|
||||||
let_date_available_from=available_from,
|
let_date_available_from=available_from,
|
||||||
last_seen_days=last_seen_days,
|
last_seen_days=last_seen_days,
|
||||||
|
min_sqm=min_sqm,
|
||||||
)
|
)
|
||||||
click.echo(
|
click.echo(
|
||||||
f"Running dump_listings for districts {district}, data dir {data_dir} and parameters: "
|
f"Running dump_listings for districts {district}, data dir {data_dir} and parameters: "
|
||||||
|
|
@ -288,6 +296,7 @@ def export_immoweb(
|
||||||
furnish_types: list[str],
|
furnish_types: list[str],
|
||||||
available_from: datetime | None,
|
available_from: datetime | None,
|
||||||
last_seen_days: int,
|
last_seen_days: int,
|
||||||
|
min_sqm: int | None = None,
|
||||||
):
|
):
|
||||||
query_parameters = QueryParameters(
|
query_parameters = QueryParameters(
|
||||||
listing_type=ListingType[type],
|
listing_type=ListingType[type],
|
||||||
|
|
@ -299,6 +308,7 @@ def export_immoweb(
|
||||||
furnish_types=[FurnishType[furnish_type] for furnish_type in furnish_types],
|
furnish_types=[FurnishType[furnish_type] for furnish_type in furnish_types],
|
||||||
let_date_available_from=available_from,
|
let_date_available_from=available_from,
|
||||||
last_seen_days=last_seen_days,
|
last_seen_days=last_seen_days,
|
||||||
|
min_sqm=min_sqm,
|
||||||
)
|
)
|
||||||
click.echo(
|
click.echo(
|
||||||
f"Exporting data to {output_file} that matches the query parameters: {query_parameters}"
|
f"Exporting data to {output_file} that matches the query parameters: {query_parameters}"
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ class QueryParameters:
|
||||||
# available from; council tax
|
# available from; council tax
|
||||||
let_date_available_from: datetime | None = None
|
let_date_available_from: datetime | None = None
|
||||||
last_seen_days: int | None = None
|
last_seen_days: int | None = None
|
||||||
|
min_sqm: int | None = None
|
||||||
|
|
||||||
|
|
||||||
async def filter_listings(
|
async def filter_listings(
|
||||||
|
|
@ -68,6 +69,9 @@ async def filter_listings(
|
||||||
and listing.letDateAvailable < query_parameters.let_date_available_from
|
and listing.letDateAvailable < query_parameters.let_date_available_from
|
||||||
):
|
):
|
||||||
continue
|
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)
|
filtered_listings.append(listing)
|
||||||
|
|
||||||
return filtered_listings
|
return filtered_listings
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue