2

I have implemented an accelerometer Reader in python and I want to execute a function in a javascript file when a new value is read that will:
1 - update the value in a database
2 - broadcast the new value to all connected client ( via Socket.io)

I was wondering how to do it? I checked PyV8 but it seems not maintained and only working with Python 2.7. My files structure looks like

--JScode
----MyJSCode
--PythonCode
----MyPythonCode
Observablerxjs
  • 692
  • 6
  • 22
  • 4
    Possible duplicate of [How do I call a Javascript function from Python?](https://stackoverflow.com/questions/8284765/how-do-i-call-a-javascript-function-from-python) – Ruzihm Sep 18 '18 at 20:04
  • Sounds like an awful headache, but you may be able to get something working with pyqt – SuperStew Sep 18 '18 at 20:05
  • 2
    Can you use Node.js and call the node binary from Python? That's easier than evoking a script in a web browser binary – duhaime Sep 18 '18 at 20:06
  • Actually I'm already using Node.js, my web app is build as a MEAN (Mongo Express Angular Node). can you give me a link to how to do it with the node binary ? thanks – Observablerxjs Sep 18 '18 at 20:08
  • 1
    You can send messages between processes using *pipes*. Just have your node server listen for a message and have your Python program send them. –  Sep 18 '18 at 20:08
  • Have you tried Js2Py? https://github.com/PiotrDabkowski/Js2Py – Valdir Stumm Junior Sep 18 '18 at 20:10
  • 1
    Yes, but from what I understood it's not possible to run a function located in another file with js2Py, all it does is just interpret function passed as strings – Observablerxjs Sep 18 '18 at 20:14

1 Answers1

0

I managed to execute a python script from the javascript file using PythonShell (link to the npm page)

Observablerxjs
  • 692
  • 6
  • 22