From 05713c76b0f9c7204881ce1bc1ecc02418fa5a42 Mon Sep 17 00:00:00 2001 From: Zachary Hampton <69336300+ZacharyHampton@users.noreply.github.com> Date: Thu, 21 Sep 2023 11:27:12 -0700 Subject: [PATCH] - redfin bug fix - .get --- homeharvest/core/scrapers/redfin/__init__.py | 4 ++-- homeharvest/core/scrapers/zillow/__init__.py | 16 ++++++++-------- pyproject.toml | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/homeharvest/core/scrapers/redfin/__init__.py b/homeharvest/core/scrapers/redfin/__init__.py index 9fa8a44..e182c3a 100644 --- a/homeharvest/core/scrapers/redfin/__init__.py +++ b/homeharvest/core/scrapers/redfin/__init__.py @@ -93,7 +93,7 @@ class RedfinScraper(Scraper): year_built=get_value("yearBuilt") if not single_search else home["yearBuilt"], lot_area_value=lot_size, property_type=PropertyType.from_int_code(home.get("propertyType")), - price_per_sqft=get_value("pricePerSqFt"), + price_per_sqft=get_value("pricePerSqFt") if type(home.get("pricePerSqFt")) != int else home.get("pricePerSqFt"), mls_id=get_value("mlsId"), latitude=home["latLong"]["latitude"] if "latLong" in home and "latitude" in home["latLong"] else None, longitude=home["latLong"]["longitude"] if "latLong" in home and "longitude" in home["latLong"] else None, @@ -183,7 +183,7 @@ class RedfinScraper(Scraper): ), property_url="https://www.redfin.com{}".format(building["url"]), listing_type=self.listing_type, - unit_count=building["numUnitsForSale"], + unit_count=building.get("numUnitsForSale"), ) def handle_address(self, home_id: str): diff --git a/homeharvest/core/scrapers/zillow/__init__.py b/homeharvest/core/scrapers/zillow/__init__.py index fc3e8c9..b37017f 100644 --- a/homeharvest/core/scrapers/zillow/__init__.py +++ b/homeharvest/core/scrapers/zillow/__init__.py @@ -147,18 +147,18 @@ class ZillowScraper(Scraper): if "hdpData" in result: home_info = result["hdpData"]["homeInfo"] address_data = { - "address_one": parse_address_one(home_info["streetAddress"])[0], + "address_one": parse_address_one(home_info.get("streetAddress"))[0], "address_two": parse_address_two(home_info["unit"]) if "unit" in home_info else "#", - "city": home_info["city"], - "state": home_info["state"], - "zip_code": home_info["zipcode"], + "city": home_info.get("city"), + "state": home_info.get("state"), + "zip_code": home_info.get("zipcode"), } property_obj = Property( site_name=self.site_name, address=Address(**address_data), property_url=f"https://www.zillow.com{result['detailUrl']}", tax_assessed_value=int(home_info["taxAssessedValue"]) if "taxAssessedValue" in home_info else None, - property_type=PropertyType(home_info["homeType"]), + property_type=PropertyType(home_info.get("homeType")), listing_type=ListingType( home_info["statusType"] if "statusType" in home_info else self.listing_type ), @@ -203,9 +203,9 @@ class ZillowScraper(Scraper): baths_min=result.get("minBaths"), area_min=result.get("minArea"), bldg_name=result.get("communityName"), - status_text=result["statusText"], - price_min=price_value if "+/mo" in result["price"] else None, - price_max=price_value if "+/mo" in result["price"] else None, + status_text=result.get("statusText"), + price_min=price_value if "+/mo" in result.get("price") else None, + price_max=price_value if "+/mo" in result.get("price") else None, latitude=result.get("latLong", {}).get("latitude"), longitude=result.get("latLong", {}).get("longitude"), unit_count=result.get("unitCount"), diff --git a/pyproject.toml b/pyproject.toml index 326a8ab..01ad8f8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "homeharvest" -version = "0.2.11" +version = "0.2.12" description = "Real estate scraping library supporting Zillow, Realtor.com & Redfin." authors = ["Zachary Hampton ", "Cullen Watson "] homepage = "https://github.com/ZacharyHampton/HomeHarvest"