-
Notifications
You must be signed in to change notification settings - Fork 2
/
node_helper.js
46 lines (41 loc) · 1.34 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
var NodeHelper = require('node_helper');
var PythonShell = require('python-shell');
var colors = require('colors');
module.exports = NodeHelper.create({
start: function() {
this.config = null;
},
socketNotificationReceived: function(notification, payload) { // Payload is 'request' from MMM-CTA
var self = this;
if (notification === "GET-MFP-DATA" ) {
self.config = payload;
self.getData(payload);
console.log("GOT notify in node_helper");
console.log(process.cwd());
}
},
getData: function(payload) {
console.log("Running MFP get data"); // for debugging
var self = this;
var resultSend = {};
var options = {
mode: 'json',
pythonPath: '/usr/bin/python',
scriptPath: './modules/MMM-MyFitnessPal/python',
// scriptPath: '/home/pi/MagicMirror/modules/MMM-MyFitnessPal',
args: [payload.user, payload.passw]
}
const mfpPyShell = new PythonShell('mfp_getdata.py', options);
mfpPyShell.on('message', function(message) {
console.log(message);
self.testvar = message;
self.sendSocketNotification("MY-MFP-DATA", message);
});
mfpPyShell.end(function (err) {
if (err) throw err;
console.log('Finished getting MFP data');
});
},
//For python get data, send each dict value to stdout, receive as array and parse
// See: https://www.npmjs.com/package/python-shell for python shell processing
});