Read the statement by Michael Teeuw here.
Python in module
-
I am trying to run a python code from my node helper file. But, it does not seem to be working
Core file:Module.register("MMM-Rediscover",{ default: {loc: 'modules/MMM-Rediscover/images'}, count : 0, files:[], start : function(){ var self = this self.sendSocketNotification("GET_FILES",self.config.loc) setInterval(function() {self.updateDom()}, 3000); }, getDom : function (){ var wrapper = document.createElement('div') wrapper.id = 'GPHOTO' var img = document.createElement('div') var i = this.count img.style.backgroundImage = 'url(' + this.files[i] + ')' img.id = 'photo' var blr = document.createElement('div') blr.id = 'backgrnd' blr.style.backgroundImage = 'url(' + this.files[i] + ')' wrapper.appendChild(blr) wrapper.appendChild(img) len = this.files.length this.count = (this.count == len-1) ? 0 : this.count+1 return wrapper }, getStyles : function (){ return ['MMM-Rediscover.css'] }, socketNotificationReceived : function(notification , payload){ if(notification == "OBTAINED"){ this.files = payload } } })My node_helper file:
var NodeHelper = require("node_helper") var file = require("fs") const spawn = require("child_process").spawn module.exports = NodeHelper.create({ start : function(){ var process = spawn("python", ["modules/MMM-Rediscover/images/Photos.py"]) process.stdout.on("data", (data)=>{console.log(data)}) }, socketNotificationReceived: function(notification, payload){ if(notification == "GET_FILES"){ var payload = this.getFiles(payload) this.sendSocketNotification("OBTAINED",payload) } }, getFiles : function(loc){ const contents = file.readdirSync(loc) ret = [] for ( var i = 0; i < contents.length; i++){ extension = contents[i].split('.').pop().toLowerCase() if (extension == 'jpg'){ var currentItem = loc + '/' + contents[i] ret.push(currentItem) } } return ret } }) -
hi,
var process = spawn(“python”, [“modules/MMM-Rediscover/images/Photos.py”])
you must give the full path to your python script
This is an example there
-
@Bugsounet I tried giving the full path too, but it did not work
The python script does work on its own, there are no errors in that file
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login