Skip to content

Instantly share code, notes, and snippets.

@jayne-mast
Last active July 18, 2023 10:17
Show Gist options
  • Save jayne-mast/f77d3907277a34d8b368c2abe4deb4f9 to your computer and use it in GitHub Desktop.
Save jayne-mast/f77d3907277a34d8b368c2abe4deb4f9 to your computer and use it in GitHub Desktop.
Monitor website changes
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