Skip to content

Commit

Permalink
- rename last_x_days
Browse files Browse the repository at this point in the history
- docstrings for scrape_property
  • Loading branch information
ZacharyHampton committed Oct 5, 2023
1 parent 6bb6876 commit de692fa
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ options:
> homeharvest "San Francisco, CA" -l for_rent -o excel -f HomeHarvest
```

### Python
### Python

```py
from homeharvest import scrape_property
Expand All @@ -72,10 +72,10 @@ current_timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
filename = f"output/{current_timestamp}.csv"

properties = scrape_property(
location="San Diego, CA",
listing_type="sold", # or (for_sale, for_rent)
last_x_days=30, # sold in last 30 days - listed in last x days if (for_sale, for_rent)
mls_only=True, # only fetch MLS listings
location="San Diego, CA",
listing_type="sold", # or (for_sale, for_rent)
property_younger_than=30, # sold in last 30 days - listed in last x days if (for_sale, for_rent)
mls_only=True, # only fetch MLS listings
)
print(f"Number of properties: {len(properties)}")

Expand All @@ -84,7 +84,6 @@ properties.to_csv(filename, index=False)
print(properties.head())
```


## Output
```plaintext
>>> properties.head()
Expand Down
2 changes: 1 addition & 1 deletion examples/HomeHarvest_Demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
properties = scrape_property(
location="San Diego, CA",
listing_type="sold", # for_sale, for_rent
last_x_days=30, # sold/listed in last 30 days
property_younger_than=30, # sold/listed in last 30 days
mls_only=True, # only fetch MLS listings
)
print(f"Number of properties: {len(properties)}")
Expand Down
10 changes: 8 additions & 2 deletions homeharvest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ def scrape_property(
listing_type: str = "for_sale",
radius: float = None,
mls_only: bool = False,
last_x_days: int = None,
property_younger_than: int = None,
proxy: str = None,
) -> pd.DataFrame:
"""
Scrape properties from Realtor.com based on a given location and listing type.
:param location: Location to search (e.g. "Dallas, TX", "85281", "2530 Al Lipscomb Way")
:param listing_type: Listing Type (for_sale, for_rent, sold)
:param radius: Get properties within _ (e.g. 1.0) miles. Only applicable for individual addresses.
:param mls_only: If set, fetches only listings with MLS IDs.
:param property_younger_than: Get properties sold/listed in last _ days.
:param proxy: Proxy to use for scraping
"""
validate_input(listing_type)

Expand All @@ -26,7 +32,7 @@ def scrape_property(
proxy=proxy,
radius=radius,
mls_only=mls_only,
last_x_days=last_x_days,
last_x_days=property_younger_than,
)

site = RealtorScraper(scraper_input)
Expand Down
2 changes: 1 addition & 1 deletion homeharvest/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def main():
radius=args.radius,
proxy=args.proxy,
mls_only=args.mls_only,
last_x_days=args.days,
property_younger_than=args.days,
)

if not args.filename:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_realtor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_realtor_comps():
result = scrape_property(
location="2530 Al Lipscomb Way",
radius=0.5,
last_x_days=180,
property_younger_than=180,
listing_type="sold",
)

Expand All @@ -18,11 +18,11 @@ def test_realtor_comps():

def test_realtor_last_x_days_sold():
days_result_30 = scrape_property(
location="Dallas, TX", listing_type="sold", last_x_days=30
location="Dallas, TX", listing_type="sold", property_younger_than=30
)

days_result_10 = scrape_property(
location="Dallas, TX", listing_type="sold", last_x_days=10
location="Dallas, TX", listing_type="sold", property_younger_than=10
)

assert all(
Expand Down

0 comments on commit de692fa

Please sign in to comment.