<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Python in module]]></title><description><![CDATA[<p dir="auto">I am trying to run a python code from my node helper file. But, it does not seem to be working<br />
Core file:</p>
<pre><code>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
			}
		}
})

</code></pre>
<p dir="auto">My node_helper file:</p>
<pre><code>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)=&gt;{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 &lt; contents.length; i++){
				extension = contents[i].split('.').pop().toLowerCase()
				if (extension == 'jpg'){
					var currentItem = loc + '/' + contents[i]
					ret.push(currentItem)
				}
			}
			return ret
		}
})

</code></pre>
]]></description><link>https://forum.magicmirror.builders/topic/13217/python-in-module</link><generator>RSS for Node</generator><lastBuildDate>Thu, 18 Jun 2026 04:58:22 GMT</lastBuildDate><atom:link href="https://forum.magicmirror.builders/topic/13217.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 06 Jul 2020 18:20:59 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Python in module on Tue, 07 Jul 2020 05:55:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bugsounet" aria-label="Profile: Bugsounet">@<bdi>Bugsounet</bdi></a>  I tried giving the full path too, but it did not work<br />
The python script does work on its own, there are no errors in that file</p>
]]></description><link>https://forum.magicmirror.builders/post/78156</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/78156</guid><dc:creator><![CDATA[UjwalReddy267]]></dc:creator><pubDate>Tue, 07 Jul 2020 05:55:48 GMT</pubDate></item><item><title><![CDATA[Reply to Python in module on Mon, 06 Jul 2020 18:31:17 GMT]]></title><description><![CDATA[<p dir="auto">hi,</p>
<blockquote>
<p dir="auto">var process = spawn(“python”, [“modules/MMM-Rediscover/images/Photos.py”])</p>
</blockquote>
<p dir="auto">you must give the full path to your python script</p>
<p dir="auto">This is an example <a href="https://github.com/bugsounet/MMM-Assistant2Display/blob/dev/node_helper.js#L205" target="_blank" rel="noopener noreferrer nofollow ugc">there</a></p>
]]></description><link>https://forum.magicmirror.builders/post/78150</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/78150</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Mon, 06 Jul 2020 18:31:17 GMT</pubDate></item></channel></rss>