migrate immoweb exporter to use models
This commit is contained in:
parent
e317d2ec54
commit
3785d01009
5 changed files with 94 additions and 22 deletions
|
|
@ -1,23 +1,22 @@
|
|||
import dataclasses
|
||||
import json
|
||||
import pathlib
|
||||
|
||||
from data_access import Listing
|
||||
from rec.query import QueryParameters
|
||||
from repositories.listing_repository import ListingRepository
|
||||
|
||||
|
||||
async def export_immoweb(
|
||||
ctx,
|
||||
repository: ListingRepository,
|
||||
output_file: str,
|
||||
query_parameters: QueryParameters | None = None,
|
||||
):
|
||||
data_dir = ctx.obj["data_dir"]
|
||||
output_file_path = pathlib.Path(output_file)
|
||||
output_file_path.touch(exist_ok=True)
|
||||
listing_paths = sorted(list(pathlib.Path(data_dir).glob("*/listing.json")))
|
||||
# listing_paths = listing_paths[:10]
|
||||
listings = Listing.get_all_listings([str(path) for path in listing_paths])
|
||||
if query_parameters is not None:
|
||||
listings = await filter_listings(listings, query_parameters)
|
||||
listings = await repository.get_listings(
|
||||
query_parameters=query_parameters,
|
||||
)
|
||||
|
||||
# Convert listings to immoweb format
|
||||
immoweb_listings = []
|
||||
|
|
@ -27,18 +26,22 @@ async def export_immoweb(
|
|||
"properties": {
|
||||
"city": "London", # change me
|
||||
"country": "United Kingdom",
|
||||
"qm": await listing.sqm_ocr(),
|
||||
"qmprice": round(await listing.price_per_sqm(), 2),
|
||||
"rooms": listing.bedrooms,
|
||||
"qm": listing.square_meters,
|
||||
"qmprice": listing.price_per_square_meter,
|
||||
"rooms": listing.number_of_bedrooms,
|
||||
"total_price": listing.price,
|
||||
"url": listing.url,
|
||||
"photo_thumbnail": listing.photo_thumbnail,
|
||||
"last_seen": listing.last_seen.isoformat(),
|
||||
"price_history": [item.to_dict() for item in listing.price_history],
|
||||
"agency": listing.agency,
|
||||
# Additional info; the above is GeoJSON format
|
||||
# Below is all other crap we want in the UI
|
||||
"info": await listing.dict_nicely(),
|
||||
"info": listing.additional_info,
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
listing.longitude,
|
||||
listing.longtitude,
|
||||
listing.latitude,
|
||||
],
|
||||
"type": "Point",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue