권은령

fixing error...

Showing 1 changed file with 25 additions and 25 deletions
...@@ -121,40 +121,40 @@ function handleEvent(event) ...@@ -121,40 +121,40 @@ function handleEvent(event)
121 else if(event.message.text.substring(0, 5)=='순위 보기') 121 else if(event.message.text.substring(0, 5)=='순위 보기')
122 { 122 {
123 // music list 출력 123 // music list 출력
124 - return new Promise(function(resolve, reject){ 124 + var url="https://www.genie.co.kr/chart/top200";
125 - var result = { type: 'text', text:''};
126 125
127 - var url="https://www.genie.co.kr/chart/top200"; 126 + request(url, function(error, response, html){
127 + var $ = cheerio.load(html);
128 + var songList=[];
129 + const $bodyList= $('#body-content > div.newest-list > div > table > tbody > tr');
128 130
129 - request(url, function(error, response, html){ 131 + $bodyList.each(function(i, elem){
130 - var $ = cheerio.load(html); 132 + if(i<20)
131 - var songList=[];
132 - const $bodyList= $('#body-content > div.newest-list > div > table > tbody > tr');
133 -
134 - $bodyList.each(function(i, elem)
135 { 133 {
136 - if(i<20) 134 + songList.push(
137 - {
138 - songList.push(
139 - {
140 - singer: $(this).find("td.info").find("a.artist.ellipsis").text().trim(),
141 - song: $(this).find("td.info").find("a.title.ellipsis").text().trim(),
142 - url: 'https://www.genie.co.kr/detail/songInfo?xgnm='+$(this).attr("songid")
143 - });
144 - }
145 - else
146 { 135 {
147 - return; 136 + singer: $(this).find("td.info").find("a.artist.ellipsis").text().trim(),
148 - } 137 + song: $(this).find("td.info").find("a.title.ellipsis").text().trim(),
149 - }); 138 + url: 'https://www.genie.co.kr/detail/songInfo?xgnm='+$(this).attr("songid")
150 - 139 + });
140 + }
141 + else
142 + {
143 + return;
144 + }
145 + });
146 + });
147 +
148 + return new Promise(function(resolve, reject)
149 + {
150 + var result = { type: 'text', text:''};
151 +
151 for(var i=0; i<songList.length; i++) 152 for(var i=0; i<songList.length; i++)
152 { 153 {
153 result.text+=i+1 + ". "+ songList[i].singer+" - "+songList[i].song+"\n"; 154 result.text+=i+1 + ". "+ songList[i].singer+" - "+songList[i].song+"\n";
154 } 155 }
155 console.log(result.text); 156 console.log(result.text);
156 - }); 157 + client.replyMessage(event.replyToken, result).then(resolve).catch(reject);
157 - client.replyMessage(event.replyToken, result).then(resolve).catch(reject);
158 }); 158 });
159 } 159 }
160 else 160 else
......