Skip to content

Commit

Permalink
feat: keep duplicates flag
Browse files Browse the repository at this point in the history
  • Loading branch information
cullenwatson committed Sep 21, 2023
1 parent e9ddc6d commit 644f16b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion homeharvest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def scrape_property(
site_name: Union[str, list[str]] = None,
listing_type: str = "for_sale",
proxy: str = None,
keep_duplicates: bool = False
) -> pd.DataFrame:
"""
Scrape property from various sites from a given location and listing type.
Expand Down Expand Up @@ -165,5 +166,6 @@ def scrape_property(
if col not in final_df.columns:
final_df[col] = None

final_df = final_df.drop_duplicates(subset=columns_to_track, keep="first")
if not keep_duplicates:
final_df = final_df.drop_duplicates(subset=columns_to_track, keep="first")
return final_df
9 changes: 8 additions & 1 deletion homeharvest/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,18 @@ def main():
help="Name of the output file (without extension)",
)

parser.add_argument(
"-k",
"--keep_duplicates",
action="store_true",
help="Keep duplicate properties based on address"
)

parser.add_argument("-p", "--proxy", type=str, default=None, help="Proxy to use for scraping")

args = parser.parse_args()

result = scrape_property(args.location, args.site_name, args.listing_type, proxy=args.proxy)
result = scrape_property(args.location, args.site_name, args.listing_type, proxy=args.proxy, keep_duplicates=args.keep_duplicates)

if not args.filename:
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
Expand Down

0 comments on commit 644f16b

Please sign in to comment.