From 011680f7d813262f15ef61ec39895053cea89aa4 Mon Sep 17 00:00:00 2001 From: Zachary Hampton <69336300+ZacharyHampton@users.noreply.github.com> Date: Thu, 6 Jun 2024 15:24:12 -0700 Subject: [PATCH] - style error bug fix --- homeharvest/utils.py | 27 ++++++++++++++------------- pyproject.toml | 2 +- tests/test_realtor.py | 10 ++++++++++ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/homeharvest/utils.py b/homeharvest/utils.py index cbd8993..46b75f4 100644 --- a/homeharvest/utils.py +++ b/homeharvest/utils.py @@ -83,19 +83,20 @@ def process_result(result: Property) -> pd.DataFrame: prop_data["nearby_schools"] = ", ".join(set(prop_data["nearby_schools"])) if prop_data["nearby_schools"] else None description = result.description - prop_data["primary_photo"] = description.primary_photo - prop_data["alt_photos"] = ", ".join(description.alt_photos) if description.alt_photos else None - prop_data["style"] = description.style if type(description.style) == str else description.style.value - prop_data["beds"] = description.beds - prop_data["full_baths"] = description.baths_full - prop_data["half_baths"] = description.baths_half - prop_data["sqft"] = description.sqft - prop_data["lot_sqft"] = description.lot_sqft - prop_data["sold_price"] = description.sold_price - prop_data["year_built"] = description.year_built - prop_data["parking_garage"] = description.garage - prop_data["stories"] = description.stories - prop_data["text"] = description.text + if description: + prop_data["primary_photo"] = description.primary_photo + prop_data["alt_photos"] = ", ".join(description.alt_photos) if description.alt_photos else None + prop_data["style"] = description.style if isinstance(description.style, str) else description.style.value if description.style else None + prop_data["beds"] = description.beds + prop_data["full_baths"] = description.baths_full + prop_data["half_baths"] = description.baths_half + prop_data["sqft"] = description.sqft + prop_data["lot_sqft"] = description.lot_sqft + prop_data["sold_price"] = description.sold_price + prop_data["year_built"] = description.year_built + prop_data["parking_garage"] = description.garage + prop_data["stories"] = description.stories + prop_data["text"] = description.text properties_df = pd.DataFrame([prop_data]) properties_df = properties_df.reindex(columns=ordered_properties) diff --git a/pyproject.toml b/pyproject.toml index cd5aa16..bacda4c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "homeharvest" -version = "0.3.29" +version = "0.3.30" description = "Real estate scraping library" authors = ["Zachary Hampton ", "Cullen Watson "] homepage = "https://github.com/Bunsly/HomeHarvest" diff --git a/tests/test_realtor.py b/tests/test_realtor.py index e88271b..ca6207a 100644 --- a/tests/test_realtor.py +++ b/tests/test_realtor.py @@ -175,3 +175,13 @@ def test_exclude_pending(): ) assert results is not None and len(results) > 0 + + +def test_style_value_error(): + results = scrape_property( + location="Alaska, AK", + listing_type="sold", + extra_property_data=False, + ) + + assert results is not None and len(results) > 0 \ No newline at end of file