Skip to content

Commit

Permalink
- pending or contingent support
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacharyHampton committed Oct 5, 2023
1 parent de692fa commit 8a5f0dc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
3 changes: 3 additions & 0 deletions homeharvest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand All @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions homeharvest/core/scrapers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -37,6 +38,7 @@ def __init__(
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]:
...
Expand Down
10 changes: 7 additions & 3 deletions homeharvest/core/scrapers/realtor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,9 @@ def general_search(
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!
Expand All @@ -352,7 +354,7 @@ def general_search(
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],
Expand All @@ -368,17 +370,19 @@ def general_search(
state_code: $state_code
status: %s
%s
%s
}
%s
limit: 200
offset: $offset
) %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]!
Expand Down
15 changes: 15 additions & 0 deletions tests/test_realtor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@
)


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",
Expand Down

0 comments on commit 8a5f0dc

Please sign in to comment.