Skip to content

Commit

Permalink
- redfin city support
Browse files Browse the repository at this point in the history
- test case updates
- types addition
- docs grammar
  • Loading branch information
ZacharyHampton committed Sep 16, 2023
1 parent 2d6e746 commit 5ea0fa0
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## RoadMap

- Currently supports scraping from **RedFin**
- Currently, supports scraping from **RedFin**
- Coming soon: Support for **Zillow** and other real estate platforms
- Under consideration: Excel plugin to attract a wider audience

Expand Down
6 changes: 6 additions & 0 deletions homeharvest/core/scrapers/realtor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ def handle_location(self):

return response_json['autocomplete'][0]


def search(self):
location_info = self.handle_location()
location_type = location_info['area_type']

"""
property types:
apartment + building + commercial + condo_townhome + condo_townhome_rowhome_coop + condos + coop + duplex_triplex + farm + investment + land + mobile + multi_family + rental + single_family + townhomes
"""
print('a')
16 changes: 12 additions & 4 deletions homeharvest/core/scrapers/redfin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@ def handle_location(self):
response = self.session.get(url)
response_json = json.loads(response.text.replace('{}&&', ''))

def get_region_type(match_type: str):
if match_type == "4":
return "2"
elif match_type == "2":
return "6"

if response_json['payload']['exactMatch'] is not None:
return response_json['payload']['exactMatch']['id'].split('_')[1]
target = response_json['payload']['exactMatch']
else:
return response_json['payload']['sections'][0]['rows'][0].split('_')[1]
target = response_json['payload']['sections'][0]['rows'][0]

return target['id'].split('_')[1], get_region_type(target['type'])

@staticmethod
def parse_home(home: dict) -> Property:
Expand Down Expand Up @@ -50,9 +58,9 @@ def get_value(key: str) -> Any | None:
)

def search(self):
region_id = self.handle_location()
region_id, region_type = self.handle_location()

url = 'https://www.redfin.com/stingray/api/gis?al=1&region_id={}&region_type=2'.format(region_id)
url = 'https://www.redfin.com/stingray/api/gis?al=1&region_id={}&region_type={}'.format(region_id, region_type)

response = self.session.get(url)
response_json = json.loads(response.text.replace('{}&&', ''))
Expand Down
2 changes: 2 additions & 0 deletions homeharvest/core/scrapers/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ class Property:
price_per_square_foot: int | None = None
price: int | None = None
mls_id: str | None = None

property_type: str | None = None
12 changes: 7 additions & 5 deletions tests/test_realtor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@


def test_realtor():
result = scrape_property(
location="85281",
site_name="realtor.com"
)
results = [
scrape_property(
location="85281",
site_name="realtor.com"
),
]

assert result is not None
assert all([result is not None for result in results])
20 changes: 15 additions & 5 deletions tests/test_redfin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@


def test_redfin():
result = scrape_property(
site_name="redfin",
location="85281"
)
results = [
scrape_property(
location="Phoenix, AZ, USA",
site_name="redfin"
),
scrape_property(
location="Dallas, TX, USA",
site_name="redfin"
),
scrape_property(
location="85281",
site_name="redfin"
),
]

assert result is not None
assert all([result is not None for result in results])

0 comments on commit 5ea0fa0

Please sign in to comment.