feat(redfin): add sold listing_type
parent
1fc2d8c549
commit
dba1c03081
|
@ -41,6 +41,10 @@ def get_ordered_properties(result: Property) -> list[str]:
|
||||||
"apt_max_price",
|
"apt_max_price",
|
||||||
"apt_min_sqft",
|
"apt_min_sqft",
|
||||||
"apt_max_sqft",
|
"apt_max_sqft",
|
||||||
|
"apt_min_beds",
|
||||||
|
"apt_max_beds",
|
||||||
|
"apt_min_baths",
|
||||||
|
"apt_max_baths",
|
||||||
"tax_assessed_value",
|
"tax_assessed_value",
|
||||||
"square_feet",
|
"square_feet",
|
||||||
"price_per_sqft",
|
"price_per_sqft",
|
||||||
|
|
|
@ -102,6 +102,10 @@ class Property:
|
||||||
bldg_min_area: int | None = None
|
bldg_min_area: int | None = None
|
||||||
|
|
||||||
# apt
|
# apt
|
||||||
|
apt_min_beds: int | None = None
|
||||||
|
apt_max_beds: int | None = None
|
||||||
|
apt_min_baths: float | None = None
|
||||||
|
apt_max_baths: float | None = None
|
||||||
apt_min_price: int | None = None
|
apt_min_price: int | None = None
|
||||||
apt_max_price: int | None = None
|
apt_max_price: int | None = None
|
||||||
apt_min_sqft: int | None = None
|
apt_min_sqft: int | None = None
|
||||||
|
|
|
@ -112,8 +112,7 @@ class RedfinScraper(Scraper):
|
||||||
url = f"https://www.redfin.com/stingray/api/v1/search/rentals?al=1&isRentals=true®ion_id={region_id}®ion_type={region_type}"
|
url = f"https://www.redfin.com/stingray/api/v1/search/rentals?al=1&isRentals=true®ion_id={region_id}®ion_type={region_type}"
|
||||||
|
|
||||||
response = self.session.get(url)
|
response = self.session.get(url)
|
||||||
response.raise_for_status() # This will raise an error if the response contains an HTTP error status.
|
response.raise_for_status()
|
||||||
|
|
||||||
homes = response.json()
|
homes = response.json()
|
||||||
|
|
||||||
properties_list = []
|
properties_list = []
|
||||||
|
@ -144,9 +143,10 @@ class RedfinScraper(Scraper):
|
||||||
site_name=SiteName.REDFIN,
|
site_name=SiteName.REDFIN,
|
||||||
listing_type=ListingType.FOR_RENT,
|
listing_type=ListingType.FOR_RENT,
|
||||||
address=address,
|
address=address,
|
||||||
square_feet=sqft_range.get("min", None),
|
apt_min_beds=bed_range.get("min", None),
|
||||||
beds=bed_range.get("min", None),
|
apt_min_baths=bath_range.get("min", None),
|
||||||
baths=bath_range.get("min", None),
|
apt_max_beds=bed_range.get("max", None),
|
||||||
|
apt_max_baths=bath_range.get("max", None),
|
||||||
description=rental_data.get("description", None),
|
description=rental_data.get("description", None),
|
||||||
latitude=centroid.get("latitude", None),
|
latitude=centroid.get("latitude", None),
|
||||||
longitude=centroid.get("longitude", None),
|
longitude=centroid.get("longitude", None),
|
||||||
|
@ -228,8 +228,11 @@ class RedfinScraper(Scraper):
|
||||||
|
|
||||||
if self.listing_type == ListingType.FOR_RENT:
|
if self.listing_type == ListingType.FOR_RENT:
|
||||||
return self._handle_rentals(region_id, region_type)
|
return self._handle_rentals(region_id, region_type)
|
||||||
elif self.listing_type == ListingType.FOR_SALE:
|
else:
|
||||||
|
if self.listing_type == ListingType.FOR_SALE:
|
||||||
url = f"https://www.redfin.com/stingray/api/gis?al=1®ion_id={region_id}®ion_type={region_type}"
|
url = f"https://www.redfin.com/stingray/api/gis?al=1®ion_id={region_id}®ion_type={region_type}"
|
||||||
|
else:
|
||||||
|
url = f"https://www.redfin.com/stingray/api/gis?al=1®ion_id={region_id}®ion_type={region_type}&sold_within_days=30"
|
||||||
response = self.session.get(url)
|
response = self.session.get(url)
|
||||||
response_json = json.loads(response.text.replace("{}&&", ""))
|
response_json = json.loads(response.text.replace("{}&&", ""))
|
||||||
homes = [
|
homes = [
|
||||||
|
@ -239,6 +242,3 @@ class RedfinScraper(Scraper):
|
||||||
for building in response_json["payload"]["buildings"].values()
|
for building in response_json["payload"]["buildings"].values()
|
||||||
]
|
]
|
||||||
return homes
|
return homes
|
||||||
else:
|
|
||||||
# Handle other cases, maybe raise an error if the listing type is not recognized.
|
|
||||||
pass
|
|
||||||
|
|
|
@ -15,10 +15,9 @@ def test_redfin():
|
||||||
scrape_property(
|
scrape_property(
|
||||||
location="Phoenix, AZ, USA", site_name=["redfin"], listing_type="for_rent"
|
location="Phoenix, AZ, USA", site_name=["redfin"], listing_type="for_rent"
|
||||||
),
|
),
|
||||||
# TODO
|
scrape_property(
|
||||||
# scrape_property(
|
location="Dallas, TX, USA", site_name="redfin", listing_type="sold"
|
||||||
# location="Dallas, TX, USA", site_name="redfin", listing_type="sold"
|
),
|
||||||
# ),
|
|
||||||
scrape_property(location="85281", site_name="redfin"),
|
scrape_property(location="85281", site_name="redfin"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue