-
Notifications
You must be signed in to change notification settings - Fork 2
/
places.js
56 lines (49 loc) · 1.64 KB
/
places.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
/**
* Created by chamod on 4/29/18.
*/
var express = require('express');
var router = express.Router();
var util = require("./util");
var aspect_analyzer = require("./aspect_analyzer");
var emotion_analyzer = require("./emotion_analyzer");
var fs = require("fs");
router.get('/:place_name*?', function (req, res) {
util.readJsonFiles('./tripadvisor-scraper/').then(function (review_files) {
util.readJsonFiles('./Data/').then(function (json_files) {
res.render('places', {
files: json_files,
review_files: review_files,
req: req,
place_name: req.params.place_name
});
});
});
});
router.post('/reviews', function (req, res) {
fs.readFile('./tripadvisor-scraper/' + req.body.place + ".json", function (err, review_data) {
if (err) {
return res.send(err);
}
review_data = JSON.parse(review_data);
aspect_analyzer.findPopularAspects(review_data).then(function (data) {
var obj = {
aspects: data,
reviews: review_data
};
console.log(data);
emotion_analyzer.findPopularEmotions(review_data).then(function (emotion_data) {
obj.emotions = emotion_data;
return res.send(obj);
}, function (err) {
console.log(err);
return res.send(err);
});
}, function (err) {
console.log(err);
return res.send(err);
});
// console.log(temp);
})
});
//export this router to use in our index.js
module.exports = router;