- redfin buildings support

pull/1/head
Zachary Hampton 2023-09-18 08:26:35 -07:00
parent ba9fe806a7
commit ba249ca20d
2 changed files with 34 additions and 3 deletions

View File

@ -71,7 +71,7 @@ def process_result(result: Union[Building, Property]) -> pd.DataFrame:
address_data = prop_data["address"] address_data = prop_data["address"]
prop_data["site_name"] = prop_data["site_name"] prop_data["site_name"] = prop_data["site_name"]
prop_data["listing_type"] = prop_data["listing_type"].value prop_data["listing_type"] = prop_data["listing_type"].value
prop_data["property_type"] = prop_data["property_type"].value.lower() if prop_data["property_type"] else None prop_data["property_type"] = prop_data["property_type"].value.lower() if prop_data.get("property_type") else None
prop_data["address_one"] = address_data.address_one prop_data["address_one"] = address_data.address_one
prop_data["city"] = address_data.city prop_data["city"] = address_data.city
prop_data["state"] = address_data.state prop_data["state"] = address_data.state

View File

@ -1,5 +1,5 @@
import json import json
from ..models import Property, Address, PropertyType from ..models import Property, Address, PropertyType, Building
from .. import Scraper from .. import Scraper
from typing import Any from typing import Any
@ -86,6 +86,34 @@ class RedfinScraper(Scraper):
mls_id=get_value("mlsId"), mls_id=get_value("mlsId"),
) )
def _parse_building(self, building: dict) -> Building:
return Building(
address=Address(
address_one=" ".join(
[
building['address']['streetNumber'],
building['address']['directionalPrefix'],
building['address']['streetName'],
building['address']['streetType'],
]
),
city=building['address']['city'],
state=building['address']['stateOrProvinceCode'],
zip_code=building['address']['postalCode'],
address_two=" ".join(
[
building['address']['unitType'],
building['address']['unitValue'],
]
)
),
site_name=self.site_name,
url="https://www.redfin.com{}".format(building["url"]),
listing_type=self.listing_type,
num_units=building["numUnitsForSale"],
)
def handle_address(self, home_id: str): def handle_address(self, home_id: str):
""" """
EPs: EPs:
@ -123,5 +151,8 @@ class RedfinScraper(Scraper):
homes = [ homes = [
self._parse_home(home) for home in response_json["payload"]["homes"] self._parse_home(home) for home in response_json["payload"]["homes"]
] #: support buildings ] + [
self._parse_building(building) for building in response_json["payload"]["buildings"].values()
]
return homes return homes