From 8a5f0dc2c95c2f102508053a2d7bdaa45709d9d8 Mon Sep 17 00:00:00 2001 From: Zachary Hampton <69336300+ZacharyHampton@users.noreply.github.com> Date: Wed, 4 Oct 2023 18:25:01 -0700 Subject: [PATCH] - pending or contingent support --- homeharvest/__init__.py | 3 +++ homeharvest/core/scrapers/__init__.py | 2 ++ homeharvest/core/scrapers/realtor/__init__.py | 10 +++++++--- tests/test_realtor.py | 15 +++++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/homeharvest/__init__.py b/homeharvest/__init__.py index cec1687..63aa13f 100644 --- a/homeharvest/__init__.py +++ b/homeharvest/__init__.py @@ -13,6 +13,7 @@ def scrape_property( radius: float = None, mls_only: bool = False, property_younger_than: int = None, + pending_or_contingent: bool = False, proxy: str = None, ) -> pd.DataFrame: """ @@ -22,6 +23,7 @@ def scrape_property( :param radius: Get properties within _ (e.g. 1.0) miles. Only applicable for individual addresses. :param mls_only: If set, fetches only listings with MLS IDs. :param property_younger_than: Get properties sold/listed in last _ days. + :param pending_or_contingent: If set, fetches only pending or contingent listings. Only applicable for for_sale listings from general area searches. :param proxy: Proxy to use for scraping """ validate_input(listing_type) @@ -33,6 +35,7 @@ def scrape_property( radius=radius, mls_only=mls_only, last_x_days=property_younger_than, + pending_or_contingent=pending_or_contingent, ) site = RealtorScraper(scraper_input) diff --git a/homeharvest/core/scrapers/__init__.py b/homeharvest/core/scrapers/__init__.py index 1ce4431..f82b321 100644 --- a/homeharvest/core/scrapers/__init__.py +++ b/homeharvest/core/scrapers/__init__.py @@ -12,6 +12,7 @@ class ScraperInput: mls_only: bool | None = None proxy: str | None = None last_x_days: int | None = None + pending_or_contingent: bool | None = None class Scraper: @@ -37,6 +38,7 @@ class Scraper: self.radius = scraper_input.radius self.last_x_days = scraper_input.last_x_days self.mls_only = scraper_input.mls_only + self.pending_or_contingent = scraper_input.pending_or_contingent def search(self) -> list[Property]: ... diff --git a/homeharvest/core/scrapers/realtor/__init__.py b/homeharvest/core/scrapers/realtor/__init__.py index cc2382a..f0e47c2 100644 --- a/homeharvest/core/scrapers/realtor/__init__.py +++ b/homeharvest/core/scrapers/realtor/__init__.py @@ -328,7 +328,9 @@ class RealtorScraper(Scraper): else "sort: [{ field: list_date, direction: desc }]" ) - if search_type == "comps": + pending_or_contingent_param = "or_filters: { contingent: true, pending: true }" if self.pending_or_contingent else "" + + if search_type == "comps": #: comps search, came from an address query = """query Property_search( $coordinates: [Float]! $radius: String! @@ -352,7 +354,7 @@ class RealtorScraper(Scraper): sort_param, results_query, ) - elif search_type == "area": + elif search_type == "area": #: general search, came from a general location query = """query Home_search( $city: String, $county: [String], @@ -368,6 +370,7 @@ class RealtorScraper(Scraper): state_code: $state_code status: %s %s + %s } %s limit: 200 @@ -375,10 +378,11 @@ class RealtorScraper(Scraper): ) %s""" % ( self.listing_type.value.lower(), date_param, + pending_or_contingent_param, sort_param, results_query, ) - else: + else: #: general search, came from an address query = ( """query Property_search( $property_id: [ID]! diff --git a/tests/test_realtor.py b/tests/test_realtor.py index 43af136..a498112 100644 --- a/tests/test_realtor.py +++ b/tests/test_realtor.py @@ -5,6 +5,21 @@ from homeharvest.exceptions import ( ) +def test_realtor_pending_or_contingent(): + pending_or_contingent_result = scrape_property( + location="Surprise, AZ", + pending_or_contingent=True, + ) + + regular_result = scrape_property( + location="Surprise, AZ", + pending_or_contingent=False, + ) + + assert all([result is not None for result in [pending_or_contingent_result, regular_result]]) + assert len(pending_or_contingent_result) != len(regular_result) + + def test_realtor_comps(): result = scrape_property( location="2530 Al Lipscomb Way",