added foreclose parameter
parent
03198428de
commit
6d987e8fc2
|
@ -15,6 +15,7 @@ def scrape_property(
|
||||||
proxy: str = None,
|
proxy: str = None,
|
||||||
date_from: str = None,
|
date_from: str = None,
|
||||||
date_to: str = None,
|
date_to: str = None,
|
||||||
|
foreclosure: bool = None,
|
||||||
) -> pd.DataFrame:
|
) -> pd.DataFrame:
|
||||||
"""
|
"""
|
||||||
Scrape properties from Realtor.com based on a given location and listing type.
|
Scrape properties from Realtor.com based on a given location and listing type.
|
||||||
|
@ -38,6 +39,7 @@ def scrape_property(
|
||||||
last_x_days=past_days,
|
last_x_days=past_days,
|
||||||
date_from=date_from,
|
date_from=date_from,
|
||||||
date_to=date_to,
|
date_to=date_to,
|
||||||
|
foreclosure=foreclosure,
|
||||||
)
|
)
|
||||||
|
|
||||||
site = RealtorScraper(scraper_input)
|
site = RealtorScraper(scraper_input)
|
||||||
|
|
|
@ -13,6 +13,7 @@ class ScraperInput:
|
||||||
last_x_days: int | None = None
|
last_x_days: int | None = None
|
||||||
date_from: str | None = None
|
date_from: str | None = None
|
||||||
date_to: str | None = None
|
date_to: str | None = None
|
||||||
|
foreclosure: bool | None = None
|
||||||
|
|
||||||
|
|
||||||
class Scraper:
|
class Scraper:
|
||||||
|
@ -40,6 +41,7 @@ class Scraper:
|
||||||
self.mls_only = scraper_input.mls_only
|
self.mls_only = scraper_input.mls_only
|
||||||
self.date_from = scraper_input.date_from
|
self.date_from = scraper_input.date_from
|
||||||
self.date_to = scraper_input.date_to
|
self.date_to = scraper_input.date_to
|
||||||
|
self.foreclosure = scraper_input.foreclosure
|
||||||
|
|
||||||
def search(self) -> list[Property]:
|
def search(self) -> list[Property]:
|
||||||
...
|
...
|
||||||
|
|
|
@ -381,9 +381,16 @@ class RealtorScraper(Scraper):
|
||||||
if self.listing_type == ListingType.PENDING
|
if self.listing_type == ListingType.PENDING
|
||||||
else ""
|
else ""
|
||||||
)
|
)
|
||||||
|
|
||||||
listing_type = ListingType.FOR_SALE if self.listing_type == ListingType.PENDING else self.listing_type
|
listing_type = ListingType.FOR_SALE if self.listing_type == ListingType.PENDING else self.listing_type
|
||||||
|
is_foreclosure = ""
|
||||||
|
|
||||||
|
if 'foreclosure' in variables and variables['foreclosure'] == True:
|
||||||
|
is_foreclosure = "foreclosure: true"
|
||||||
|
|
||||||
|
if 'foreclosure' in variables and variables['foreclosure'] == False:
|
||||||
|
is_foreclosure = "foreclosure: false"
|
||||||
|
|
||||||
if search_type == "comps": #: comps search, came from an address
|
if search_type == "comps": #: comps search, came from an address
|
||||||
query = """query Property_search(
|
query = """query Property_search(
|
||||||
$coordinates: [Float]!
|
$coordinates: [Float]!
|
||||||
|
@ -392,6 +399,7 @@ class RealtorScraper(Scraper):
|
||||||
) {
|
) {
|
||||||
home_search(
|
home_search(
|
||||||
query: {
|
query: {
|
||||||
|
%s
|
||||||
nearby: {
|
nearby: {
|
||||||
coordinates: $coordinates
|
coordinates: $coordinates
|
||||||
radius: $radius
|
radius: $radius
|
||||||
|
@ -404,6 +412,7 @@ class RealtorScraper(Scraper):
|
||||||
limit: 200
|
limit: 200
|
||||||
offset: $offset
|
offset: $offset
|
||||||
) %s""" % (
|
) %s""" % (
|
||||||
|
is_foreclosure,
|
||||||
listing_type.value.lower(),
|
listing_type.value.lower(),
|
||||||
date_param,
|
date_param,
|
||||||
pending_or_contingent_param,
|
pending_or_contingent_param,
|
||||||
|
@ -420,6 +429,7 @@ class RealtorScraper(Scraper):
|
||||||
) {
|
) {
|
||||||
home_search(
|
home_search(
|
||||||
query: {
|
query: {
|
||||||
|
%s
|
||||||
city: $city
|
city: $city
|
||||||
county: $county
|
county: $county
|
||||||
postal_code: $postal_code
|
postal_code: $postal_code
|
||||||
|
@ -432,6 +442,7 @@ class RealtorScraper(Scraper):
|
||||||
limit: 200
|
limit: 200
|
||||||
offset: $offset
|
offset: $offset
|
||||||
) %s""" % (
|
) %s""" % (
|
||||||
|
is_foreclosure,
|
||||||
listing_type.value.lower(),
|
listing_type.value.lower(),
|
||||||
date_param,
|
date_param,
|
||||||
pending_or_contingent_param,
|
pending_or_contingent_param,
|
||||||
|
@ -541,7 +552,7 @@ class RealtorScraper(Scraper):
|
||||||
search_variables = {
|
search_variables = {
|
||||||
"offset": 0,
|
"offset": 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
search_type = (
|
search_type = (
|
||||||
"comps"
|
"comps"
|
||||||
if self.radius and location_type == "address"
|
if self.radius and location_type == "address"
|
||||||
|
@ -586,6 +597,9 @@ class RealtorScraper(Scraper):
|
||||||
"postal_code": location_info.get("postal_code"),
|
"postal_code": location_info.get("postal_code"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.foreclosure:
|
||||||
|
search_variables['foreclosure'] = self.foreclosure
|
||||||
|
|
||||||
result = self.general_search(search_variables, search_type=search_type)
|
result = self.general_search(search_variables, search_type=search_type)
|
||||||
total = result["total"]
|
total = result["total"]
|
||||||
homes = result["properties"]
|
homes = result["properties"]
|
||||||
|
|
|
@ -139,3 +139,15 @@ def test_realtor_bad_address():
|
||||||
if len(bad_results) == 0:
|
if len(bad_results) == 0:
|
||||||
assert True
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_realtor_foreclosed():
|
||||||
|
foreclosed = scrape_property(
|
||||||
|
location="Dallas, TX", listing_type="for_sale", past_days=100, foreclosure=True
|
||||||
|
)
|
||||||
|
|
||||||
|
not_foreclosed = scrape_property(
|
||||||
|
location="Dallas, TX", listing_type="for_sale", past_days=100, foreclosure=False
|
||||||
|
)
|
||||||
|
|
||||||
|
assert len(foreclosed) != len(not_foreclosed)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue