mirror of
https://github.com/Bunsly/HomeHarvest.git
synced 2026-03-04 19:44:29 -08:00
refactor: scrape_property()
This commit is contained in:
@@ -17,9 +17,11 @@ class ListingType(Enum):
|
||||
class PropertyType(Enum):
|
||||
HOUSE = "HOUSE"
|
||||
CONDO = "CONDO"
|
||||
TOWNHOUSE = "townhousE"
|
||||
TOWNHOUSE = "TOWNHOUSE"
|
||||
SINGLE_FAMILY = "SINGLE_FAMILY"
|
||||
MULTI_FAMILY = "MULTI_FAMILY"
|
||||
MANUFACTURED = "MANUFACTURED"
|
||||
APARTMENT = "APARTMENT"
|
||||
LAND = "LAND"
|
||||
OTHER = "OTHER"
|
||||
|
||||
|
||||
@@ -55,6 +55,15 @@ class RedfinScraper(Scraper):
|
||||
)
|
||||
url = "https://www.redfin.com{}".format(home["url"])
|
||||
property_type = home["propertyType"] if "propertyType" in home else None
|
||||
lot_size_data = home.get("lotSize")
|
||||
if not isinstance(lot_size_data, int):
|
||||
lot_size = (
|
||||
lot_size_data.get("value", None)
|
||||
if isinstance(lot_size_data, dict)
|
||||
else None
|
||||
)
|
||||
else:
|
||||
lot_size = lot_size_data
|
||||
|
||||
return Property(
|
||||
site_name=self.site_name,
|
||||
@@ -70,7 +79,7 @@ class RedfinScraper(Scraper):
|
||||
if not single_search
|
||||
else home["yearBuilt"],
|
||||
square_feet=get_value("sqFt"),
|
||||
lot_size=home.get("lotSize", {}).get("value", None),
|
||||
lot_size=lot_size,
|
||||
property_type=PropertyType.from_int_code(home.get("propertyType")),
|
||||
price_per_square_foot=get_value("pricePerSqFt"),
|
||||
price=get_value("price"),
|
||||
|
||||
@@ -97,7 +97,9 @@ class ZillowScraper(Scraper):
|
||||
else property_data["hdpUrl"]
|
||||
)
|
||||
address_data = property_data["address"]
|
||||
address_one, address_two = cls._parse_address_two(address_data["streetAddress"])
|
||||
address_one, address_two = self._parse_address_two(
|
||||
address_data["streetAddress"]
|
||||
)
|
||||
address = Address(
|
||||
address_one=address_one,
|
||||
address_two=address_two,
|
||||
@@ -106,7 +108,6 @@ class ZillowScraper(Scraper):
|
||||
zip_code=address_data["zipcode"],
|
||||
)
|
||||
property_type = property_data.get("homeType", None)
|
||||
print(property_type)
|
||||
|
||||
return Property(
|
||||
site_name=self.site_name,
|
||||
|
||||
Reference in New Issue
Block a user