Friday 2 June 2017

Nodejs run python Script with PythonShell

Actually, I can run this python script and this script create csv file when I run it in terminal. However, when I run this in nodejs backend this file cant create a csv file. Where am I making mistakes?

Here is the pythonshell main page : https://github.com/extrabacon/python-shell

var options = {
     mode: 'text',
     scriptPath: './views',
     args: [informations["camera_id"], informations.start_s, informations.start_min, informations.start_h, informations.start_d, informations.start_mon, informations.start_y, informations.end_s, informations.end_min, informations.end_h, informations.end_d, informations.end_mon, informations.end_y]
     };

var pyshell = new PythonShell('historical_inquiry_1.py', options);
     pyshell.on('message', function (message) {
     console.log("script message : ",message);
     });

and here is the python script, (test is an array):

...
with open("test.csv", "w") as text_file:
        text_file.write(test)
...

Actually, I will use this for huge query result. Normal ways result is timeout. Can you please give my fault, our better way to take huge mongodb query result. Thanks in advance.



via Estel

No comments:

Post a Comment