-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_helper.js
45 lines (40 loc) · 1.17 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
38
39
40
41
42
43
44
45
const NodeHelper = require("node_helper");
const fs = require("fs");
var pyshell = require('python-shell');
module.exports = NodeHelper.create({
socketNotificationReceived: function (notification, payload) {
if (notification === "START") {
this.config = payload;
this.kudagoGetData();
setInterval(() => {
this.kudagoGetData();
}, this.config.updateInterval);
}
},
readData: function () {
//read a file with events
fs.readFile("./modules/MMM-KudaGo/kudago/events.json", "utf8", (err, data) => {
if (err) throw err;
this.sendSocketNotification("DATA", data);
});
},
kudagoGetData: function () {
//call python script for collecting events from KudaGo api
self = this;
var options = {
pythonPath: this.config.pythonPath,
scriptPath: './modules/MMM-KudaGo',
mode: 'json',
args: [
"--location", this.config.location,
"--days", this.config.days,
"--categories", this.config.categories,
"--tags", this.config.tags,
]
};
pyshell.PythonShell.run('KudaGo.py', options, function (err) {
if (err) throw err;
});
self.readData();
},
});