add command to export the data in a way that the ui (immoweb) can consume
This commit is contained in:
parent
102c20ac42
commit
7e8c79d3d1
4 changed files with 66 additions and 3 deletions
43
crawler/ui_exporter.py
Normal file
43
crawler/ui_exporter.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
|
||||
import json
|
||||
import pathlib
|
||||
|
||||
from data_access import Listing
|
||||
|
||||
|
||||
async def export_immoweb(ctx, output_file: str):
|
||||
data_dir = ctx.obj['data_dir']
|
||||
output_file_path = pathlib.Path(output_file)
|
||||
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])
|
||||
|
||||
# Convert listings to immoweb format
|
||||
immoweb_listings = []
|
||||
for listing in listings:
|
||||
immoweb_listing = {
|
||||
'type': 'Feature',
|
||||
'properties': {
|
||||
'city': 'London', # change me
|
||||
'country': 'United Kingdom',
|
||||
'qm': await listing.sqm_ocr(),
|
||||
'qmprice': await listing.price_per_sqm(),
|
||||
'rooms': listing.bedrooms,
|
||||
'total_price': listing.price,
|
||||
},
|
||||
'geometry': {
|
||||
'coordinates': [
|
||||
listing.longitude,
|
||||
listing.latitude,
|
||||
],
|
||||
'type': 'Point',
|
||||
}
|
||||
}
|
||||
immoweb_listings.append(immoweb_listing)
|
||||
|
||||
prefix = 'var data = '
|
||||
serialized_data = {"type": "FeatureCollection", "features": immoweb_listings}
|
||||
result = prefix + json.dumps(serialized_data, indent=4)
|
||||
with open(output_file_path, 'w') as f:
|
||||
f.write(result)
|
||||
# json.dump(serialized_data, f, indent=4)
|
||||
Loading…
Add table
Add a link
Reference in a new issue