From ec86b572b350a1e76e1cb6698ea3337554e6b94b Mon Sep 17 00:00:00 2001 From: Kadir Date: Sat, 30 Mar 2024 18:31:49 +0100 Subject: [PATCH] adding districts and location identifier to search --- crawler/rec/districts.py | 36 ++++++++++++++++++++++++++++++++++++ crawler/rec/query.py | 30 ++++++++++++++++-------------- 2 files changed, 52 insertions(+), 14 deletions(-) create mode 100644 crawler/rec/districts.py diff --git a/crawler/rec/districts.py b/crawler/rec/districts.py new file mode 100644 index 0000000..2778241 --- /dev/null +++ b/crawler/rec/districts.py @@ -0,0 +1,36 @@ +def get_districts(): + return { + "City of London": "REGION^61224", + "Greenwich": "REGION^61226", + "Hillingdon": "REGION^93959", + "Ealing": "REGION^93947", + "Richmond upon Thames": "REGION^61415", + "Sutton": "REGION^93974", + "Wandsworth": "REGION^93977", + "Camden": "REGION^93941", + "Enfield": "REGION^93950", + "Croydon": "REGION^93944", + "Hackney": "REGION^93953", + "Kingston upon Thames": "REGION^93968", + "Kensington and Chelsea": "REGION^61229", + "Bromley": "REGION^93938", + "Brent": "REGION^93935", + "Waltham Forest": "REGION^61232", + "Southwark": "REGION^61518", + "Harrow": "REGION^93956", + "Lewisham": "REGION^61413", + "Barnet": "REGION^93929", + "Islington": "REGION^93965", + "Haringey": "REGION^61227", + "Lambeth": "REGION^93971", + "Westminster": "REGION^93980", + "Tower Hamlets": "REGION^61417", + "Havering": "REGION^61228", + "Barking and Dagenham": "REGION^61400", + "Hammersmith and Fulham": "REGION^61407", + "Bexley": "REGION^93932", + "Redbridge": "REGION^61537", + "Newham": "REGION^61231", + "Merton": "REGION^61414", + "Hounslow": "REGION^93962", +} diff --git a/crawler/rec/query.py b/crawler/rec/query.py index 90d2184..e0d104a 100644 --- a/crawler/rec/query.py +++ b/crawler/rec/query.py @@ -17,14 +17,15 @@ headers = { "Connection": "close", } -class PropertyType(enum.StrEnum): - BUNGALOW= "bungalow" - DETACHED= "detached" - FLAT= "flat" - LAND= "land" - PARK_HOME= "park-home" - SEMI_DETACHED= "semi-detached" - TERRACED= "terraced" + +class PropertyType(enum.StrEnum): + BUNGALOW = "bungalow" + DETACHED = "detached" + FLAT = "flat" + LAND = "land" + PARK_HOME = "park-home" + SEMI_DETACHED = "semi-detached" + TERRACED = "terraced" def detail_query(detail_id: int): @@ -48,19 +49,19 @@ def listing_query( radius: float, min_price: int, max_price: int, + location_id: str = "STATION^5168", # kings cross station mustNewHome: bool = False, max_days_since_added: int = None, - property_type: List['PropertyType'] = [] + property_type: List["PropertyType"] = [], ) -> dict: params = { - "locationIdentifier": "POSTCODE^4228216", + "locationIdentifier": location_id, "channel": "BUY", "page": str(page), - "numberOfPropertiesPerPage": "25", + "numberOfPropertiesPerPage": "100", "radius": str(radius), "sortBy": "distance", "includeUnavailableProperties": "false", - "propertyTypes": "flat", "dontShow": "sharedOwnership,retirement", "minPrice": str(min_price), "maxPrice": str(max_price), @@ -70,7 +71,7 @@ def listing_query( "appVersion": "3.70.0", } if len(property_type) > 0: - params['propertyTypes'] = ','.join(property_type) + params["propertyTypes"] = ",".join(property_type) if max_days_since_added: if max_days_since_added not in [1, 3, 7, 14]: raise Exception("Invalid max days. Can only be", [1, 3, 7, 14]) @@ -78,7 +79,7 @@ def listing_query( if mustNewHome: params["mustHave"] = "newHome" - + print(params) response = requests.get( "https://api.rightmove.co.uk/api/property-listing", params=params, @@ -111,3 +112,4 @@ if __name__ == "__main__": lon=d["longitude"], ) rl.save() +