윤준현

Add_Mot_Guckkasten

something wrong
...@@ -9,6 +9,9 @@ var async = require('async'); ...@@ -9,6 +9,9 @@ var async = require('async');
9 var crawlReol = require('./crawling/Reol'); 9 var crawlReol = require('./crawling/Reol');
10 var crawlYonezu = require('./crawling/Yonezu'); 10 var crawlYonezu = require('./crawling/Yonezu');
11 var crawlYorusika = require('./crawling/Yorusika'); 11 var crawlYorusika = require('./crawling/Yorusika');
12 +var crawlGuckkasten = require('./crawling/Guckkasten');
13 +var crawlMot = require('./crawling/Mot');
14 +
12 var singer; 15 var singer;
13 16
14 //body-parser 미들웨어 사용 17 //body-parser 미들웨어 사용
...@@ -25,7 +28,7 @@ app.get('/keyboard', function(req,res){ ...@@ -25,7 +28,7 @@ app.get('/keyboard', function(req,res){
25 }); 28 });
26 29
27 //8080포트로 서버 접속 30 //8080포트로 서버 접속
28 -http.createServer(app).listen(8080, () => { 31 +http.createServer(app).listen(9000, () => {
29 console.log('Server running..'); 32 console.log('Server running..');
30 }); 33 });
31 34
...@@ -57,6 +60,18 @@ app.post('/message', function(req,res){ ...@@ -57,6 +60,18 @@ app.post('/message', function(req,res){
57 callback(null,yorusika); 60 callback(null,yorusika);
58 }); 61 });
59 break; 62 break;
63 + case 'Guckkasten-Discography' :
64 + singer = 'guckkasten';
65 + crawlGuckkasten.crawl_guckkasten(function(guckkasten){
66 + callback(null,guckkasten);
67 + });
68 + break;
69 + case 'Mot-Discography':
70 + singer = 'mot';
71 + crawlMot.crawl_mot(function (mot) {
72 + callback(null, mot);
73 + });
74 + break;
60 default: 75 default:
61 if(singer == 'Reol'){ 76 if(singer == 'Reol'){
62 crawlReol.crawl_Reol('https://namu.wiki/w/%EB%A0%88%EC%98%A4%EB%A3%A8/%EC%9D%8C%EB%B0%98#toc',function(Reol){ 77 crawlReol.crawl_Reol('https://namu.wiki/w/%EB%A0%88%EC%98%A4%EB%A3%A8/%EC%9D%8C%EB%B0%98#toc',function(Reol){
...@@ -68,11 +83,21 @@ app.post('/message', function(req,res){ ...@@ -68,11 +83,21 @@ app.post('/message', function(req,res){
68 callback(null,yonezu) 83 callback(null,yonezu)
69 }); 84 });
70 } 85 }
71 - else if(singer=='yorusika'){ 86 + else if(singer=='yorusika'){
72 crawlYorusika.crawl_yorusika('http://yorushika.com/discography/', function(yorusika){ 87 crawlYorusika.crawl_yorusika('http://yorushika.com/discography/', function(yorusika){
73 callback(null,yorusika); 88 callback(null,yorusika);
74 }); 89 });
75 } 90 }
91 + else if(singer=='guckkasten'){
92 + crawlGuckkasten.crawl_guckkasten(function(guckkasten){
93 + callback(null,guckkasten);
94 + });
95 + }
96 + else if(singer=='mot'){
97 + crawlMot.crawl_mot(function (mot) {
98 + callback(null, mot);
99 + });
100 + }
76 else 101 else
77 callback(null,null); 102 callback(null,null);
78 break; 103 break;
...@@ -81,7 +106,6 @@ app.post('/message', function(req,res){ ...@@ -81,7 +106,6 @@ app.post('/message', function(req,res){
81 }, 106 },
82 107
83 // 사용자의 msg를 받아 res를 보냄 // 108 // 사용자의 msg를 받아 res를 보냄 //
84 -
85 function(discography, callback){ 109 function(discography, callback){
86 var index = parseInt(msg[0])-1; 110 var index = parseInt(msg[0])-1;
87 switch (msg) { 111 switch (msg) {
...@@ -101,11 +125,11 @@ app.post('/message', function(req,res){ ...@@ -101,11 +125,11 @@ app.post('/message', function(req,res){
101 case '한국': 125 case '한국':
102 send = { 126 send = {
103 'message': { 127 'message': {
104 - 'text': '미구현' 128 + 'text': '등록된 가수 목록입니다.'
105 }, 129 },
106 keyboard: { 130 keyboard: {
107 'type': 'buttons', 131 'type': 'buttons',
108 - 'buttons': ['MOT', 'Gukkasten', 'ZICO'] 132 + 'buttons': ['Mot', 'Guckkasten']
109 } 133 }
110 }; 134 };
111 break; 135 break;
...@@ -203,7 +227,7 @@ app.post('/message', function(req,res){ ...@@ -203,7 +227,7 @@ app.post('/message', function(req,res){
203 case 'ヨルシカ': 227 case 'ヨルシカ':
204 send = { 228 send = {
205 'message': { 229 'message': {
206 - 'text': '개요 : 2인조 밴드\n멤버 : n-buna, suis \n역할 : 작사, 작곡, 편곡 - n-buna\n 보컬 - suis\n서포트 멤버 : \n 下鶴光康(Guitar)\n キタニタツヤ(Bass)\n Masack(Drums)', 230 + 'text': '설명 : 2인조 밴드\n멤버 : n-buna, suis \n역할 : 작사, 작곡, 편곡 - n-buna\n 보컬 - suis\n서포트 멤버 : \n 下鶴光康(Guitar)\n キタニタツヤ(Bass)\n Masack(Drums)',
207 'photo': { 231 'photo': {
208 'url': 'http://yorushika.com/wp-content/uploads/2018/05/biography_image2.jpg', 232 'url': 'http://yorushika.com/wp-content/uploads/2018/05/biography_image2.jpg',
209 'width': 1000, 233 'width': 1000,
...@@ -241,11 +265,76 @@ app.post('/message', function(req,res){ ...@@ -241,11 +265,76 @@ app.post('/message', function(req,res){
241 265
242 }; 266 };
243 break; 267 break;
268 + ////////////////
269 + // Guckkasten //
270 + ////////////////
271 + case 'Guckkasten':
272 + send = {
273 + 'message': {
274 + 'text': '설명 : 4인조 밴드\n멤버 :\n 하현우(Vocal, Guitar)\n 전규호(Guitar)\n 이정길(Drum)\n 김기범(Bass)\n장르 : 싸이키델릭 록\n데뷔 : 2007년\n소속사 : 인터파크',
275 + 'photo': {
276 + 'url': 'http://ticketimage.interpark.com/interparkenter/guckkasten/about/guckkasten_about_pc_image(540x420px).jpg',
277 + 'width': 540,
278 + 'height': 420
279 + },
280 + 'message_button': {
281 + 'label': '공식 홈페이지',
282 + 'url': "http://www.interparkenter.com/guckkasten/Main"
283 + }
284 + },
285 + keyboard: {
286 + 'type': 'buttons',
287 + 'buttons': ['Guckkasten-Discography']
288 + }
289 + };
290 + break;
291 + case 'Guckkasten-Discography':
292 + send = {
293 + 'message': {
294 + 'text': 'Album List',
295 + },
296 + keyboard: {
297 + 'type': 'buttons',
298 + 'buttons': discography[0].json_album
299 + }
244 300
301 + };
302 + break;
245 ///////////// 303 /////////////
246 - //// MOT //// 304 + //// Mot ////
247 ///////////// 305 /////////////
306 + case 'Mot':
307 + send = {
308 + 'message': {
309 + 'text': '설명 : 5인조 밴드\n현멤버(3집 이후) :\n 이이언(Vocal)\n 유웅렬(Guitar)\n 조남열(Drum)\n 송인섭(Bass)\n 이하윤(Keyboard)\n구멤버(1, 2집) :\n 이이언(Vocal)\n지이(Guitar)\n장르 : Indie Rock\n 데뷔 : 2007년\n소속사 : 인터파크',
310 + 'photo': {
311 + 'url': 'https://scontent-icn1-1.xx.fbcdn.net/v/t1.0-1/p320x320/31164203_908165976030791_1214044515636084736_n.jpg?_nc_cat=111&_nc_ht=scontent-icn1-1.xx&oh=7da23be5eb9dfcd537287b012f231dbb&oe=5C9B33D0',
312 + 'width': 1000,
313 + 'height': 677
314 + },
315 + 'message_button': {
316 + 'label': '공식 Facebook',
317 + 'url': "https://www.facebook.com/bandmot.official"
318 + }
319 + },
320 + keyboard: {
321 + 'type': 'buttons',
322 + 'buttons': ['Mot-Discography']
323 + }
324 + };
325 + break;
326 + case 'Mot-Discography':
327 + send = {
328 + 'message': {
329 + 'text': 'Album List',
330 + },
331 + keyboard: {
332 + 'type': 'buttons',
333 + 'buttons': discography[0].json_album
334 + }
248 335
336 + };
337 + break;
249 338
250 // 앨범 정보 읽기 // 339 // 앨범 정보 읽기 //
251 340
...@@ -284,7 +373,28 @@ app.post('/message', function(req,res){ ...@@ -284,7 +373,28 @@ app.post('/message', function(req,res){
284 } 373 }
285 } 374 }
286 } 375 }
287 - break; 376 + else if (singer == 'guckkasten'){
377 + send = {
378 + 'message': {
379 + 'text': album + '\n발매년도 : ' + discography[0].json_year[index] + '\n수록곡 : \n' + discography[0].json_track[index]
380 + },
381 + keyboard: {
382 + 'type': 'buttons',
383 + 'buttons': ['Guckkasten-Discography', '초기화면']
384 + }
385 + }
386 + }
387 + else if (singer == 'mot'){
388 + send = {
389 + 'message': {
390 + 'text': album + '\n발매년도 : ' + discography[0].json_year[index] + '\n수록곡 : \n' + discography[0].json_track[index]
391 + },
392 + keyboard: {
393 + 'type': 'buttons',
394 + 'buttons': ['Mot-Discography', '초기화면']
395 + }
396 + }
397 + }
288 398
289 // 초기 설정으로 돌아가기 // 399 // 초기 설정으로 돌아가기 //
290 400
......
1 +var request = require('request');
2 +var cheerio = require('cheerio');
3 +
4 +function crawl_guckkasten(callback){
5 + var n = 0;
6 + var guckkasten = [];
7 + crawl(function(album,year,track){
8 + n++
9 + if (n == 10) {
10 + var j;
11 + var a, y, t;
12 + for (var i = 1; i < year.length; i++) {
13 + y = year[i];
14 + a = album[i];
15 + t = track[i]
16 + j = i - 1;
17 + while (j >= 0 && year[j] > y) {
18 + album[j + 1] = album[j];
19 + year[j + 1] = year[j];
20 + track[j + 1] = track[j];
21 + j--;
22 + }
23 + album[j + 1] = a;
24 + year[j + 1] = y;
25 + track[j + 1] = t;
26 + }
27 + for(var i = 0; i<album.length; i++){
28 + album[i] = (i+1)+'. ' +album[i];
29 + }
30 + guckkasten.push(album, year, track);
31 + callback(guckkasten);
32 + }
33 + })
34 +}
35 +
36 +function crawl(callback){
37 + var url;
38 + let json_album = [], json_year = [], json_track = [];
39 + var track;
40 + var year;
41 + var album;
42 + for (var i = 1; i <= 13; i++) {
43 + url = 'http://www.interparkenter.com/guckkasten/Album/' + i;
44 + if (!(i > 9 && i < 13)) {
45 + request(url, function (err, res, body) {
46 + const $ = cheerio.load(body);
47 +
48 + var track_num = 0;
49 + var album_track = '';
50 + $('#divDetail > div.disco_left_box > div.track_area > div > ol').find('li').each(function () {
51 + track_num++;
52 + track = $('#divDetail > div.disco_left_box > div.track_area > div > ol > li:nth-child(' + track_num + ')').text()
53 + album_track += track + '\n';
54 + })
55 + json_track.push(album_track);
56 +
57 + year = $('#divDetail > div.disco_right_box > div.Introduction > p.txt_release').text();
58 + year = year.substr(3);
59 + json_year.push(year);
60 +
61 + album = $('#divDetail > div.disco_right_box > div.Introduction > p.txt_title').text();
62 + json_album.push(album);
63 + callback(json_album,json_year,json_track);
64 + });
65 + }
66 + }
67 +}
68 +
69 +
70 +exports.crawl_guckkasten = crawl_guckkasten;
...\ No newline at end of file ...\ No newline at end of file
1 +var request = require('request');
2 +var cheerio = require('cheerio');
3 +
4 +function crawl_mot(callback){
5 + var url = 'https://namu.wiki/w/%EB%AA%BB(%EB%B0%B4%EB%93%9C)';
6 + let json_album = [], json_year = [], json_track = [];
7 + let Mot = [];
8 + var track;
9 + json_year.push('2004. 06. 18');
10 + json_year.push('2007. 05. 22');
11 + json_year.push('2016. 02. 19');
12 +
13 + request(url, function (err, res, body) {
14 + const $ = cheerio.load(body);
15 + var index = 12;
16 + var album_num = 0;
17 + for(var i = 1; i<=3; i++){
18 + index += 2;
19 + if(index == 18)
20 + index += 6;
21 + var title_index = 0;
22 + var track_cnt = 0;
23 + var album_track = '';
24 + $('body > div.content-wrapper > article > div.wiki-content.clearfix > div > div:nth-child('+index+') > div > table > tbody').find('tr').each(function () {
25 + title_index++;
26 + if (title_index == 1) {
27 + album_num++;
28 + album = $('body > div.content-wrapper > article > div.wiki-content.clearfix > div > div:nth-child('+index+') > div > table > tbody > tr:nth-child(1)').text()
29 + album = album_num + '. ' + album;
30 + }
31 + else if (title_index >= 3) {
32 + track_cnt++;
33 + track = $('body > div.content-wrapper > article > div.wiki-content.clearfix > div > div:nth-child('+index+') > div > table > tbody > tr:nth-child(' + title_index + ') > td:nth-child(2)').text();
34 + track = track_cnt + '. ' + track;
35 + album_track += track + '\n';
36 + }
37 + });
38 + json_album.push(album);
39 + json_track.push(album_track);
40 + }
41 +
42 + Mot.push({ json_album, json_year, json_track});
43 + callback(Mot);
44 + });
45 +}
46 +
47 +exports.crawl_mot = crawl_mot;