Skip to content

Commit

Permalink
Add ability to filter by specific date
Browse files Browse the repository at this point in the history
  • Loading branch information
JordWyatt committed Dec 18, 2022
1 parent f800259 commit 4afd07c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ To configure a search, create `configuration.ini` and edit as required:
locationIdentifiers - Comma seperated RightMove location identifiers, you can grab this from your target search URL in a browser
[filters]
availableAfterNWeeks - The number of weeks until you need to move, only properties available after this date will be returned
availableAfter - The date you want to filter properties by, only properties available on or after this date will be returned
availableAfterNWeeks - (OVERRIDES availableAfter) The number of weeks until you need to move, only properties available after this date will be returned
radius - Radius in miles
minPrice - Minimum Price
maxPrice - Maximum Price
Expand Down Expand Up @@ -53,6 +54,7 @@ identifiers = REGION^93802,REGION^87521
[filters]
availableAfterNWeeks = 7
# availableAfter = 01/01/2023
radius=1
minPrice = 0
maxPrice = 1500
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ rsa==4.2
six==1.15.0
soupsieve==2.0.1
toml==0.10.1
typed-ast==1.4.1
typed-ast==1.5.4
urllib3==1.25.9
wrapt==1.12.1
25 changes: 23 additions & 2 deletions rightmove_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class RightmoveScraper:
def __init__(self):
self.base_url = "https://rightmove.co.uk"
# Default to 24 hour period for now, don't show let agreed
self.base_search_url = self.base_url + \
"/property-to-rent/find.html?maxDaysSinceAdded=1&_includeLetAgreed=false&"
self.base_search_url = self.base_url + "/property-to-rent/find.html?_includeLetAgreed=false&"
self.sheet = Sheet(service_account_configuration_path, sheet_name)

def build_search_url(self, location_identifier):
Expand Down Expand Up @@ -55,6 +54,26 @@ def convert_date(x):
available_after = (today + delta)
return [listing for listing in listings if listing.has_date_available() and convert_date(listing.date_available) > available_after]

def get_listings_available_after_date(self, date_str, listings):
if(not len(listings)):
return listings

print(
f'Filtering listings down only those available after {date_str}'
)

def convert_date(x):
return datetime.datetime.strptime(x, "%d/%m/%Y").date()

date = convert_date(date_str)
today = datetime.datetime.now().date()

return [
listing for listing in listings if
(listing.has_date_available() and convert_date(listing.date_available) >= date) or
(listing.date_available == "Now" and today >= date)
]

def get_location_name(self, dom):
title = dom.title.string
result = re.search(r".*Rent in (.*) \|", title)
Expand Down Expand Up @@ -89,6 +108,8 @@ def filter_listings(self, listings):
if(config.has_option("filters", "availableAfterNWeeks")):
listings = self.get_listings_available_after_n_weeks(
int(config.get("filters", "availableAfterNWeeks")), listings)
elif(config.has_option("filters", "availableAfter")):
listings = self.get_listings_available_after_date(config.get("filters", "availableAfter"), listings)
return listings

def scrape_listings(self, location_identifiers):
Expand Down

0 comments on commit 4afd07c

Please sign in to comment.