-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
35 lines (28 loc) · 1.09 KB
/
server.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
let {PythonShell} = require('python-shell')
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const port = process.env.PORT || 5000;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/api/sentiment', (req, res) => {
let pyshell = new PythonShell('TweetScraper/run_and_export.py');
var temp = 'bad reponse from python'
// sends a message to the Python script via stdin
pyshell.send('hello');
pyshell.on('message', function (message) {
// received a message sent from the Python script (a simple "print" statement)
console.log(message);
res.send({ express: message });
});
pyshell.end(function (err,code,signal) {
// if (err) throw err;
console.log('The exit code was: ' + code);
console.log('The exit signal was: ' + signal);
console.log('finished');
console.log('finished');
});
// res.send({ express: temp });
// end the input stream and allow the process to exit
});
app.listen(port, () => console.log(`Listening on port ${port}`));