From a9b8d4d630f42ccea19e222e9e9b3d0803ccedb3 Mon Sep 17 00:00:00 2001 From: Kadir Date: Wed, 13 Mar 2024 16:21:54 +0000 Subject: [PATCH] adding musthave and lastXdays --- crawler/proof_of_concept/listings.py | 1 + crawler/proof_of_concept/utils.py | 17 ----------------- crawler/rec/query.py | 9 ++++++++- 3 files changed, 9 insertions(+), 18 deletions(-) delete mode 100644 crawler/proof_of_concept/utils.py diff --git a/crawler/proof_of_concept/listings.py b/crawler/proof_of_concept/listings.py index a1a8b5c..60b47da 100644 --- a/crawler/proof_of_concept/listings.py +++ b/crawler/proof_of_concept/listings.py @@ -16,6 +16,7 @@ params = { 'sortBy': 'distance', 'includeUnavailableProperties': 'false', 'propertyTypes': 'flat', + 'mustHave': 'newHome', # added manually later 'dontShow': 'sharedOwnership,retirement', 'minPrice': '150000', 'maxPrice': '500000', diff --git a/crawler/proof_of_concept/utils.py b/crawler/proof_of_concept/utils.py deleted file mode 100644 index 8140720..0000000 --- a/crawler/proof_of_concept/utils.py +++ /dev/null @@ -1,17 +0,0 @@ -from datetime import datetime, timedelta, timezone - -def nextMonday(): - """ - I think this function doesnt work when the day is monday itself. - - Returns: - _type_: _description_ - """ - now = datetime.now(timezone.utc) - days_until_monday = (0 - now.weekday() + 7) % 7 - monday = now + timedelta(days=days_until_monday) - monday_9am = monday.replace(hour=9, minute=0, second=0, microsecond=0, tzinfo=timezone.utc) - return monday_9am - -if __name__ == '__main__': - print(nextMonday()) diff --git a/crawler/rec/query.py b/crawler/rec/query.py index 657fe76..410de18 100644 --- a/crawler/rec/query.py +++ b/crawler/rec/query.py @@ -30,7 +30,7 @@ def detail_query(detail_id: int): # @cache.memoize() -def listing_query(page: int, min_bedrooms: int, max_bedrooms: int, radius: float, min_price: int, max_price: int) -> dict: +def listing_query(page: int, min_bedrooms: int, max_bedrooms: int, radius: float, min_price: int, max_price: int, mustNewHome: bool = False, max_days_since_added: int = None) -> dict: params = { "locationIdentifier": "POSTCODE^4228216", "channel": "BUY", @@ -48,6 +48,13 @@ def listing_query(page: int, min_bedrooms: int, max_bedrooms: int, radius: float "apiApplication": "ANDROID", "appVersion": "3.70.0", } + 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]) + params['maxDaysSinceAdded'] = max_days_since_added + + if mustNewHome: + params['mustHave'] = 'newHome' response = requests.get( "https://api.rightmove.co.uk/api/property-listing",