index.js
983 Bytes
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
var express = require('express');
var router = express.Router();
const { PythonShell } = require('python-shell');
var pyshell = new PythonShell("all_data.py");
/* GET home page. */
router.get('/', function(req, res ) {
res.render('index');
});
router.post('/', function(req,res){
console.log(req.body.userid); // req.body.userid를 받아옴
pyshell.send(JSON.stringify(req.body.userid));//the problem function
pyshell.on('message', function (row) {
// received a message sent from the Python script (a simple "print" statement)
console.log(row);
return res.render('show', { userid:req.body.userid, data:JSON.parse(row)});
});
// end the input stream and allow the process to exit
pyshell.end(function (err,) {
if (err){
throw err;
};
console.log('finished');
});
});
router.get('show', function (req,res){
console.log(row);
res.render('show' ,{userid:req.body.userid, data:row});
});
module.exports = router;