-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
70 lines (56 loc) · 1.63 KB
/
index.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const Browser = require("zombie");
const express = require("express");
const STATUS = {
FAIL: "FAIL",
OK: "OK"
};
const VISIT_INTERVAL = 12 * 60 * 60 * 1000;
const HISTORY = [];
// Stop all JS requests, easier than polyfilling zombie/jsdom
Browser.runScripts = false;
function log(status, url, err) {
if (status === STATUS.FAIL) {
console.error(STATUS.FAIL, err, url);
} else {
console.info(STATUS.OK, url);
}
const date = new Date().toString();
const logData = { status, url, err, date, timestamp: Date.now() };
HISTORY.push(logData);
}
function visit() {
const browser = new Browser();
return browser.visit("https://stackoverflow.com/users/login", async () => {
console.log(
"Attempting login with:",
process.env.email,
process.env.password
);
try {
await Promise.all([
browser.fill("email", process.env.email),
browser.fill("password", process.env.password)
]);
await browser.pressButton("#submit-button");
await browser.clickLink(".my-profile");
if (browser.location.href.includes(process.env.userid)) {
log(STATUS.OK, browser.location.href);
} else {
log(STATUS.FAIL, browser.location.href, err);
}
} catch (err) {
log(STATUS.FAIL, browser.location.href, err);
}
});
}
visit();
setInterval(visit, VISIT_INTERVAL);
const app = express();
app.use(express.static("public"));
app.set("port", process.env.PORT || 3000);
app.get("/", (appReq, appRes) => {
appRes.json(HISTORY);
});
app.listen(app.get("port"), function() {
console.log("Fanatic running on port", `http://localhost:${app.get("port")}`);
});