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,4 +1,5 @@
|
|||
import asyncio
|
||||
from datetime import datetime
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
|
|
@ -8,7 +9,7 @@ import importlib
|
|||
from rec.districts import get_districts
|
||||
from data_access import Listing
|
||||
import csv_exporter
|
||||
from rec.query import ListingType, FurnishType
|
||||
from rec.query import ListingType, FurnishType, QueryParameters
|
||||
from rec.routing import API_KEY_ENVIRONMENT_VARIABLE, TravelMode
|
||||
from ui_exporter import export_immoweb as export_immoweb_ui
|
||||
from functools import wraps
|
||||
|
|
@ -75,6 +76,12 @@ def listing_filter_options(func):
|
|||
),
|
||||
multiple=True,
|
||||
)
|
||||
@click.option(
|
||||
"--available-from",
|
||||
help="Let date available from",
|
||||
default=None,
|
||||
type=click.DateTime(),
|
||||
)
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
return func(*args, **kwargs)
|
||||
|
|
@ -113,9 +120,10 @@ def dump_listings(
|
|||
max_price: int,
|
||||
type: str,
|
||||
furnish_types: list[str],
|
||||
available_from: datetime | None,
|
||||
):
|
||||
data_dir: str = ctx.obj["data_dir"]
|
||||
query_parameters = dump_listings_module.QueryParameters(
|
||||
query_parameters = QueryParameters(
|
||||
listing_type=ListingType[type],
|
||||
district_names=set(district),
|
||||
min_bedrooms=min_bedrooms,
|
||||
|
|
@ -123,6 +131,7 @@ def dump_listings(
|
|||
min_price=min_price,
|
||||
max_price=max_price,
|
||||
furnish_types=[FurnishType[furnish_type] for furnish_type in furnish_types],
|
||||
let_date_available_from=available_from,
|
||||
)
|
||||
click.echo(
|
||||
f"Running dump_listings for districts {district}, data dir {data_dir} and parameters: "
|
||||
|
|
@ -257,10 +266,34 @@ def export_csv(ctx: click.core.Context, output_file: str, columns: tuple[str]):
|
|||
resolve_path=True,
|
||||
),
|
||||
)
|
||||
@listing_filter_options
|
||||
@click.pass_context
|
||||
def export_immoweb(ctx, output_file: str):
|
||||
click.echo(f"Exporting data to {output_file}")
|
||||
asyncio.run(export_immoweb_ui(ctx, output_file))
|
||||
def export_immoweb(
|
||||
ctx,
|
||||
output_file: str,
|
||||
district: list[str],
|
||||
min_bedrooms: int,
|
||||
max_bedrooms: int,
|
||||
min_price: int,
|
||||
max_price: int,
|
||||
type: str,
|
||||
furnish_types: list[str],
|
||||
available_from: datetime | None,
|
||||
):
|
||||
query_parameters = QueryParameters(
|
||||
listing_type=ListingType[type],
|
||||
district_names=set(district),
|
||||
min_bedrooms=min_bedrooms,
|
||||
max_bedrooms=max_bedrooms,
|
||||
min_price=min_price,
|
||||
max_price=max_price,
|
||||
furnish_types=[FurnishType[furnish_type] for furnish_type in furnish_types],
|
||||
let_date_available_from=available_from,
|
||||
)
|
||||
click.echo(
|
||||
f"Exporting data to {output_file} that matches the query parameters: {query_parameters}"
|
||||
)
|
||||
asyncio.run(export_immoweb_ui(ctx, output_file, query_parameters))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue