- pending or contingent support

pull/31/head
Zachary Hampton 2023-10-04 18:25:01 -07:00
parent de692faae2
commit 8a5f0dc2c9
4 changed files with 27 additions and 3 deletions

View File

@ -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)

View File

@ -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]:
...

View File

@ -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]!

View File

@ -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",