-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_helper.js
38 lines (33 loc) · 1.26 KB
/
node_helper.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
const NodeHelper = require("node_helper");
const { exec } = require("child_process");
module.exports = NodeHelper.create({
start: function() {
console.log("Starting helper: " + this.name);
},
socketNotificationReceived: function(notification) {
if (notification === "RUN_COMMAND") {
this.runCommand();
}
},
runCommand: function() {
command = "curl -s http://www.wheeloffortunesolutions.com/spinid.html|grep -i 'meta name=\"date\"' | cut -d= -f3 | tr -d '\">/'";
command = command + "&&" + "curl -s http://www.wheeloffortunesolutions.com/spinid.html|grep -i TableSpinID | sed 's/<[^>]*>//g' | awk '{$1=$1};1' | grep -v '^[[:space:]]*$' | head -3 | tr '\r\n' ',' | sed -r 's/[,,]+/,/g'";
exec(command, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
this.sendSocketNotification("COMMAND_OUTPUT", `Error: ${error.message}`);
return;
}
if (stderr) {
console.error(`stderr: ${stderr}`);
this.sendSocketNotification("COMMAND_OUTPUT", `Error: ${stderr}`);
return;
};
[date, spinids] = stdout.split('\r\n');
this.sendSocketNotification("COMMAND_OUTPUT", {
date: date,
spinIds: spinids
});
});
},
});