extract common listing filtering options into a decorator to enable reuse between commands
This commit is contained in:
parent
c543be7ff6
commit
a23a5ae192
1 changed files with 64 additions and 51 deletions
|
|
@ -11,6 +11,8 @@ import csv_exporter
|
||||||
from rec.query import ListingType, FurnishType
|
from rec.query import ListingType, FurnishType
|
||||||
from rec.routing import API_KEY_ENVIRONMENT_VARIABLE, TravelMode
|
from rec.routing import API_KEY_ENVIRONMENT_VARIABLE, TravelMode
|
||||||
from ui_exporter import export_immoweb as export_immoweb_ui
|
from ui_exporter import export_immoweb as export_immoweb_ui
|
||||||
|
from functools import wraps
|
||||||
|
|
||||||
|
|
||||||
dump_listings_module = importlib.import_module("1_dump_listings")
|
dump_listings_module = importlib.import_module("1_dump_listings")
|
||||||
dump_detail_module = importlib.import_module("2_dump_detail")
|
dump_detail_module = importlib.import_module("2_dump_detail")
|
||||||
|
|
@ -19,26 +21,9 @@ detect_floorplan_module = importlib.import_module("4_detect_floorplan")
|
||||||
routing_module = importlib.import_module("5_routing")
|
routing_module = importlib.import_module("5_routing")
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
def listing_filter_options(func):
|
||||||
@click.option(
|
"""Decorator to add common options for filtering listings."""
|
||||||
"--data-dir",
|
|
||||||
default=pathlib.Path("data/rs/"),
|
|
||||||
help="Districts to scrape",
|
|
||||||
type=click.Path(
|
|
||||||
writable=True,
|
|
||||||
file_okay=False,
|
|
||||||
dir_okay=True,
|
|
||||||
resolve_path=True,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
@click.pass_context
|
|
||||||
def cli(ctx, data_dir: str):
|
|
||||||
ctx.ensure_object(dict)
|
|
||||||
ctx.obj["data_dir"] = data_dir
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
|
||||||
@click.option(
|
@click.option(
|
||||||
"--type",
|
"--type",
|
||||||
"-t",
|
"-t",
|
||||||
|
|
@ -90,6 +75,34 @@ def cli(ctx, data_dir: str):
|
||||||
),
|
),
|
||||||
multiple=True,
|
multiple=True,
|
||||||
)
|
)
|
||||||
|
@wraps(func)
|
||||||
|
def wrapper(*args, **kwargs):
|
||||||
|
return func(*args, **kwargs)
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
@click.group()
|
||||||
|
@click.option(
|
||||||
|
"--data-dir",
|
||||||
|
default=pathlib.Path("data/rs/"),
|
||||||
|
help="Districts to scrape",
|
||||||
|
type=click.Path(
|
||||||
|
writable=True,
|
||||||
|
file_okay=False,
|
||||||
|
dir_okay=True,
|
||||||
|
resolve_path=True,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
@click.pass_context
|
||||||
|
def cli(ctx, data_dir: str):
|
||||||
|
ctx.ensure_object(dict)
|
||||||
|
ctx.obj["data_dir"] = data_dir
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command()
|
||||||
|
@listing_filter_options
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def dump_listings(
|
def dump_listings(
|
||||||
ctx: click.core.Context,
|
ctx: click.core.Context,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue