app.js
1.62 KB
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
77
78
79
var jsdom = require("jsdom");
const { JSDOM } = jsdom;
const { window } = new JSDOM();
const { document } = (new JSDOM('')).window;
var $ = jQuery = require('jquery')(window);
var express = require('express');
var app = express();
const bodyParser = require('body-parser');
app.set("view engine","ejs");
app.use(express.static(__dirname + '/public'));
app.get("/", function(req,res){
res.render("index", {low:arr[0],middle:arr[1],high:arr[2],ment:ment, cloth:cloth});
});
app.get("/data", function(req, res) {
res.send({
low: arr[0],
middle: arr[2],
high: arr[1],
ment: ment,
cloth: cloth
});
});
app.listen(8080, function(){
console.log('Server On!');
});
const {PythonShell} = require('python-shell');
var options = {
mode: 'text',
pythonOptions: ['-u'],
scriptPath: '',
encoding: 'utf8',
args: ["영통1동"]
};
/*
var arr = new Array();
var test = new PythonShell('recommend_clothes.py', options);
var data;
test.send(data);
test.on('message',function(message){
arr.push(message);
console.log(arr);
})
*/
var arr = new Array(1, 2, 3);
var clothes;
var cloth = new Array();
var ment = "";
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.post("/location", function(req, res){
while(arr.length){
arr.pop();
}
var data = req.body.location;
var test = new PythonShell('recommend_clothes.py', options);
test.send(data);
test.on('message',function(message){
arr.push(message);
console.log(arr);
if(arr.length == 5){
ment = arr[4];
clothes = arr[3];
cloth = clothes.split(',');
res.json({ok:true});
}
})
});