Last active
July 18, 2023 10:17
-
-
Save jayne-mast/f77d3907277a34d8b368c2abe4deb4f9 to your computer and use it in GitHub Desktop.
Monitor website changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require("axios"); | |
const nodemailer = require("nodemailer"); | |
const urlToCheck = "SOME_URL"; | |
const textToCheck = "Text on page"; | |
const checkingFrequencyInSeconds = 15; | |
const emailAddress = "YOUR_GMAIL_EMAIL"; | |
const gmailPassword = "YOUR_PASSWORD"; | |
function sendMail() { | |
var transporter = nodemailer.createTransport({ | |
service: "gmail", | |
auth: { | |
user: emailAddress, | |
pass: gmailPassword, | |
}, | |
}); | |
var mailOptions = { | |
from: emailAddress, | |
to: emailAddress, | |
subject: "Parking tickets!", | |
text: urlToCheck, | |
}; | |
transporter.sendMail(mailOptions, function (error, info) { | |
if (error) { | |
console.log(error); | |
} else { | |
console.log("Email sent: " + info.response); | |
} | |
}); | |
} | |
let interval; | |
interval = setInterval(() => { | |
axios.get(urlToCheck).then((res) => { | |
const hasText = res.data.includes(textToCheck); | |
if (hasText) { | |
console.log("now!"); | |
sendMail(); | |
} else { | |
console.log("not yet..."); | |
} | |
}); | |
}, checkingFrequencyInSeconds * 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment