Skip to content

Instantly share code, notes, and snippets.

@SirProdigle
Last active February 20, 2021 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SirProdigle/9d1c444522b2ceb51df6f8072cf17422 to your computer and use it in GitHub Desktop.
Save SirProdigle/9d1c444522b2ceb51df6f8072cf17422 to your computer and use it in GitHub Desktop.
Rightmove Flat Hunter
import requests
import time
import re
from datetime import datetime
from discord_webhook import DiscordWebhook, DiscordEmbed
from bs4 import BeautifulSoup
FROM_MONTH = 7
TO_MONTH = 9
MONTH_LIST = ["july", "august", "september", "jul", "aug", "sep", "sept"]
# Go the the url below and customize settings/location to your liking, only REQUIREMENT is that the time filter is in
# the last day
LIST_URL = "https://www.rightmove.co.uk/property-to-rent/find.html?minBedrooms=1&keywords=&includeLetAgreed=false&dontShow=houseShare%2Cretirement%2Cstudent&channel=RENT&index=0&retirement=false&houseFlatShare=false&sortType=6&minPrice=400&viewType=LIST&maxPrice=1000&radius=1.0&maxDaysSinceAdded=1&locationIdentifier=OUTCODE%5E1688"
# Go to discord server settings -> Integrations -> Webhooks, make a new one and click the copy URL button, fill in here
WEBHOOK_LOG = DiscordWebhook(
"https://discord.com/api/webhooks/811636028662087730/got3PD00DC5Xz0fZZ9n1BJgDHiOLU-PZk1U3cLLMRAFAuvAd10hLuFsX6T6F_c_j50QJ")
WEBHOOK_ERROR = DiscordWebhook(
"https://discord.com/api/webhooks/811658515604963348/1Nxx_ZHlCvr7VnYWMdghKQ8FKjj8lUHwCd8-kYKW9FpoZnmcHH0p9XbnjbMVWAeNmmvN")
PING_STRING = "@everyone"
# Everything below this line does not need to be edited to use
def checkDate(date: str):
if re.match(r"\d{{1,2}}/0[{0}-{1}]".format(FROM_MONTH, TO_MONTH), date):
return {"success": True, "message": date}
elif any(month in date.lower() for month in MONTH_LIST) or (
datetime.now().month >= FROM_MONTH and date.lower() == "now"):
return {"success": True, "message": date}
else:
return {"success": False}
baseURL = "https://www.rightmove.co.uk"
checkListFile = open("./list.txt", "a+", buffering=1)
logFile = open("./log.txt", "a+", buffering=1)
checkListFile.seek(0, 0)
checkList = checkListFile.read().splitlines()
while True:
message = DiscordEmbed(title=datetime.now().strftime("%A %d %B %H:%M"))
discText = ""
response = requests.get(LIST_URL)
soup = BeautifulSoup(response.text, "html.parser")
links = soup.select("a[class='propertyCard-link'][href*='/properties/'][data-test*='property-details']")
toSearch = []
for link in links:
url = link["href"]
if url not in toSearch:
toSearch.append(url)
for url in toSearch:
if url in checkList:
continue
response = requests.get(baseURL + url)
soup = BeautifulSoup(response.text, "html.parser")
element = soup.select('div[class="_2RnXSVJcWbWv4IpBC1Sng6"]')
if element:
try:
if "Let available date" in soup.dt.get_text():
date = soup.dd.get_text()
result = checkDate(date)
if result.get("success"):
discText += baseURL + url + " : " + result["message"] + '\n\n'
except Exception as e:
WEBHOOK_ERROR.content = str(e)
try:
WEBHOOK_ERROR.execute()
except:
pass
checkList.append(url)
checkListFile.write(url + "\n")
# All checked
if discText:
message.description = PING_STRING
message.add_embed_field(name="Properties", value=discText)
WEBHOOK_LOG.content = PING_STRING
WEBHOOK_LOG.add_embed(message)
if WEBHOOK_LOG.execute():
print("sent successfully")
logFile.write(datetime.now().strftime("%d-%m %H:%M") + "sent Webhook")
print(datetime.now().strftime("%d-%m %H:%M") + " check complete\n")
logFile.write(datetime.now().strftime("%d-%m %H:%M") + " check complete\n")
time.sleep(600)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment