add cli param for querying properties to rent

example:
python main.py --data-dir data/rs2 dump-listings --max-price 3500 --min-bedrooms 2 --max-bedrooms 4 --district islington -t rent
This commit is contained in:
Viktor Barzin 2025-05-17 21:22:39 +00:00
parent bb9afc76fe
commit df24c2c1b7
No known key found for this signature in database
GPG key ID: 4056458DBDBF8863
3 changed files with 44 additions and 18 deletions

View file

@ -6,7 +6,11 @@ import urllib3
urllib3.disable_warnings()
# cache = Cache(r"_cache")
class ListingType(enum.StrEnum):
BUY = "BUY"
RENT = "RENT"
headers = {
"Host": "api.rightmove.co.uk",
@ -42,9 +46,9 @@ def detail_query(detail_id: int):
return response.json()
# @cache.memoize()
def listing_query(
page: int,
channel: ListingType,
min_bedrooms: int,
max_bedrooms: int,
radius: float,
@ -58,29 +62,38 @@ def listing_query(
) -> dict:
params = {
"locationIdentifier": location_id,
"channel": "BUY",
"channel": channel.upper(),
"page": str(page),
"numberOfPropertiesPerPage": str(page_size),
"radius": str(radius),
"sortBy": "distance",
"includeUnavailableProperties": "false",
"dontShow": "sharedOwnership,retirement",
"minPrice": str(min_price),
"maxPrice": str(max_price),
"minBedrooms": str(min_bedrooms),
"maxBedrooms": str(max_bedrooms),
"apiApplication": "ANDROID",
"appVersion": "3.70.0",
"appVersion": "4.28.0",
}
if len(property_type) > 0:
params["propertyTypes"] = ",".join(property_type)
if max_days_since_added:
if max_days_since_added not in [1, 3, 7, 14]:
if channel is ListingType.BUY:
params["dontShow"] = "sharedOwnership,retirement",
if len(property_type) > 0:
params["propertyTypes"] = ",".join(property_type)
if max_days_since_added is not None and max_days_since_added not in [
1, 3, 7, 14
]:
raise Exception("Invalid max days. Can only be", [1, 3, 7, 14])
params["maxDaysSinceAdded"] = max_days_since_added
if mustNewHome:
params["mustHave"] = "newHome"
if mustNewHome:
params["mustHave"] = "newHome"
headers = {
"Host": "api.rightmove.co.uk",
"Accept-Encoding": "gzip, deflate, br",
"User-Agent": "okhttp/4.12.0",
"Connection": "keep-alive"
}
response = requests.get(
"https://api.rightmove.co.uk/api/property-listing",
params=params,
@ -91,5 +104,3 @@ def listing_query(
raise Exception("Failed due to: ", response.text)
return response.json()