- broker data

pull/82/head v0.3.22
Zachary Hampton 2024-05-11 21:35:29 -07:00
parent c3e24a4ce0
commit 3458a08383
4 changed files with 35 additions and 6 deletions

View File

@ -121,7 +121,8 @@ class Property:
neighborhoods: Optional[str] = None neighborhoods: Optional[str] = None
county: Optional[str] = None county: Optional[str] = None
fips_code: Optional[str] = None fips_code: Optional[str] = None
agents: list[Agent] = None agents: list[Agent] | None = None
brokers: list[Broker] | None = None
nearby_schools: list[str] = None nearby_schools: list[str] = None
assessed_value: int | None = None assessed_value: int | None = None
estimated_value: int | None = None estimated_value: int | None = None

View File

@ -10,7 +10,7 @@ from datetime import datetime
from typing import Dict, Union, Optional from typing import Dict, Union, Optional
from .. import Scraper from .. import Scraper
from ..models import Property, Address, ListingType, Description, PropertyType, Agent from ..models import Property, Address, ListingType, Description, PropertyType, Agent, Broker
class RealtorScraper(Scraper): class RealtorScraper(Scraper):
@ -180,6 +180,7 @@ class RealtorScraper(Scraper):
), ),
days_on_mls=days_on_mls, days_on_mls=days_on_mls,
agents=prop_details.get("agents"), agents=prop_details.get("agents"),
brokers=prop_details.get("brokers"),
nearby_schools=prop_details.get("schools"), nearby_schools=prop_details.get("schools"),
assessed_value=prop_details.get("assessed_value"), assessed_value=prop_details.get("assessed_value"),
estimated_value=prop_details.get("estimated_value"), estimated_value=prop_details.get("estimated_value"),
@ -295,6 +296,7 @@ class RealtorScraper(Scraper):
address=self._parse_address(property_info, search_type="handle_address"), address=self._parse_address(property_info, search_type="handle_address"),
description=self._parse_description(property_info), description=self._parse_description(property_info),
agents=prop_details.get("agents"), agents=prop_details.get("agents"),
brokers=prop_details.get("brokers"),
nearby_schools=prop_details.get("schools"), nearby_schools=prop_details.get("schools"),
assessed_value=prop_details.get("assessed_value"), assessed_value=prop_details.get("assessed_value"),
estimated_value=prop_details.get("estimated_value"), estimated_value=prop_details.get("estimated_value"),
@ -553,6 +555,7 @@ class RealtorScraper(Scraper):
fips_code=result["location"]["county"].get("fips_code") if result["location"]["county"] else None, fips_code=result["location"]["county"].get("fips_code") if result["location"]["county"] else None,
days_on_mls=self.calculate_days_on_mls(result), days_on_mls=self.calculate_days_on_mls(result),
agents=prop_details.get("agents"), agents=prop_details.get("agents"),
brokers=prop_details.get("brokers"),
nearby_schools=prop_details.get("schools"), nearby_schools=prop_details.get("schools"),
assessed_value=prop_details.get("assessed_value"), assessed_value=prop_details.get("assessed_value"),
estimated_value=prop_details.get("estimated_value"), estimated_value=prop_details.get("estimated_value"),
@ -666,6 +669,12 @@ class RealtorScraper(Scraper):
phones { number type ext primary } phones { number type ext primary }
} }
consumer_advertisers {
name
phone
href
type
}
nearbySchools: nearby_schools(radius: 5.0, limit_per_level: 3) { nearbySchools: nearby_schools(radius: 5.0, limit_per_level: 3) {
__typename schools { district { __typename id name } } __typename schools { district { __typename id name } }
@ -700,7 +709,9 @@ class RealtorScraper(Scraper):
except (KeyError, TypeError, IndexError): except (KeyError, TypeError, IndexError):
return {} return {}
ads = get_key(["data", "home", "advertisers"]) agents = get_key(["data", "home", "advertisers"])
advertisers = get_key(["data", "home", "consumer_advertisers"])
schools = get_key(["data", "home", "nearbySchools", "schools"]) schools = get_key(["data", "home", "nearbySchools", "schools"])
assessed_value = get_key(["data", "home", "taxHistory", 0, "assessment", "total"]) assessed_value = get_key(["data", "home", "taxHistory", 0, "assessment", "total"])
estimated_value = get_key(["data", "home", "estimates", "currentValues", 0, "estimate"]) estimated_value = get_key(["data", "home", "estimates", "currentValues", 0, "estimate"])
@ -709,11 +720,18 @@ class RealtorScraper(Scraper):
name=ad["name"], name=ad["name"],
email=ad["email"], email=ad["email"],
phones=ad["phones"] phones=ad["phones"]
) for ad in ads] ) for ad in agents]
brokers = [Broker(
name=ad["name"],
phone=ad["phone"],
website=ad["href"]
) for ad in advertisers if ad.get("type") != "Agent"]
schools = [school["district"]["name"] for school in schools if school['district'].get('name')] schools = [school["district"]["name"] for school in schools if school['district'].get('name')]
return { return {
"agents": agents if agents else None, "agents": agents if agents else None,
"brokers": brokers if brokers else None,
"schools": schools if schools else None, "schools": schools if schools else None,
"assessed_value": assessed_value if assessed_value else None, "assessed_value": assessed_value if assessed_value else None,
"estimated_value": estimated_value if estimated_value else None, "estimated_value": estimated_value if estimated_value else None,

View File

@ -40,6 +40,9 @@ ordered_properties = [
"agent", "agent",
"agent_email", "agent_email",
"agent_phones", "agent_phones",
"broker",
"broker_phone",
"broker_website",
"nearby_schools", "nearby_schools",
"primary_photo", "primary_photo",
"alt_photos", "alt_photos",
@ -65,6 +68,13 @@ def process_result(result: Property) -> pd.DataFrame:
prop_data["agent_email"] = agents[0].email prop_data["agent_email"] = agents[0].email
prop_data["agent_phones"] = agents[0].phones prop_data["agent_phones"] = agents[0].phones
if "brokers" in prop_data:
brokers = prop_data["brokers"]
if brokers:
prop_data["broker"] = brokers[0].name
prop_data["broker_phone"] = brokers[0].phone
prop_data["broker_website"] = brokers[0].website
prop_data["price_per_sqft"] = prop_data["prc_sqft"] prop_data["price_per_sqft"] = prop_data["prc_sqft"]
prop_data["nearby_schools"] = filter(None, prop_data["nearby_schools"]) if prop_data["nearby_schools"] else None prop_data["nearby_schools"] = filter(None, prop_data["nearby_schools"]) if prop_data["nearby_schools"] else None
prop_data["nearby_schools"] = ", ".join(set(prop_data["nearby_schools"])) if prop_data["nearby_schools"] else None prop_data["nearby_schools"] = ", ".join(set(prop_data["nearby_schools"])) if prop_data["nearby_schools"] else None

View File

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "homeharvest" name = "homeharvest"
version = "0.3.21" version = "0.3.22"
description = "Real estate scraping library" description = "Real estate scraping library"
authors = ["Zachary Hampton <zachary@bunsly.com>", "Cullen Watson <cullen@bunsly.com>"] authors = ["Zachary Hampton <zachary@bunsly.com>", "Cullen Watson <cullen@bunsly.com>"]
homepage = "https://github.com/Bunsly/HomeHarvest" homepage = "https://github.com/Bunsly/HomeHarvest"