add api endpoint for geojson data fetching
This commit is contained in:
parent
7602c3762b
commit
b995bc2286
2 changed files with 18 additions and 6 deletions
|
|
@ -7,13 +7,13 @@ from repositories.listing_repository import ListingRepository
|
|||
|
||||
async def export_immoweb(
|
||||
repository: ListingRepository,
|
||||
output_file: str,
|
||||
output_file: str | None = None,
|
||||
query_parameters: QueryParameters | None = None,
|
||||
limit: int | None = None,
|
||||
):
|
||||
output_file_path = pathlib.Path(output_file)
|
||||
output_file_path.touch(exist_ok=True)
|
||||
listings = await repository.get_listings(
|
||||
query_parameters=query_parameters,
|
||||
limit=limit,
|
||||
)
|
||||
|
||||
# Convert listings to immoweb format
|
||||
|
|
@ -53,6 +53,10 @@ async def export_immoweb(
|
|||
prefix = "var data = "
|
||||
serialized_data = {"type": "FeatureCollection", "features": immoweb_listings}
|
||||
result = prefix + json.dumps(serialized_data, indent=4)
|
||||
with open(str(output_file_path), "w") as f:
|
||||
f.write(result)
|
||||
# json.dump(serialized_data, f, indent=4)
|
||||
|
||||
if output_file:
|
||||
output_file_path = pathlib.Path(output_file)
|
||||
output_file_path.touch(exist_ok=True)
|
||||
with open(str(output_file_path), "w") as f:
|
||||
f.write(result)
|
||||
return serialized_data
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue