Fix buy listing support: thread ListingType through processing pipeline
The listing processor was hardcoded to create RentListing objects and query only the rentlisting table. Buy listings fetched from Rightmove were stored in the wrong table with missing fields. This threads ListingType through ListingProcessor and all Step subclasses so the correct model (RentListing/BuyListing) is created, the correct table is queried, and buy-specific fields (service_charge, lease_left) are parsed from the API response and included in GeoJSON streaming output.
This commit is contained in:
parent
5e48a26958
commit
e5ce8c1201
6 changed files with 116 additions and 41 deletions
|
|
@ -53,9 +53,7 @@ def convert_row_to_geojson(row: dict[str, Any], listing_type: str = "RENT") -> d
|
|||
else:
|
||||
last_seen_str = str(last_seen_val)
|
||||
|
||||
return {
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
properties: dict[str, Any] = {
|
||||
"listing_type": listing_type,
|
||||
"city": "London",
|
||||
"country": "United Kingdom",
|
||||
|
|
@ -69,7 +67,16 @@ def convert_row_to_geojson(row: dict[str, Any], listing_type: str = "RENT") -> d
|
|||
"price_history": price_history,
|
||||
"agency": row.get('agency'),
|
||||
"available_from": available_from_str,
|
||||
},
|
||||
}
|
||||
|
||||
if row.get('service_charge') is not None:
|
||||
properties["service_charge"] = row['service_charge']
|
||||
if row.get('lease_left') is not None:
|
||||
properties["lease_left"] = row['lease_left']
|
||||
|
||||
return {
|
||||
"type": "Feature",
|
||||
"properties": properties,
|
||||
"geometry": {
|
||||
"coordinates": [row['longitude'], row['latitude']],
|
||||
"type": "Point",
|
||||
|
|
@ -90,9 +97,7 @@ def convert_to_geojson_feature(listing: RentListing | BuyListing) -> dict[str, A
|
|||
property_info = listing.additional_info.get("property", {}) if listing.additional_info else {}
|
||||
listing_type = "RENT" if isinstance(listing, RentListing) else "BUY"
|
||||
|
||||
return {
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
properties: dict[str, Any] = {
|
||||
"listing_type": listing_type,
|
||||
"city": "London", # change me
|
||||
"country": "United Kingdom",
|
||||
|
|
@ -106,7 +111,17 @@ def convert_to_geojson_feature(listing: RentListing | BuyListing) -> dict[str, A
|
|||
"price_history": [item.to_dict() for item in listing.price_history],
|
||||
"agency": listing.agency,
|
||||
"available_from": property_info.get("letDateAvailable", None),
|
||||
},
|
||||
}
|
||||
|
||||
if isinstance(listing, BuyListing):
|
||||
if listing.service_charge is not None:
|
||||
properties["service_charge"] = listing.service_charge
|
||||
if listing.lease_left is not None:
|
||||
properties["lease_left"] = listing.lease_left
|
||||
|
||||
return {
|
||||
"type": "Feature",
|
||||
"properties": properties,
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
listing.longitude,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue