Skip to content

Commit

Permalink
- redfin buildings support
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacharyHampton committed Sep 18, 2023
1 parent ba9fe80 commit ba249ca
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion homeharvest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def process_result(result: Union[Building, Property]) -> pd.DataFrame:
address_data = prop_data["address"]
prop_data["site_name"] = prop_data["site_name"]
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["city"] = address_data.city
prop_data["state"] = address_data.state
Expand Down
35 changes: 33 additions & 2 deletions homeharvest/core/scrapers/redfin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from ..models import Property, Address, PropertyType
from ..models import Property, Address, PropertyType, Building
from .. import Scraper
from typing import Any

Expand Down Expand Up @@ -86,6 +86,34 @@ def get_value(key: str) -> Any | None:
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):
"""
EPs:
Expand Down Expand Up @@ -123,5 +151,8 @@ def search(self):

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

0 comments on commit ba249ca

Please sign in to comment.