MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    Python in module

    Scheduled Pinned Locked Moved Development
    3 Posts 2 Posters 522 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • U Offline
      UjwalReddy267
      last edited by

      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
      		}
      })
      
      
      1 Reply Last reply Reply Quote 0
      • ? Offline
        A Former User
        last edited by

        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

        U 1 Reply Last reply Reply Quote 0
        • U Offline
          UjwalReddy267 @Guest
          last edited by

          @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

          1 Reply Last reply Reply Quote 0

          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
          • 1 / 1
          • First post
            Last post
          Enjoying MagicMirror? Please consider a donation!
          MagicMirror created by Michael Teeuw.
          Forum managed by Sam, technical setup by Karsten.
          This forum is using NodeBB as its core | Contributors
          Contact | Privacy Policy