HomeHarvest/homeharvest/core/scrapers/models.py

110 lines
2.4 KiB
Python
Raw Normal View History

2023-09-15 15:17:37 -07:00
from dataclasses import dataclass
from enum import Enum
2023-09-19 19:13:20 -07:00
from typing import Tuple
2023-09-15 15:17:37 -07:00
2023-09-17 16:30:37 -07:00
class SiteName(Enum):
ZILLOW = "zillow"
REDFIN = "redfin"
REALTOR = "realtor.com"
@classmethod
def get_by_value(cls, value):
for item in cls:
if item.value == value:
return item
raise ValueError(f"{value} not found in {cls}")
2023-09-17 16:30:37 -07:00
2023-09-15 15:17:37 -07:00
class ListingType(Enum):
2023-09-18 11:38:17 -07:00
FOR_SALE = "FOR_SALE"
FOR_RENT = "FOR_RENT"
SOLD = "SOLD"
2023-09-15 15:17:37 -07:00
2023-09-17 16:30:37 -07:00
class PropertyType(Enum):
HOUSE = "HOUSE"
2023-09-18 11:38:17 -07:00
BUILDING = "BUILDING"
2023-09-17 16:30:37 -07:00
CONDO = "CONDO"
2023-09-17 16:52:34 -07:00
TOWNHOUSE = "TOWNHOUSE"
2023-09-17 16:30:37 -07:00
SINGLE_FAMILY = "SINGLE_FAMILY"
MULTI_FAMILY = "MULTI_FAMILY"
2023-09-17 16:52:34 -07:00
MANUFACTURED = "MANUFACTURED"
2023-09-18 11:38:17 -07:00
NEW_CONSTRUCTION = "NEW_CONSTRUCTION"
2023-09-17 16:52:34 -07:00
APARTMENT = "APARTMENT"
2023-09-18 11:38:17 -07:00
APARTMENTS = "APARTMENTS"
2023-09-17 16:30:37 -07:00
LAND = "LAND"
2023-09-18 11:38:17 -07:00
LOT = "LOT"
2023-09-17 16:30:37 -07:00
OTHER = "OTHER"
2023-09-18 11:38:17 -07:00
BLANK = "BLANK"
2023-09-17 16:30:37 -07:00
@classmethod
def from_int_code(cls, code):
mapping = {
1: cls.HOUSE,
2: cls.CONDO,
3: cls.TOWNHOUSE,
4: cls.MULTI_FAMILY,
5: cls.LAND,
6: cls.OTHER,
8: cls.SINGLE_FAMILY,
13: cls.SINGLE_FAMILY,
}
2023-09-18 11:38:17 -07:00
return mapping.get(code, cls.BLANK)
2023-09-17 16:30:37 -07:00
2023-09-15 15:17:37 -07:00
@dataclass
class Address:
2023-09-19 19:13:20 -07:00
address_one: str | None = None
address_two: str | None = "#"
city: str | None = None
state: str | None = None
zip_code: str | None = None
2023-09-15 15:17:37 -07:00
2023-09-18 11:38:17 -07:00
@dataclass
class Property:
property_url: str
2023-09-17 16:30:37 -07:00
site_name: SiteName
2023-09-18 11:38:17 -07:00
listing_type: ListingType
2023-09-15 15:17:37 -07:00
address: Address
property_type: PropertyType | None = None
2023-09-15 16:03:17 -07:00
2023-09-18 11:38:17 -07:00
# house for sale
tax_assessed_value: int | None = None
lot_area_value: float | None = None
lot_area_unit: str | None = None
2023-09-15 16:03:17 -07:00
stories: int | None = None
year_built: int | None = None
2023-09-18 11:38:17 -07:00
price_per_sqft: int | None = None
2023-09-15 16:03:17 -07:00
mls_id: str | None = None
2023-09-17 16:30:37 -07:00
agent_name: str | None = None
2023-09-18 11:38:17 -07:00
img_src: str | None = None
2023-09-17 13:06:31 -07:00
description: str | None = None
2023-09-18 11:38:17 -07:00
status_text: str | None = None
posted_time: str | None = None
# building for sale
bldg_name: str | None = None
2023-09-19 19:13:20 -07:00
area_min: int | None = None
beds_min: int | None = None
beds_max: int | None = None
baths_min: float | None = None
baths_max: float | None = None
sqft_min: int | None = None
sqft_max: int | None = None
price_min: int | None = None
price_max: int | None = None
unit_count: int | None = None
latitude: float | None = None
longitude: float | None = None