app.js 1.62 KB
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});
    }
  })
});