2023-09-15 15:17:37 -07:00
|
|
|
from dataclasses import dataclass
|
|
|
|
import requests
|
2023-09-17 16:30:37 -07:00
|
|
|
from .models import Property, ListingType, SiteName
|
2023-09-15 15:17:37 -07:00
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class ScraperInput:
|
|
|
|
location: str
|
|
|
|
listing_type: ListingType
|
2023-10-02 13:58:47 -07:00
|
|
|
radius: float | None = None
|
2023-10-04 08:11:53 -07:00
|
|
|
mls_only: bool | None = None
|
2023-09-19 13:43:24 -07:00
|
|
|
proxy: str | None = None
|
2023-10-04 08:11:53 -07:00
|
|
|
last_x_days: int | None = None
|
2023-11-03 16:35:41 -07:00
|
|
|
date_from: str | None = None
|
|
|
|
date_to: str | None = None
|
2023-09-15 15:17:37 -07:00
|
|
|
|
|
|
|
|
|
|
|
class Scraper:
|
2023-10-04 08:11:53 -07:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
scraper_input: ScraperInput,
|
2023-10-05 08:10:48 -07:00
|
|
|
session: requests.Session = None,
|
2023-10-04 08:11:53 -07:00
|
|
|
):
|
2023-09-15 15:17:37 -07:00
|
|
|
self.location = scraper_input.location
|
2023-09-18 08:16:59 -07:00
|
|
|
self.listing_type = scraper_input.listing_type
|
|
|
|
|
2023-09-28 18:40:16 -07:00
|
|
|
if not session:
|
|
|
|
self.session = requests.Session()
|
|
|
|
else:
|
|
|
|
self.session = session
|
|
|
|
|
2023-09-19 14:05:14 -07:00
|
|
|
if scraper_input.proxy:
|
|
|
|
proxy_url = scraper_input.proxy
|
2023-09-19 19:13:20 -07:00
|
|
|
proxies = {"http": proxy_url, "https": proxy_url}
|
2023-09-19 14:05:14 -07:00
|
|
|
self.session.proxies.update(proxies)
|
2023-09-28 18:40:16 -07:00
|
|
|
|
2023-09-17 16:30:37 -07:00
|
|
|
self.listing_type = scraper_input.listing_type
|
2023-10-02 13:58:47 -07:00
|
|
|
self.radius = scraper_input.radius
|
2023-10-04 08:11:53 -07:00
|
|
|
self.last_x_days = scraper_input.last_x_days
|
|
|
|
self.mls_only = scraper_input.mls_only
|
2023-11-03 16:35:41 -07:00
|
|
|
self.date_from = scraper_input.date_from
|
|
|
|
self.date_to = scraper_input.date_to
|
2023-09-15 15:17:37 -07:00
|
|
|
|
2023-09-17 13:06:31 -07:00
|
|
|
def search(self) -> list[Property]:
|
|
|
|
...
|
2023-09-15 15:42:47 -07:00
|
|
|
|
|
|
|
@staticmethod
|
2023-09-17 13:06:31 -07:00
|
|
|
def _parse_home(home) -> Property:
|
|
|
|
...
|
2023-09-15 20:58:54 -07:00
|
|
|
|
2023-09-17 13:06:31 -07:00
|
|
|
def handle_location(self):
|
|
|
|
...
|