-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
51 lines (46 loc) · 1.2 KB
/
bot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const http = require("http");
const url = "http://thexlofts.com/";
/** String to find in the page */
const needle = "No units available";
/** SMS Recipient */
const to= "TO_NUMBER",
/** Delay - 24hrs */
const delay = 1000 * 60 * 60 * 24;
/** Twilio */
const from = 'TWILIO_NUMBER'
const accountSid = "accountSid";
const authToken = "authToken";
const client = require("twilio")(accountSid, authToken);
const sendText = (body) => {
console.log(`SMS to ${to}`)
client.messages
.create({
body,
from,
to,
})
.then((message) => console.log("sent", message.sid))
.catch((err) => console.log(err));
};
const main = () => {
console.log(new Date().toDateString());
console.log(`Loading ${url}`);
http
.get(url, (resp) => {
let data = "";
resp.on("data", (chunk) => {
data += chunk;
});
// response complete
resp.on("end", () => {
const found = !data.includes(needle);
const body = `Did I find "${needle}" on ${url} Today?? ${found ? "YES!!!!!!" : "NO!"}`;
console.log(body);
sendText(body);
});
})
.on("error", console.error);
};
const testDelay = 1000 * 10;
main();
setInterval(main, delay);