Showing
2 changed files
with
66 additions
and
12 deletions
... | @@ -86,7 +86,7 @@ function handleEvent(event) { | ... | @@ -86,7 +86,7 @@ function handleEvent(event) { |
86 | return; | 86 | return; |
87 | } | 87 | } |
88 | }); | 88 | }); |
89 | - | 89 | + |
90 | return new Promise(function(resolve, reject) | 90 | return new Promise(function(resolve, reject) |
91 | { | 91 | { |
92 | var result = { type: 'text', text:''}; | 92 | var result = { type: 'text', text:''}; |
... | @@ -125,7 +125,7 @@ function handleEvent(event) { | ... | @@ -125,7 +125,7 @@ function handleEvent(event) { |
125 | 125 | ||
126 | console.log(songList[userNum].song); | 126 | console.log(songList[userNum].song); |
127 | console.log(lyric); | 127 | console.log(lyric); |
128 | - | 128 | + |
129 | //papago 언어 감지 | 129 | //papago 언어 감지 |
130 | request.post(detect_options, (error,response,body)=> | 130 | request.post(detect_options, (error,response,body)=> |
131 | { | 131 | { |
... | @@ -135,10 +135,10 @@ function handleEvent(event) { | ... | @@ -135,10 +135,10 @@ function handleEvent(event) { |
135 | var source = ''; | 135 | var source = ''; |
136 | var target = ''; | 136 | var target = ''; |
137 | var result = { type: 'text', text:''}; | 137 | var result = { type: 'text', text:''}; |
138 | - | 138 | + |
139 | //언어 감지가 제대로 됐는지 확인 | 139 | //언어 감지가 제대로 됐는지 확인 |
140 | console.log(detect_body.langCode); | 140 | console.log(detect_body.langCode); |
141 | - | 141 | + |
142 | //번역은 한국어->영어 / 영어->한국어만 지원 | 142 | //번역은 한국어->영어 / 영어->한국어만 지원 |
143 | if(detect_body.langCode == 'ko'||detect_body.langCode == 'en') | 143 | if(detect_body.langCode == 'ko'||detect_body.langCode == 'en') |
144 | { | 144 | { |
... | @@ -151,7 +151,7 @@ function handleEvent(event) { | ... | @@ -151,7 +151,7 @@ function handleEvent(event) { |
151 | form: {'source':source, 'target':target, 'text': lyric}, | 151 | form: {'source':source, 'target':target, 'text': lyric}, |
152 | headers: {'X-Naver-Client-Id': client_id, 'X-Naver-Client-Secret': client_secret} | 152 | headers: {'X-Naver-Client-Id': client_id, 'X-Naver-Client-Secret': client_secret} |
153 | }; | 153 | }; |
154 | - | 154 | + |
155 | // Naver Post API | 155 | // Naver Post API |
156 | request.post(options, function(error, response, body){ | 156 | request.post(options, function(error, response, body){ |
157 | // Translate API Sucess | 157 | // Translate API Sucess |
... | @@ -159,7 +159,7 @@ function handleEvent(event) { | ... | @@ -159,7 +159,7 @@ function handleEvent(event) { |
159 | // JSON | 159 | // JSON |
160 | var objBody = JSON.parse(response.body); | 160 | var objBody = JSON.parse(response.body); |
161 | // Message 잘 찍히는지 확인 | 161 | // Message 잘 찍히는지 확인 |
162 | - | 162 | + |
163 | result.text = objBody.message.result.translatedText; | 163 | result.text = objBody.message.result.translatedText; |
164 | console.log("result: "+result.text); | 164 | console.log("result: "+result.text); |
165 | //번역된 문장 보내기 | 165 | //번역된 문장 보내기 |
... | @@ -183,7 +183,7 @@ function handleEvent(event) { | ... | @@ -183,7 +183,7 @@ function handleEvent(event) { |
183 | }); | 183 | }); |
184 | } | 184 | } |
185 | else if (event.message.text.indexOf('http')!=-1) { | 185 | else if (event.message.text.indexOf('http')!=-1) { |
186 | - return new Promise(async(resolve,reject)=>{ | 186 | + return new Promise(async(resolve,reject)=>{ |
187 | var uriBase = 'https://koreacentral.api.cognitive.microsoft.com/vision/v2.1/ocr'; | 187 | var uriBase = 'https://koreacentral.api.cognitive.microsoft.com/vision/v2.1/ocr'; |
188 | var imageUrl=event.message.text; | 188 | var imageUrl=event.message.text; |
189 | var options = { | 189 | var options = { |
... | @@ -198,9 +198,9 @@ function handleEvent(event) { | ... | @@ -198,9 +198,9 @@ function handleEvent(event) { |
198 | }, | 198 | }, |
199 | body:'{"url": ' + '"' + imageUrl + '"}', | 199 | body:'{"url": ' + '"' + imageUrl + '"}', |
200 | }; | 200 | }; |
201 | - | 201 | + |
202 | request.post(options, function (error, response, body) { | 202 | request.post(options, function (error, response, body) { |
203 | - var data=JSON.stringify(body); | 203 | + var data=JSON.stringify(body); |
204 | console.log(data); | 204 | console.log(data); |
205 | var text=''; | 205 | var text=''; |
206 | while(data.indexOf('text\\')!=-1) | 206 | while(data.indexOf('text\\')!=-1) |
... | @@ -218,7 +218,7 @@ function handleEvent(event) { | ... | @@ -218,7 +218,7 @@ function handleEvent(event) { |
218 | console.log(url); | 218 | console.log(url); |
219 | var $ = cheerio.load(html); | 219 | var $ = cheerio.load(html); |
220 | const $bodyList= $('#body-content > div.search_lyrics > div.music-list-wrap.type-lyrics > table > tbody > tr'); | 220 | const $bodyList= $('#body-content > div.search_lyrics > div.music-list-wrap.type-lyrics > table > tbody > tr'); |
221 | - | 221 | + |
222 | var songs=[]; | 222 | var songs=[]; |
223 | $bodyList.each(function(i, elem){ | 223 | $bodyList.each(function(i, elem){ |
224 | if(i<20){ | 224 | if(i<20){ |
... | @@ -226,7 +226,7 @@ function handleEvent(event) { | ... | @@ -226,7 +226,7 @@ function handleEvent(event) { |
226 | singer: $(this).find("td.info").find("a.artist.ellipsis").text().trim(), | 226 | singer: $(this).find("td.info").find("a.artist.ellipsis").text().trim(), |
227 | song: $(this).find("td.info").find("a.title.ellipsis").text().trim(), | 227 | song: $(this).find("td.info").find("a.title.ellipsis").text().trim(), |
228 | }); | 228 | }); |
229 | - | 229 | + |
230 | } | 230 | } |
231 | }) | 231 | }) |
232 | console.log(songs); | 232 | console.log(songs); |
... | @@ -246,6 +246,60 @@ function handleEvent(event) { | ... | @@ -246,6 +246,60 @@ function handleEvent(event) { |
246 | }); | 246 | }); |
247 | }); | 247 | }); |
248 | } | 248 | } |
249 | + else if(event.message.text.substring(0,6)=='콘서트 보기'||event.message.text.substring(0,5)=='콘서트보기'){ | ||
250 | + | ||
251 | + return new Promise(function(resolve, reject) | ||
252 | + { | ||
253 | + var showlist = { type: 'text', text:''}; | ||
254 | + for(var i = 0; i < concert_list.length; i++) | ||
255 | + { | ||
256 | + showlist.text+=i+1 + ". " + concert_list[i] + "\n"; | ||
257 | + } | ||
258 | + console.log(showlist.text); | ||
259 | + | ||
260 | + client.replyMessage(event.replyToken, showlist).then(resolve).catch(reject); | ||
261 | + }); | ||
262 | + } | ||
263 | + | ||
264 | + else if(0 < event.message.text.substr(0,2)*1 && event.message.text.substr(0,2)*1 < 27){ | ||
265 | + | ||
266 | + var selectnum = (event.message.text.substr(0,2)*1); | ||
267 | + var result = { type: 'text', text:''}; | ||
268 | + console.log(selectnum); | ||
269 | + if(selectnum <=0 || selectnum >=27){ | ||
270 | + result.text = '목록에 존재하지 않는 콘서트입니다.'; | ||
271 | + return ; | ||
272 | + } | ||
273 | + | ||
274 | + return new Promise(function(resolve, reject){ | ||
275 | + var concert_name = concert_list[selectnum-1]; | ||
276 | + var $ = cheerio.load(concert_name); | ||
277 | + var keyword = $.text(); | ||
278 | + console.log(keyword); | ||
279 | + | ||
280 | + var options = {method: 'GET', | ||
281 | + url: 'https://www.googleapis.com/youtube/v3/search', | ||
282 | + qs: { key: 'AIzaSyB4b-n8SSv73CLDKvFigpLPYA6yWG2JQ9A', | ||
283 | + part: 'id', | ||
284 | + maxResults: '1', | ||
285 | + order: 'relevance', | ||
286 | + q: keyword, | ||
287 | + type: 'video'} | ||
288 | + }; | ||
289 | + | ||
290 | + | ||
291 | + request(options, function(error,result,body){ | ||
292 | + if(error) throw new Error(error); | ||
293 | + var videourl = { type: 'text', text:''}; | ||
294 | + | ||
295 | + var temp1 = body.split(':'); | ||
296 | + videourl.text += "https://www.youtube.com/watch?v=" + temp1[13].substr(2,11); | ||
297 | + | ||
298 | + console.log(videourl.text); | ||
299 | + client.replyMessage(event.replyToken, videourl).then(resolve).catch(reject); | ||
300 | + }); | ||
301 | + }); | ||
302 | + } | ||
249 | else{ | 303 | else{ |
250 | return new Promise(function(resolve, reject) { | 304 | return new Promise(function(resolve, reject) { |
251 | //언어 감지 option | 305 | //언어 감지 option |
... | @@ -312,4 +366,4 @@ function handleEvent(event) { | ... | @@ -312,4 +366,4 @@ function handleEvent(event) { |
312 | 366 | ||
313 | app.get('/',(req,res)=>{ | 367 | app.get('/',(req,res)=>{ |
314 | res.send("hello"); | 368 | res.send("hello"); |
315 | -}) | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
369 | +}) | ... | ... |
event.json
0 → 100644
This diff could not be displayed because it is too large.
-
Please register or login to post a comment