How to use python-shell - 10 common examples

To help you get started, we’ve selected a few python-shell examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github justinmoon / junction / index.js View on Github external
function createWindow () {
  // run junction
  PythonShell.run('electron.py', {}, function  (err, results)  {
   if  (err)  console.log(err);
  });

  // open browser windows, visit junction
  window = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nativeWindowOpen: true,
    },
  })

  window.webContents.on('new-window', (event, url, frameName, disposition, options, additionalFeatures) => {
    if (frameName === 'modal') {
      // open window as modal
      event.preventDefault()
github geojacobm6 / keyword_finder / js / main.js View on Github external
(async () => {
        let port = await getPort()
        let script = getScriptPath()
        global.port = port;
        var options = {
          args: [port]
        };
        console.log(script)
        console.log(script)
        if (guessPackaged()) {
            global.py_proc = require('child_process').execFile(script, [port])
        } else {
            global.py_proc = PythonShell.run(script, options,  function  (err, results)  {
             if  (err)  console.log(err);
            });
        }
//        PythonShell.run('./backend/engine.py', options,  function  (err, results)  {
//         if  (err)  console.log(err);
//        });

        window = new BrowserWindow({width: 800, height: 600,
                                    frame: true,
                                    webPreferences: {
                                        webSecurity: false,
                                        plugins: true
                                        },
                                    });
//        window.webContents.openDevTools()
github senthilchandrasegaran / textplorer / textplorer.js View on Github external
app.post('/infoContent', function(req, res) {
    // invoke this just once, and send all the data over to the client.
    // This will make the code more responsive.
    // var infoContentParams = req.body;
    var pyShell = new PythonShell('infoContent.py', options)
    // pyShell.send(req.body.data);
    // send the transcript text to the python shell
    pyShell.send(outputtrans.target);
    pyShell.on('message', function(message) {
        infoContentDict = message
        console.log(infoContentDict)
        res.status(200).send({data: infoContentDict});
        // res.send(200, {data: infoContentDict});
        // outputInfoContent.target = infoContentParams.infoContent;
    });
    pyShell.end(function(err) {
        if (err) throw err;
    });
});
github nischi / MMM-Face-Reco-DNN / node_helper.js View on Github external
'--method=' + this.config.method,
        '--detectionMethod=' + this.config.detectionMethod,
        '--interval=' + this.config.checkInterval,
        '--output=' + this.config.output,
        '--extendDataset=' + extendedDataset,
        '--dataset=' + this.config.dataset,
        '--tolerance=' + this.config.tolerance
      ],
    };

    if (this.config.pythonPath != null && this.config.pythonPath !== '') {
      options.pythonPath = this.config.pythonPath;
    }

    // Start face reco script
    self.pyshell = new PythonShell(
      'modules/' + this.name + '/tools/facerecognition.py',
      options
    );

    // check if a message of the python script is comming in
    self.pyshell.on('message', function(message) {
      // A status message has received and will log
      if (message.hasOwnProperty('status')) {
        console.log('[' + self.name + '] ' + message.status);
      }

      // Somebody new are in front of the camera, send it back to the Magic Mirror Module
      if (message.hasOwnProperty('login')) {
        console.log(
          '[' +
            self.name +
github havardh / workflow / packages / workflow-wm-wmctrl / src / index.js View on Github external
return new Promise((resolve, reject) => {
      const options = {
        args: app.open.split(' '),
        pythonPath: '/usr/bin/python',
        mode: 'json',
      };
      const script = new PythonShell('wms/windows/open.py', options);

      script.on('message', data => {
        resolve(data.pid);
      });
      script.on('error', error => {
        reject(error);
      });
      script.end(() => {
        // resolve(pid);
      });
    });
  }
github krpeacock / google_home_starter / app.js View on Github external
this.setState = function(state) {
    var str = state === "on" ? onString(this.id[2]) : offString(this.id[2]);
    PythonShell.run(str, function(err) {
      if (!process.env.DEV) {
        if (err) throw err;
      }
    });
    this.state = state;
  };
  // Invokes setState on init to set the switch to its last recalled state.
github WasabiFan / ev3dev-lang-js / test / test-utils.js View on Github external
module.exports.cleanArena = function (callback) {
    PythonShell.run(path.join(fakeSysRootDir, "/clean_arena.py"), function (err) {
        if (err) throw err;

        callback();
    });
}
github lovell / cc / bin / cpplint.js View on Github external
args.push("--filter");
      args.push(
        config.filter
          .map(function(filter) {
            return `-${filter}`;
          })
          .join(",")
      );
    }
    const cppLintOptions = {
      pythonPath,
      scriptPath: __dirname,
      args: args.concat(files)
    };

    PythonShell.run("cpplint.py", cppLintOptions, function(err) {
      if (err) {
        console.error(err.message);
        process.exit(1);
      }
    });
  } else {
    console.error(`No files found matching ${config.files.join(", ")}`);
    process.exit(1);
  }
});
github jean-emmanuel / open-stage-control / src / server / midi.js View on Github external
static list() {

        var pythonPath = settings.read('midi') ? settings.read('midi').filter(x=>x.includes('path=')).map(x=>x.split('=')[1])[0] : undefined

        PythonShell.run('python/list.py', Object.assign({pythonPath}, pythonOptions), function(err, results) {
            if (err) console.error(err)
            MidiConverter.parseIpc(results)
        })

    }
github midorineko / rpi_automation / app.js View on Github external
});
	}else if(req.params.switch == "off"){
		var options = {
		  args: ['off']
		};
		PythonShell.run('livolo.py', options, function (err) {
			res.statusCode = 302;
			res.setHeader("Location", "/scenes");
			res.end();
		});
	}else{
		var options = {
		  args: [req.params.switch.toLowerCase()]
		};
		inputArgs=req.params.switch.toLowerCase()
		PythonShell.run('scene_main.py', options, function (err) {
			  res.statusCode = 302;
			  var myarr = ['led_off', 'lights_off', 'lights_on', 'all_off', 'led_off', 'led_on'];
			  var route_main = (myarr.indexOf(inputArgs) > -1);
			  if(route_main){
				res.setHeader("Location", "/");
			  }else{
			  	res.setHeader("Location", "/lights/off");
			  }
			  res.end();
			console.log(err)

		});
	}
});

python-shell

Run Python scripts from Node.js with simple (but efficient) inter-process communication through stdio

MIT
Latest version published 1 year ago

Package Health Score

70 / 100
Full package analysis