• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
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 script into MagicMirror module

Scheduled Pinned Locked Moved Hardware
4 Posts 2 Posters 3.9k 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.
  • S Offline
    sureshkocherla
    last edited by Nov 17, 2017, 9:33 AM

    Hi, I want to run the python script into MagicMirror module. Kindly give the solution to my requirement.

    ? 1 Reply Last reply Nov 17, 2017, 9:41 AM Reply Quote 0
    • ? Offline
      A Former User @sureshkocherla
      last edited by Nov 17, 2017, 9:41 AM

      @sureshkocherla
      You can execute an external program with Child Process of node.js. After reading this, create or modify your module.
      https://nodejs.org/api/child_process.html

      1 Reply Last reply Reply Quote 0
      • S Offline
        sureshkocherla
        last edited by Nov 17, 2017, 9:57 AM

        Hi, Sean Thanks for your valuable reply,
        I have one python script. I want to create a new custom module for the requirement and also run this python script automatically in the module.
        Kindly guide me.

        ? 1 Reply Last reply Nov 17, 2017, 10:21 AM Reply Quote 0
        • ? Offline
          A Former User @sureshkocherla
          last edited by Nov 17, 2017, 10:21 AM

          @sureshkocherla
          Ok, Let’s see the example.
          MMM-Tools is using several external shell scripts in the module.
          https://github.com/eouia/MMM-Tools

          See the node_helpers.js (https://github.com/eouia/MMM-Tools/blob/master/node_helper.js)
          First, Child process could not be used on the frontend, so you need to build node_helpers.js for it.

          in line 10

          var exec = require('child_process').exec
          

          child_proces.exec is declared to use. You might need other methods like spawn or fork for your purpose.

          in line 123.

          getIP : function() {
              exec (this.scripts['IP'], (err, stdout, stderr)=>{
                if (err == null) {
                  var matched = stdout.trim().match(/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/)
                  this.status['IP'] = (matched) ? matched[0] : "Unknown"
                }
              })
            },
          

          this is all for your using exec.

          exec ("your command", function callback(error, outputonsuccess, outputonerr) {
             console.log(error, outputonsuccess, outputonerror)
          })
          

          Try this in your module.

          ※ child_process.exec is a just simple method to get result of external command. But when you need more complexed function, you could consider spawn or fork or execFile instead exec

          https://dzone.com/articles/understanding-execfile-spawn-exec-and-fork-in-node
          this doc will be help.

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          1 / 1
          • First post
            1/4
            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