-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
77 lines (50 loc) · 1.53 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const express = require('express')
const cors = require('cors')
const app = express()
var PythonShell = require('python-shell');
var fs = require('fs')
var bodyParser = require('body-parser')
app.use( bodyParser.json() ); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));
app.use(cors());
/*
let runPy = new Promise(function(sucess, nosuccess) {
const { spawn } = require('child_process');
const pyprog = spawn('python',['./RunModel.py']);
pyprog.stdout.on('data', function(data) {
sucess(data);
});
pyprog.stderr.on('data', (data) => {
nosuccess(data);
});
});*/
app.post('/', (req, res) => {
var comment = req.body.comnt;
console.log(comment);
/*fs.writeFile('commentinput.txt',comment,function(err){
if (err) {
console.log(err)
}
else
{
console.log('written');
}
})*/
var options = {
mode: 'text',
args: [comment]
};
PythonShell.run('RunModel.py', options, function (err, results) {
if (err) throw err;
// results is an array consisting of messages collected during execution
console.log('results: %j', results);
res.send(results[0])
});
/* runPy.then(function(fromRunpy) {
console.log(fromRunpy.toString());
res.end(fromRunpy);
});*/
})
app.listen(4000, () => console.log('app listening on port 4000!'))