-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnode_helper.js
58 lines (51 loc) · 1.38 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
46
47
48
49
50
51
52
53
54
55
56
57
58
const NodeHelper = require("node_helper");
var pyshell = require('python-shell');
const sqlite3 = require('sqlite3');
module.exports = NodeHelper.create({
socketNotificationReceived: function (notification, payload) {
if (notification === "START_FAST_NOTES") {
this.config = payload;
this.todoListStart();
setInterval(() => {
this.readDb();
}, this.config.updateInterval);
}
},
todoListStart: function () {
self = this;
var options = {
pythonPath: this.config.pythonPath,
scriptPath: './modules/MMM-FastNotes',
args: [
"--host", this.config.host,
"--port", this.config.port
]
};
pyshell.PythonShell.run('FastNotes.py', options, function (err) {
if (err) throw err;
});
},
readDb: function () {
let db = new sqlite3.Database('./modules/MMM-FastNotes/backend/database.db', sqlite3.OPEN_READWRITE, (err) => {
if (err) {
console.error(err.message);
}
});
let sql = `SELECT title Title,
content Text,
created Date
FROM posts
ORDER BY created`;
db.all(sql, [], (err, rows) => {
if (err) {
throw err;
}
this.sendSocketNotification("DATABASE", rows);
});
db.close((err) => {
if (err) {
console.error(err.message);
}
});
},
});