-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_helper.js
More file actions
41 lines (39 loc) · 1.18 KB
/
node_helper.js
File metadata and controls
41 lines (39 loc) · 1.18 KB
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
var NodeHelper = require('node_helper');
const cp = require('child_process');
const path = require('path');
module.exports = NodeHelper.create({
socketNotificationReceived: function (notification, payload) {
if (notification === 'PULL_NEWS') {
const execOptions = {
cwd: __dirname,
encoding: 'utf8',
timeout: 0,
shell: '/bin/bash',
};
const id = payload[0];
const secret = payload[1];
const out = cp.exec(
`/usr/bin/python3 reddit-news-str.py ${id} ${secret}`,
execOptions,
(err, stdout, stderr) => {
this.sendSocketNotification('TITLES', stdout);
console.log(err);
console.log(stderr);
}
);
}
if (notification === 'DOM_OBJECTS_CREATED') {
const data = payload;
const string = data.toString();
const length = string.length;
const time = Math.round(length / 12);
this.sendSocketNotification('TIME', time);
this.joinData(data);
}
},
joinData: function (arr) {
const ray = arr.split('~');
const joined = ray.join('    ::    ');
this.sendSocketNotification('ARR', joined);
},
});