나혜원

add concert function

Showing 1 changed file with 35 additions and 21 deletions
......@@ -5,7 +5,7 @@ const line = require('@line/bot-sdk');
var request = require('request');
var https=require('https');
var http=require('http');
/*
const lex = require('greenlock-express').create({
version: 'draft-11', // 버전2
store: require('greenlock-store-fs'),
......@@ -30,7 +30,7 @@ https.createServer(lex.httpsOptions, lex.middleware(app)).listen((process.env.SS
http.createServer(lex.middleware(require('redirect-https')())).listen(process.env.PORT || 80,()=>{
console.log("server on 80");
});
*/
//번역 api_url
var translate_api_url = 'https://openapi.naver.com/v1/papago/n2mt';
......@@ -70,7 +70,7 @@ for(var i = 0; i < data_list.length; i++){
}
for(var i = 0; i < concert_list.length; i++){
console.log(i+1,') ',concert_list[i],'\n');
console.log(i+1,'. ',concert_list[i],'\n');
}
//콘서트 목록
......@@ -102,41 +102,55 @@ function handleEvent(event) {
console.log(showlist.text);
client.replyMessage(event.replyToken, showlist).then(resolve).catch(reject);
});
}
else if(isNaN(event.message.text)){
var selectnum = (event.message.text*1);
var selectnum = 1;
var concert_name = concert_list[selectnum];
if(selectnum >=0 || selectnum <=27){
result.text = '목록에 존재하지 않는 콘서트입니다.';
client.replyMessage(event.replyToken, result).then(resolve).catch(reject);
}
return new Promise(function(resolve, reject){
var concert_name = concert_list[selectnum-1];
var $ = cheerio.load(concert_name);
var keyword = $.text();
console.log(keyword);
//키워드 추출
var options = { method: 'GET',
var options = {method: 'GET',
url: 'https://www.googleapis.com/youtube/v3/search',
qs:
{ key: 'AIzaSyB4b-n8SSv73CLDKvFigpLPYA6yWG2JQ9A',
qs: { key: 'AIzaSyB4b-n8SSv73CLDKvFigpLPYA6yWG2JQ9A',
part: 'id',
maxResults: '3',
order: 'viewCount',
maxResults: '1',
order: 'relevance',
q: keyword,
type: 'video'},
type: 'video'}
};
//youtube api
var videourl = { type: 'url', label: '관련 영상', url:''};
request(options, function(error,result,body){
if(error) throw new Error(error);
//var temp = body.replace('{','');
//var temp = temp.replace('}','');
var temp1 = body.split(':');
var temp = body.split(':');
videourl.url += "https://www.youtube.com/watch?v=" + temp1[13].substr(2,11);
});
for(var i = 0; i < temp1.length; i++){
console.log(i,temp1[i],'\n');
}
console.log(videourl.url);
//console.log(temp1);
client.replyMessage(event.replyToken, videourl).then(resolve).catch(reject);
})};
app.post('/webhook', line.middleware(config), (req, res) => {
console.log(res.statusCode);
Promise
.all(req.body.events.map(handleEvent2))
.then((result) => res.json(result))
.catch((err)=>{console.log(err);
})
});
//search on youtube
return new Promise(function(resolve, reject) {
//언어 감지 option
......