Skip to content

Commit

Permalink
- switch eps
Browse files Browse the repository at this point in the history
- new hrefs
- property_id, listing_id data points
  • Loading branch information
ZacharyHampton committed Sep 6, 2024
1 parent 8cfe056 commit 1f717bd
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ Optional
Property
├── Basic Information:
│ ├── property_url
│ ├── property_id
│ ├── listing_id
│ ├── mls
│ ├── mls_id
│ └── status
Expand Down
17 changes: 15 additions & 2 deletions homeharvest/core/scrapers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,21 @@ def __init__(
Scraper.session.mount("https://", adapter)
Scraper.session.headers.update(
{
"auth": f"Bearer {self.get_access_token()}",
"apollographql-client-name": "com.move.Realtor-apollo-ios",
'accept': 'application/json, text/javascript',
'accept-language': 'en-US,en;q=0.9',
'cache-control': 'no-cache',
'content-type': 'application/json',
'origin': 'https://www.realtor.com',
'pragma': 'no-cache',
'priority': 'u=1, i',
'rdc-ab-tests': 'commute_travel_time_variation:v1',
'sec-ch-ua': '"Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
}
)

Expand Down
4 changes: 4 additions & 0 deletions homeharvest/core/scrapers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ class Advertisers:
@dataclass
class Property:
property_url: str

property_id: str
listing_id: str | None = None

mls: str | None = None
mls_id: str | None = None
status: str | None = None
Expand Down
10 changes: 4 additions & 6 deletions homeharvest/core/scrapers/realtor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,9 @@ def process_property(self, result: dict, query_name: str) -> Property | None:
if "source" in result and isinstance(result["source"], dict)
else None
),
property_url=(
f"{self.PROPERTY_URL}{property_id}"
if self.listing_type != ListingType.FOR_RENT
else f"{self.PROPERTY_URL}M{property_id}?listing_status=rental"
),
property_url=result["href"],
property_id=property_id,
listing_id=result.get("listing_id"),
status="PENDING" if is_pending else result["status"].upper(),
list_price=result["list_price"],
list_price_min=result["list_price_min"],
Expand Down Expand Up @@ -469,7 +467,7 @@ def get_prop_details(self, property_id: str) -> dict:
}"""

variables = {"property_id": property_id}
response = self.session.post(self.PROPERTY_GQL, json={"query": query, "variables": variables})
response = self.session.post(self.SEARCH_GQL_URL, json={"query": query, "variables": variables})

data = response.json()
property_details = data["data"]["home"]
Expand Down
1 change: 1 addition & 0 deletions homeharvest/core/scrapers/realtor/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pending_date
listing_id
property_id
href
list_date
status
last_sold_price
Expand Down
2 changes: 2 additions & 0 deletions homeharvest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

ordered_properties = [
"property_url",
"property_id",
"listing_id",
"mls",
"mls_id",
"status",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "homeharvest"
version = "0.4.2"
version = "0.4.3"
description = "Real estate scraping library"
authors = ["Zachary Hampton <[email protected]>", "Cullen Watson <[email protected]>"]
homepage = "https://github.com/Bunsly/HomeHarvest"
Expand Down
27 changes: 27 additions & 0 deletions tests/test_realtor.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def test_realtor_bad_address():
location="abceefg ju098ot498hh9",
listing_type="for_sale",
)

if len(bad_results) == 0:
assert True

Expand Down Expand Up @@ -253,3 +254,29 @@ def test_builder_exists():

assert listing is not None
assert listing["builder_name"].nunique() > 0


def test_phone_number_matching():
searches = [
scrape_property(
location="Phoenix, AZ",
listing_type="for_sale",
limit=100,
),
scrape_property(
location="Phoenix, AZ",
listing_type="for_sale",
limit=100,
),
]

assert all([search is not None for search in searches])

#: random row
row = searches[0][searches[0]["agent_phones"].notnull()].sample()

#: find matching row
matching_row = searches[1].loc[searches[1]["property_url"] == row["property_url"].values[0]]

#: assert phone numbers are the same
assert row["agent_phones"].values[0] == matching_row["agent_phones"].values[0]

0 comments on commit 1f717bd

Please sign in to comment.