From 3c60ae689d29673fc5f117266f12bd068f3e2617 Mon Sep 17 00:00:00 2001 From: jvech Date: Mon, 3 Apr 2023 21:39:05 -0500 Subject: add: rent offers option included --- scrap/fincaraiz.py | 3 ++- scrap/scrap.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/scrap/fincaraiz.py b/scrap/fincaraiz.py index e8adcf0..354f407 100644 --- a/scrap/fincaraiz.py +++ b/scrap/fincaraiz.py @@ -87,7 +87,7 @@ JSON_DATA = { } } -def get_json(city: str, pages: int = 1) -> list: +def get_json(city: str, pages: int = 1, offer: list[str] = ["sell"]) -> list: """Get json data from fincaraiz.com.co Parameters @@ -129,6 +129,7 @@ def get_json(city: str, pages: int = 1) -> list: for x in requests.get("https://www.datos.gov.co/resource/xdk5-pm3f.json").json() if town_exist(x['municipio'])] + json_data["filter"]["offer"]["slug"] = offer if location: json_data["filter"]["locations"] = {"cities": {"slug": location } } else: diff --git a/scrap/scrap.py b/scrap/scrap.py index 50ef3d4..946a2a4 100644 --- a/scrap/scrap.py +++ b/scrap/scrap.py @@ -7,6 +7,9 @@ Options: -v --verbose Be more verbose -o FILE Redirect standard output to FILE. -p INT Number of pages to get [default: 1] + -r --rent Select housing rent offers. + -s --sell Select housing sell offers, if there is no -r option this + option is enabled by default. Examples: $ scrap MedellĂ­n -p 20 @@ -24,7 +27,13 @@ def main(): args = docopt(__doc__) city: str = args[""] - options = {"pages": int(args["-p"])} + options = {"pages": int(args["-p"]), + "offer": ["sell"]} + + if args["-s"] and args["-r"]: + options["offer"].append("rent") + elif args["-r"] and not args["-s"]: + options["offer"] = ["rent"] json_data = get_json(city, **options) -- cgit v1.2.3-70-g09d2