2023-09-15 15:17:37 -07:00
|
|
|
from .core.scrapers.redfin import RedfinScraper
|
2023-09-15 20:58:54 -07:00
|
|
|
from .core.scrapers.realtor import RealtorScraper
|
2023-09-17 13:06:31 -07:00
|
|
|
from .core.scrapers.zillow import ZillowScraper
|
|
|
|
from .core.scrapers.models import ListingType, Property, Building
|
2023-09-15 15:17:37 -07:00
|
|
|
from .core.scrapers import ScraperInput
|
|
|
|
from .exceptions import InvalidSite, InvalidListingType
|
2023-09-17 13:06:31 -07:00
|
|
|
from typing import Union
|
2023-09-15 15:17:37 -07:00
|
|
|
|
|
|
|
|
|
|
|
_scrapers = {
|
|
|
|
"redfin": RedfinScraper,
|
2023-09-17 13:06:31 -07:00
|
|
|
"realtor.com": RealtorScraper,
|
|
|
|
"zillow": ZillowScraper,
|
2023-09-15 15:17:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def scrape_property(
|
2023-09-17 13:06:31 -07:00
|
|
|
location: str,
|
|
|
|
site_name: str,
|
|
|
|
listing_type: str = "for_sale", #: for_sale, for_rent, sold
|
|
|
|
) -> Union[list[Building], list[Property]]: #: eventually, return pandas dataframe
|
2023-09-15 15:21:29 -07:00
|
|
|
if site_name.lower() not in _scrapers:
|
2023-09-15 15:17:37 -07:00
|
|
|
raise InvalidSite(f"Provided site, '{site_name}', does not exist.")
|
|
|
|
|
|
|
|
if listing_type.upper() not in ListingType.__members__:
|
2023-09-17 13:06:31 -07:00
|
|
|
raise InvalidListingType(
|
|
|
|
f"Provided listing type, '{listing_type}', does not exist."
|
|
|
|
)
|
2023-09-15 15:17:37 -07:00
|
|
|
|
|
|
|
scraper_input = ScraperInput(
|
|
|
|
location=location,
|
|
|
|
listing_type=ListingType[listing_type.upper()],
|
|
|
|
)
|
|
|
|
|
2023-09-15 15:21:29 -07:00
|
|
|
site = _scrapers[site_name.lower()](scraper_input)
|
2023-09-15 15:17:37 -07:00
|
|
|
|
|
|
|
return site.search()
|