-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
36 lines (30 loc) · 987 Bytes
/
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
var express = require('express');
var PythonShell = require('python-shell');
var cors = require('cors');
var path = require('path');
var app = express();
app.use(cors())
app.use(express.static(__dirname));
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname + '/index.html'));
});
app.get('/predict', predict);
function predict (request, response) {
console.log("Predict")
var options = {
mode: 'text',
pythonOptions: ['-u'], // get print results in real-time
args: [request.query.dt, request.query.weather, request.query.temp, request.query.humidity, request.query.windspeed]
};
var results;
PythonShell.run('test.py', options, function (err, res) {
if (err) throw err;
//res is an array consisting of messages collected during execution
results = res[0].replace('\r','');
console.log(res);
response.json({"prediction" : results});
});
}
app.listen(3000, function () {
console.log('Server running on port 3000');
})