Showing
1 changed file
with
69 additions
and
1 deletions
... | @@ -5,6 +5,7 @@ const line = require('@line/bot-sdk'); | ... | @@ -5,6 +5,7 @@ const line = require('@line/bot-sdk'); |
5 | var request = require('request'); | 5 | var request = require('request'); |
6 | var https=require('https'); | 6 | var https=require('https'); |
7 | var http=require('http'); | 7 | var http=require('http'); |
8 | +/* | ||
8 | const lex = require('greenlock-express').create({ | 9 | const lex = require('greenlock-express').create({ |
9 | version: 'draft-11', // 버전2 | 10 | version: 'draft-11', // 버전2 |
10 | store: require('greenlock-store-fs'), | 11 | store: require('greenlock-store-fs'), |
... | @@ -29,6 +30,7 @@ https.createServer(lex.httpsOptions, lex.middleware(app)).listen((process.env.SS | ... | @@ -29,6 +30,7 @@ https.createServer(lex.httpsOptions, lex.middleware(app)).listen((process.env.SS |
29 | http.createServer(lex.middleware(require('redirect-https')())).listen(process.env.PORT || 80,()=>{ | 30 | http.createServer(lex.middleware(require('redirect-https')())).listen(process.env.PORT || 80,()=>{ |
30 | console.log("server on 80"); | 31 | console.log("server on 80"); |
31 | }); | 32 | }); |
33 | +*/ | ||
32 | //번역 api_url | 34 | //번역 api_url |
33 | var translate_api_url = 'https://openapi.naver.com/v1/papago/n2mt'; | 35 | var translate_api_url = 'https://openapi.naver.com/v1/papago/n2mt'; |
34 | 36 | ||
... | @@ -54,6 +56,23 @@ const client = new line.Client(config); | ... | @@ -54,6 +56,23 @@ const client = new line.Client(config); |
54 | // register a webhook handler with middleware | 56 | // register a webhook handler with middleware |
55 | // about the middleware, please refer to doc | 57 | // about the middleware, please refer to doc |
56 | 58 | ||
59 | +var cheerio = require('cheerio'); | ||
60 | +var data = require('./event.json'); | ||
61 | +//json 불러오기 | ||
62 | + | ||
63 | +var data_list = data["DATA"] | ||
64 | +var concert_list = []; | ||
65 | + | ||
66 | +for(var i = 0; i < data_list.length; i++){ | ||
67 | + if (data_list[i].codename=="콘서트"){ | ||
68 | + concert_list.push(data_list[i].title); | ||
69 | + } | ||
70 | + } | ||
71 | + | ||
72 | +for(var i = 0; i < concert_list.length; i++){ | ||
73 | + console.log(i+1,') ',concert_list[i],'\n'); | ||
74 | + } | ||
75 | +//콘서트 목록 | ||
57 | 76 | ||
58 | app.post('/webhook', line.middleware(config), (req, res) => { | 77 | app.post('/webhook', line.middleware(config), (req, res) => { |
59 | console.log(res.statusCode); | 78 | console.log(res.statusCode); |
... | @@ -61,9 +80,9 @@ console.log(res.statusCode); | ... | @@ -61,9 +80,9 @@ console.log(res.statusCode); |
61 | .all(req.body.events.map(handleEvent)) | 80 | .all(req.body.events.map(handleEvent)) |
62 | .then((result) => res.json(result)) | 81 | .then((result) => res.json(result)) |
63 | .catch((err)=>{console.log(err); | 82 | .catch((err)=>{console.log(err); |
64 | - console.log(err.originalError.response) | ||
65 | }) | 83 | }) |
66 | }); | 84 | }); |
85 | + | ||
67 | // event handler | 86 | // event handler |
68 | function handleEvent(event) { | 87 | function handleEvent(event) { |
69 | console.log(event.message); | 88 | console.log(event.message); |
... | @@ -71,6 +90,54 @@ function handleEvent(event) { | ... | @@ -71,6 +90,54 @@ function handleEvent(event) { |
71 | // ignore non-text-message event | 90 | // ignore non-text-message event |
72 | return Promise.resolve(null); | 91 | return Promise.resolve(null); |
73 | } | 92 | } |
93 | + else if(event.message.text.substring(0,6)=='콘서트 보기'){ | ||
94 | + | ||
95 | + return new Promise(function(resolve, reject) | ||
96 | + { | ||
97 | + var showlist = { type: 'text', text:''}; | ||
98 | + for(var i = 0; i < concert_list.length; i++) | ||
99 | + { | ||
100 | + showlist.text+=i+1 + ". " + concert_list[i] + "\n"; | ||
101 | + } | ||
102 | + console.log(showlist.text); | ||
103 | + client.replyMessage(event.replyToken, showlist).then(resolve).catch(reject); | ||
104 | + }); | ||
105 | + } | ||
106 | + | ||
107 | + var selectnum = 1; | ||
108 | + var concert_name = concert_list[selectnum]; | ||
109 | + var $ = cheerio.load(concert_name); | ||
110 | + var keyword = $.text(); | ||
111 | + console.log(keyword); | ||
112 | + //키워드 추출 | ||
113 | + | ||
114 | + var options = { method: 'GET', | ||
115 | + url: 'https://www.googleapis.com/youtube/v3/search', | ||
116 | + qs: | ||
117 | + { key: 'AIzaSyB4b-n8SSv73CLDKvFigpLPYA6yWG2JQ9A', | ||
118 | + part: 'id', | ||
119 | + maxResults: '3', | ||
120 | + order: 'viewCount', | ||
121 | + q: keyword, | ||
122 | + type: 'video'}, | ||
123 | + }; | ||
124 | + //youtube api | ||
125 | + | ||
126 | + request(options, function(error,result,body){ | ||
127 | + if(error) throw new Error(error); | ||
128 | + | ||
129 | + //var temp = body.replace('{',''); | ||
130 | + //var temp = temp.replace('}',''); | ||
131 | + var temp1 = body.split(':'); | ||
132 | + | ||
133 | + for(var i = 0; i < temp1.length; i++){ | ||
134 | + console.log(i,temp1[i],'\n'); | ||
135 | + } | ||
136 | + | ||
137 | + //console.log(temp1); | ||
138 | + }); | ||
139 | + //search on youtube | ||
140 | + | ||
74 | return new Promise(function(resolve, reject) { | 141 | return new Promise(function(resolve, reject) { |
75 | //언어 감지 option | 142 | //언어 감지 option |
76 | var detect_options = { | 143 | var detect_options = { |
... | @@ -79,6 +146,7 @@ function handleEvent(event) { | ... | @@ -79,6 +146,7 @@ function handleEvent(event) { |
79 | headers: {'X-Naver-Client-Id': client_id, 'X-Naver-Client-Secret': client_secret} | 146 | headers: {'X-Naver-Client-Id': client_id, 'X-Naver-Client-Secret': client_secret} |
80 | }; | 147 | }; |
81 | //papago 언어 감지 | 148 | //papago 언어 감지 |
149 | + | ||
82 | request.post(detect_options,async (error,response,body)=>{ | 150 | request.post(detect_options,async (error,response,body)=>{ |
83 | console.log(response.statusCode); | 151 | console.log(response.statusCode); |
84 | if(!error && response.statusCode == 200){ | 152 | if(!error && response.statusCode == 200){ | ... | ... |
-
Please register or login to post a comment