-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathemotions.js
76 lines (63 loc) · 2.36 KB
/
emotions.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
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
/**
* Created by chamod on 4/29/18.
*/
var express = require('express');
var router = express.Router();
var util = require("./util");
var request = require('request');
var PythonShell = require('python-shell');
const EMOTION_HOST = '192.168.8.102'; //'111.223.140.244';
const EMOTION_PORT = 5001;
const {check, validationResult} = require('express-validator/check')
router.get('/', function (req, res) {
util.readJsonFiles('./Data').then(function (json_files) {
res.render('emotions', {files: json_files, req: req});
});
});
router.post('/findEmotions', [
check('message')
.isLength({min: 1})
.withMessage('Review is required'),
], (req, res) => {
const errors = validationResult(req)
if (!errors.isEmpty()) {
return res.render('emotions', {
data: req.body,
errors: errors.mapped(),
})
}
request("http://" + EMOTION_HOST + ":" + EMOTION_PORT + "/emo?tweet='" + req.body.message + "'",
function (error, response, body) {
emotions = []
if (body) {
data = body.toString().replace('[', '').replace(']', '').replace("'", '').split(',');
for (e in data) {
emotions.push(data[e].trim(" ").replace("\"", '').replace("\"", '').replace("\n", ''));
}
}
util.readJsonFiles('./Data').then(function (json_files) {
return res.render('emotions', {
data: req.body,
emotions: emotions,
files: json_files, req: req
})
});
});
})
router.post('/findReviewEmotions', function (req, res) { //111.223.150.141
request("http://" + EMOTION_HOST + ":" + EMOTION_PORT + "/emo?tweet='" + req.body.review + "'",
function (error, response, body) {
console.log('review : ' + req.body.review)
console.log('body : ' + body)
emotions = []
if (body) {
data = body.toString().replace('[', '').replace(']', '').replace("'", '').split(',');
for (e in data) {
emotions.push(data[e].trim(" ").replace("\"", '').replace("\"", '').replace("\n", ''));
}
}
return res.send(emotions);
});
});
//export this router to use in our index.js
module.exports = router;