Skip to content

Commit

Permalink
- None address bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacharyHampton committed Oct 18, 2023
1 parent 11a7d85 commit c597a78
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
33 changes: 20 additions & 13 deletions homeharvest/core/scrapers/realtor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,21 +587,28 @@ def _parse_neighborhoods(result: dict) -> Optional[str]:
return ", ".join(neighborhoods_list) if neighborhoods_list else None

@staticmethod
def _parse_address(result: dict, search_type):
def handle_none_safely(address_part):
if address_part is None:
return ""

return address_part

def _parse_address(self, result: dict, search_type):
if search_type == "general_search":
return Address(
street=f"{result['location']['address']['street_number']} {result['location']['address']['street_name']} {result['location']['address']['street_suffix']}",
unit=result["location"]["address"]["unit"],
city=result["location"]["address"]["city"],
state=result["location"]["address"]["state_code"],
zip=result["location"]["address"]["postal_code"],
)
address = result['location']['address']
else:
address = result["address"]

return Address(
street=f"{result['address']['street_number']} {result['address']['street_name']} {result['address']['street_suffix']}",
unit=result["address"]["unit"],
city=result["address"]["city"],
state=result["address"]["state_code"],
zip=result["address"]["postal_code"],
street=" ".join([
self.handle_none_safely(address.get('street_number')),
self.handle_none_safely(address.get('street_name')),
self.handle_none_safely(address.get('street_suffix')),
]).strip(),
unit=address["unit"],
city=address["city"],
state=address["state_code"],
zip=address["postal_code"],
)

@staticmethod
Expand Down
10 changes: 10 additions & 0 deletions tests/test_realtor.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ def test_realtor_pending_comps():
assert len(set([len(result) for result in results])) == len(results)


def test_realtor_sold_past():
result = scrape_property(
location="San Diego, CA",
past_days=30,
listing_type="sold",
)

assert result is not None and len(result) > 0


def test_realtor_comps():
result = scrape_property(
location="2530 Al Lipscomb Way",
Expand Down

0 comments on commit c597a78

Please sign in to comment.