Search.js
4.31 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
var express = require('express');
var app = express();
var client_id = 'cnS9zzj0OZ3xPgHqtaLJ';
var client_secret = 'oQGaxdr7aq';
//data parsing
var data='';
var title='';
var link='';
var category='';
var address='';
var roadAddress='';
//받아와야할 데이터
var chatbotaddress={ //chatbot의 위치 데이터 (json)
"type":"location",
"id":13100,
"title":"성수역",
"address":"성동구 아차산로"
};
var cfrdata={
"info": {
"size": {
"width": 900,
"height": 1349
},
"faceCount": 1
},
"faces": [{
"roi": {
"x": 235,
"y": 227,
"width": 326,
"height": 326
},
"landmark": {
"leftEye": {
"x": 311,
"y": 289
},
"rightEye": {
"x": 425,
"y": 287
},
"nose": {
"x": 308,
"y": 346
},
"leftMouth": {
"x": 306,
"y": 425
},
"rightMouth": {
"x": 383,
"y": 429
}
},
"gender": {
"value": "male",
"confidence": 0.91465
},
"age": {
"value": "22~26",
"confidence": 0.742265
},
"emotion": {
"value": "smile",
"confidence": 0.460465
},
"pose": {
"value": "frontal_face",
"confidence": 0.937789
}
}]
}
var cfrgender=cfrdata.faces[0].gender.value; //CFR의 성별 데이터 (json)
var cfremotion=cfrdata.faces[0].emotion.value; //CFR의 감정 데이터 (json)
//위치 데이터에서 필요한 부분만 자르기
var chatbotdata1=chatbotaddress.address;
var chatbotdata2=chatbotdata1.split(' ');
var chatbotAddress=chatbotdata2[0];
var place = chatbotAddress; //사용자 위치
var gender = cfrgender; //사용자 성별
var emotion = cfremotion; //사용자 감정
var menu='';
if(gender=='male'){
if(emotion=='angry'){
menu='술';
}
else if(emotion=='disgust'){
menu='야식';
}
else if(emotion=='fear'){
menu='한식';
}
else if(emotion=='laugh'){
menu='치킨';
}
else if(emotion=='neutral'){
menu='양식';
}
else if(emotion=='sad'){
menu='중식';
}
else if(emotion=='surprise'){
menu='일식';
}
else if(emotion=='smile'){
menu='고기';
}
else if(emotion=='talking'){
menu='술';
}
else{
menu='';
}
}
else if(gender=='female'){
if(emotion=='angry'){
menu='고기';
}
else if(emotion=='disgust'){
menu='디저트';
}
else if(emotion=='fear'){
menu='한식';
}
else if(emotion=='laugh'){
menu='일식';
}
else if(emotion=='neutral'){
menu='중식';
}
else if(emotion=='sad'){
menu='야식';
}
else if(emotion=='surprise'){
menu='중식';
}
else if(emotion=='smile'){
menu='치킨';
}
else if(emotion=='talking'){
menu='카페';
}
else{
menu='';
}
}
else{
menu='';
}
var query= place + ' ' + menu + ' 맛집'; //검색 원하는 문자열
var display = '1'; //검색 결과 출력 건수. 최대 5개
var start = '1'; //검색 시작 위치. 1만 가능
var sort = 'comment'; //정렬 옵션 (random : 유사도순, comment : 카페/블로그 리뷰 개수 순)
app.get('/search/local', function (req, res) {
var api_url = 'https://openapi.naver.com/v1/search/local?query=' + encodeURI(query)+ '&display='+encodeURI(display) + '&start='+encodeURI(start)+'&sort='+encodeURI(sort);
var request = require('request');
var options = {
url: api_url,
headers: {'X-Naver-Client-Id':client_id, 'X-Naver-Client-Secret': client_secret}
};
request.get(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
res.writeHead(200, {'Content-Type': 'text/json;charset=utf-8'});
console.log(body);
//데이터 파싱
data=JSON.parse(body);
title=data.items[0].title;
console.log(title);
link=data.items[0].link;
console.log(link);
category=data.items[0].category;
console.log(category);
address=data.items[0].address;
console.log(address);
roadAddress=data.items[0].roadAddress;
console.log(roadAddress);
res.end(body);
} else {
res.status(response.statusCode).end();
console.log('error = ' + response.statusCode);
}
});
});
app.listen(3000, function () {
console.log('app listening on port 3000!');
console.log(query);
});