윤준현

Add_Mot_Guckkasten

something wrong
......@@ -9,6 +9,9 @@ var async = require('async');
var crawlReol = require('./crawling/Reol');
var crawlYonezu = require('./crawling/Yonezu');
var crawlYorusika = require('./crawling/Yorusika');
var crawlGuckkasten = require('./crawling/Guckkasten');
var crawlMot = require('./crawling/Mot');
var singer;
//body-parser 미들웨어 사용
......@@ -25,7 +28,7 @@ app.get('/keyboard', function(req,res){
});
//8080포트로 서버 접속
http.createServer(app).listen(8080, () => {
http.createServer(app).listen(9000, () => {
console.log('Server running..');
});
......@@ -57,6 +60,18 @@ app.post('/message', function(req,res){
callback(null,yorusika);
});
break;
case 'Guckkasten-Discography' :
singer = 'guckkasten';
crawlGuckkasten.crawl_guckkasten(function(guckkasten){
callback(null,guckkasten);
});
break;
case 'Mot-Discography':
singer = 'mot';
crawlMot.crawl_mot(function (mot) {
callback(null, mot);
});
break;
default:
if(singer == 'Reol'){
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){
callback(null,yonezu)
});
}
else if(singer=='yorusika'){
else if(singer=='yorusika'){
crawlYorusika.crawl_yorusika('http://yorushika.com/discography/', function(yorusika){
callback(null,yorusika);
});
}
else if(singer=='guckkasten'){
crawlGuckkasten.crawl_guckkasten(function(guckkasten){
callback(null,guckkasten);
});
}
else if(singer=='mot'){
crawlMot.crawl_mot(function (mot) {
callback(null, mot);
});
}
else
callback(null,null);
break;
......@@ -81,7 +106,6 @@ app.post('/message', function(req,res){
},
// 사용자의 msg를 받아 res를 보냄 //
function(discography, callback){
var index = parseInt(msg[0])-1;
switch (msg) {
......@@ -101,11 +125,11 @@ app.post('/message', function(req,res){
case '한국':
send = {
'message': {
'text': '미구현'
'text': '등록된 가수 목록입니다.'
},
keyboard: {
'type': 'buttons',
'buttons': ['MOT', 'Gukkasten', 'ZICO']
'buttons': ['Mot', 'Guckkasten']
}
};
break;
......@@ -203,7 +227,7 @@ app.post('/message', function(req,res){
case 'ヨルシカ':
send = {
'message': {
'text': '개요 : 2인조 밴드\n멤버 : n-buna, suis \n역할 : 작사, 작곡, 편곡 - n-buna\n 보컬 - suis\n서포트 멤버 : \n 下鶴光康(Guitar)\n キタニタツヤ(Bass)\n Masack(Drums)',
'text': '설명 : 2인조 밴드\n멤버 : n-buna, suis \n역할 : 작사, 작곡, 편곡 - n-buna\n 보컬 - suis\n서포트 멤버 : \n 下鶴光康(Guitar)\n キタニタツヤ(Bass)\n Masack(Drums)',
'photo': {
'url': 'http://yorushika.com/wp-content/uploads/2018/05/biography_image2.jpg',
'width': 1000,
......@@ -241,11 +265,76 @@ app.post('/message', function(req,res){
};
break;
////////////////
// Guckkasten //
////////////////
case 'Guckkasten':
send = {
'message': {
'text': '설명 : 4인조 밴드\n멤버 :\n 하현우(Vocal, Guitar)\n 전규호(Guitar)\n 이정길(Drum)\n 김기범(Bass)\n장르 : 싸이키델릭 록\n데뷔 : 2007년\n소속사 : 인터파크',
'photo': {
'url': 'http://ticketimage.interpark.com/interparkenter/guckkasten/about/guckkasten_about_pc_image(540x420px).jpg',
'width': 540,
'height': 420
},
'message_button': {
'label': '공식 홈페이지',
'url': "http://www.interparkenter.com/guckkasten/Main"
}
},
keyboard: {
'type': 'buttons',
'buttons': ['Guckkasten-Discography']
}
};
break;
case 'Guckkasten-Discography':
send = {
'message': {
'text': 'Album List',
},
keyboard: {
'type': 'buttons',
'buttons': discography[0].json_album
}
};
break;
/////////////
//// MOT ////
//// Mot ////
/////////////
case 'Mot':
send = {
'message': {
'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소속사 : 인터파크',
'photo': {
'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',
'width': 1000,
'height': 677
},
'message_button': {
'label': '공식 Facebook',
'url': "https://www.facebook.com/bandmot.official"
}
},
keyboard: {
'type': 'buttons',
'buttons': ['Mot-Discography']
}
};
break;
case 'Mot-Discography':
send = {
'message': {
'text': 'Album List',
},
keyboard: {
'type': 'buttons',
'buttons': discography[0].json_album
}
};
break;
// 앨범 정보 읽기 //
......@@ -284,7 +373,28 @@ app.post('/message', function(req,res){
}
}
}
break;
else if (singer == 'guckkasten'){
send = {
'message': {
'text': album + '\n발매년도 : ' + discography[0].json_year[index] + '\n수록곡 : \n' + discography[0].json_track[index]
},
keyboard: {
'type': 'buttons',
'buttons': ['Guckkasten-Discography', '초기화면']
}
}
}
else if (singer == 'mot'){
send = {
'message': {
'text': album + '\n발매년도 : ' + discography[0].json_year[index] + '\n수록곡 : \n' + discography[0].json_track[index]
},
keyboard: {
'type': 'buttons',
'buttons': ['Mot-Discography', '초기화면']
}
}
}
// 초기 설정으로 돌아가기 //
......
var request = require('request');
var cheerio = require('cheerio');
function crawl_guckkasten(callback){
var n = 0;
var guckkasten = [];
crawl(function(album,year,track){
n++
if (n == 10) {
var j;
var a, y, t;
for (var i = 1; i < year.length; i++) {
y = year[i];
a = album[i];
t = track[i]
j = i - 1;
while (j >= 0 && year[j] > y) {
album[j + 1] = album[j];
year[j + 1] = year[j];
track[j + 1] = track[j];
j--;
}
album[j + 1] = a;
year[j + 1] = y;
track[j + 1] = t;
}
for(var i = 0; i<album.length; i++){
album[i] = (i+1)+'. ' +album[i];
}
guckkasten.push(album, year, track);
callback(guckkasten);
}
})
}
function crawl(callback){
var url;
let json_album = [], json_year = [], json_track = [];
var track;
var year;
var album;
for (var i = 1; i <= 13; i++) {
url = 'http://www.interparkenter.com/guckkasten/Album/' + i;
if (!(i > 9 && i < 13)) {
request(url, function (err, res, body) {
const $ = cheerio.load(body);
var track_num = 0;
var album_track = '';
$('#divDetail > div.disco_left_box > div.track_area > div > ol').find('li').each(function () {
track_num++;
track = $('#divDetail > div.disco_left_box > div.track_area > div > ol > li:nth-child(' + track_num + ')').text()
album_track += track + '\n';
})
json_track.push(album_track);
year = $('#divDetail > div.disco_right_box > div.Introduction > p.txt_release').text();
year = year.substr(3);
json_year.push(year);
album = $('#divDetail > div.disco_right_box > div.Introduction > p.txt_title').text();
json_album.push(album);
callback(json_album,json_year,json_track);
});
}
}
}
exports.crawl_guckkasten = crawl_guckkasten;
\ No newline at end of file
var request = require('request');
var cheerio = require('cheerio');
function crawl_mot(callback){
var url = 'https://namu.wiki/w/%EB%AA%BB(%EB%B0%B4%EB%93%9C)';
let json_album = [], json_year = [], json_track = [];
let Mot = [];
var track;
json_year.push('2004. 06. 18');
json_year.push('2007. 05. 22');
json_year.push('2016. 02. 19');
request(url, function (err, res, body) {
const $ = cheerio.load(body);
var index = 12;
var album_num = 0;
for(var i = 1; i<=3; i++){
index += 2;
if(index == 18)
index += 6;
var title_index = 0;
var track_cnt = 0;
var album_track = '';
$('body > div.content-wrapper > article > div.wiki-content.clearfix > div > div:nth-child('+index+') > div > table > tbody').find('tr').each(function () {
title_index++;
if (title_index == 1) {
album_num++;
album = $('body > div.content-wrapper > article > div.wiki-content.clearfix > div > div:nth-child('+index+') > div > table > tbody > tr:nth-child(1)').text()
album = album_num + '. ' + album;
}
else if (title_index >= 3) {
track_cnt++;
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();
track = track_cnt + '. ' + track;
album_track += track + '\n';
}
});
json_album.push(album);
json_track.push(album_track);
}
Mot.push({ json_album, json_year, json_track});
callback(Mot);
});
}
exports.crawl_mot = crawl_mot;