Skip to content

Commit

Permalink
refactor: remove cls method
Browse files Browse the repository at this point in the history
  • Loading branch information
cullenwatson committed Sep 17, 2023
1 parent a433e46 commit b76c659
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
3 changes: 0 additions & 3 deletions homeharvest/core/scrapers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ class ScraperInput:


class Scraper:
listing_type = ListingType.FOR_SALE

def __init__(self, scraper_input: ScraperInput):
self.location = scraper_input.location
self.session = requests.Session()
Scraper.listing_type = scraper_input.listing_type

if scraper_input.proxy_url:
self.session.proxies = {
Expand Down
19 changes: 9 additions & 10 deletions homeharvest/core/scrapers/zillow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ZillowScraper(Scraper):

def __init__(self, scraper_input):
super().__init__(scraper_input)
self.listing_type = scraper_input.listing_type
if self.listing_type == ListingType.FOR_SALE:
self.url = f"https://www.zillow.com/homes/for_sale/{self.location}_rb/"
elif self.listing_type == ListingType.FOR_RENT:
Expand Down Expand Up @@ -48,8 +49,7 @@ def search(self):
return [property]
raise PropertyNotFound("Specific property data not found in the response.")

@classmethod
def _parse_home(cls, home: dict):
def _parse_home(self, home: dict):
"""
This method is used when a user enters a generic location & zillow returns more than one property
"""
Expand All @@ -60,9 +60,9 @@ def _parse_home(cls, home: dict):
)

if "hdpData" in home and "homeInfo" in home["hdpData"]:
price_data = cls._extract_price(home)
address = cls._extract_address(home)
agent_name = cls._extract_agent_name(home)
price_data = self._extract_price(home)
address = self._extract_address(home)
agent_name = self._extract_agent_name(home)
beds = home["hdpData"]["homeInfo"]["bedrooms"]
baths = home["hdpData"]["homeInfo"]["bathrooms"]
listing_type = home["hdpData"]["homeInfo"].get("homeType")
Expand All @@ -79,10 +79,10 @@ def _parse_home(cls, home: dict):
else:
keys = ("addressStreet", "addressCity", "addressState", "addressZipcode")
address_one, city, state, zip_code = (home[key] for key in keys)
address_one, address_two = cls._parse_address_two(address_one)
address_one, address_two = self._parse_address_two(address_one)
address = Address(address_one, city, state, zip_code, address_two)

building_info = cls._extract_building_info(home)
building_info = self._extract_building_info(home)
return Building(address=address, url=url, **building_info)

@classmethod
Expand Down Expand Up @@ -124,15 +124,14 @@ def _get_single_property_page(cls, property_data: dict):
listing_type=property_data.get("homeType", None),
)

@classmethod
def _extract_building_info(cls, home: dict) -> dict:
def _extract_building_info(self, home: dict) -> dict:
num_units = len(home["units"])
prices = [
int(unit["price"].replace("$", "").replace(",", "").split("+")[0])
for unit in home["units"]
]
return {
"listing_type": cls.listing_type,
"listing_type": self.listing_type,
"num_units": len(home["units"]),
"min_unit_price": min(
(
Expand Down

0 comments on commit b76c659

Please sign in to comment.