feat(redfin): add sold listing_type

pull/9/head
Cullen Watson 2023-09-19 12:27:13 -05:00
parent 1fc2d8c549
commit dba1c03081
4 changed files with 21 additions and 14 deletions

View File

@ -41,6 +41,10 @@ def get_ordered_properties(result: Property) -> list[str]:
"apt_max_price",
"apt_min_sqft",
"apt_max_sqft",
"apt_min_beds",
"apt_max_beds",
"apt_min_baths",
"apt_max_baths",
"tax_assessed_value",
"square_feet",
"price_per_sqft",

View File

@ -102,6 +102,10 @@ class Property:
bldg_min_area: int | None = None
# 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_max_price: int | None = None
apt_min_sqft: int | None = None

View File

@ -112,8 +112,7 @@ class RedfinScraper(Scraper):
url = f"https://www.redfin.com/stingray/api/v1/search/rentals?al=1&isRentals=true&region_id={region_id}&region_type={region_type}"
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()
properties_list = []
@ -144,9 +143,10 @@ class RedfinScraper(Scraper):
site_name=SiteName.REDFIN,
listing_type=ListingType.FOR_RENT,
address=address,
square_feet=sqft_range.get("min", None),
beds=bed_range.get("min", None),
baths=bath_range.get("min", None),
apt_min_beds=bed_range.get("min", None),
apt_min_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),
latitude=centroid.get("latitude", None),
longitude=centroid.get("longitude", None),
@ -228,8 +228,11 @@ class RedfinScraper(Scraper):
if self.listing_type == ListingType.FOR_RENT:
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&region_id={region_id}&region_type={region_type}"
else:
url = f"https://www.redfin.com/stingray/api/gis?al=1&region_id={region_id}&region_type={region_type}&sold_within_days=30"
response = self.session.get(url)
response_json = json.loads(response.text.replace("{}&&", ""))
homes = [
@ -239,6 +242,3 @@ class RedfinScraper(Scraper):
for building in response_json["payload"]["buildings"].values()
]
return homes
else:
# Handle other cases, maybe raise an error if the listing type is not recognized.
pass

View File

@ -15,10 +15,9 @@ def test_redfin():
scrape_property(
location="Phoenix, AZ, USA", site_name=["redfin"], listing_type="for_rent"
),
# TODO
# scrape_property(
# location="Dallas, TX, USA", site_name="redfin", listing_type="sold"
# ),
scrape_property(
location="Dallas, TX, USA", site_name="redfin", listing_type="sold"
),
scrape_property(location="85281", site_name="redfin"),
]