app.js
5.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// 모듈 불러오기
var express = require('express');
var http = require('http');
var bodyParser = require('body-parser');
var app = express(); // express 객체 저장
var webcrawl = require('./crawling/Reol');
var async = require('async');
//body-parser 미들웨어 사용
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
// http://서버주소/keyboard
app.get('/keyboard', function(req,res){
var data = {
'type' : 'buttons',
'buttons' : ['일본', '한국']};
res.json(data);
});
//8080포트로 서버 접속
http.createServer(app).listen(8080, () => {
console.log('Server running..');
});
// http://서버주소/message
app.post('/message', function(req,res){
//유저가 입력한 데이터
var msg = req.body.content;
console.log('전달받은 메시지 : ' + msg);
var send = {};
var task = [
function(callback){
switch(msg){
case 'Reol-Discography' :
webcrawl.crawl_Reol('https://namu.wiki/w/%EB%A0%88%EC%98%A4%EB%A3%A8/%EC%9D%8C%EB%B0%98#toc',function(Reol){
callback(null,Reol);
})
break;
case '米津玄師-Discography' :
}
},
function(discography, callback){
switch (msg) {
case '일본':
send = {
'message': {
'text': '등록된 가수 목록입니다.'
},
keyboard: {
'type': 'buttons',
'buttons': ['Reol', '米津玄師', 'yanaginagi', 'ヨルシカ', 'ダズビ', 'Polkadot Stingray', 'Aimyong']
}
};
break;
case '한국':
send = {
'message': {
'text': '등록된 가수 목록입니다.'
},
keyboard: {
'type': 'buttons',
'buttons': ['볼빨간 사춘기', 'MOT', 'Gukkasten', 'ZICO', 'DEAN', 'IU', 'Heize']
}
};
break;
// ---------- contents -------------- //
///// Reol ////
case 'Reol' :
send = {
'message' : {
'text' : '이름 : Reol(れをる) \n성별 : 여성 \n생년월일 : 1993년 11월 9일 \n혈액형 : AB형',
'photo' : {
'url' : 'https://www.reol.jp/images/profile/reol_Aphoto_2.png',
'width' : 1000,
'height' : 667
},
'message_button' : {
'label' : '공식 홈페이지',
'url' : "https://www.reol.jp/"
}
},
keyboard : {
'type' : 'buttons',
'buttons' : ['Reol-Discography']
}
};
break;
case 'Reol-Discography' :
console.log(discography);
send = {
'message': {
'text': '앨범 목록입니다.'
},
keyboard: {
'type': 'buttons',
'buttons': discography[0].json_album
}
}
break;
case discography[0].json_album[0]:
send = {
'message' : {
'text' : discography[0].json_album[0] + '\n 발매년도 : ' + discography[0].json_year[0] + '\n 수록곡 : \n' + discography[0].json_track[0]
}
}
/// 米津玄師 ///
case '米津玄師' :
send = {
'message' : {
'text' : '이름 : 米津玄師(Yonezu Kenshi) \n 성별 : 남성 \n생년월일 : 1991년 3월 10일 \n혈액형 : O형',
'photo' : {
'url' : 'http://reissuerecords.net/rr/wp-content/uploads/flamingo_photo2.jpg',
'width' : 1000,
'height' : 667
},
'message_button' : {
'label' : '공식 홈페이지',
'url' : "http://reissuerecords.net/"
}
},
keyboard : {
'type' : 'buttons',
'buttons' : ['米津玄師-Discography']
}
};
break;
case '米津玄師-Discography' :
send = {
'message' : {
'text' : 'Album List'
},
keyboard : {
'type' : 'buttons',
'buttons' : ['Reol', '米津玄師', 'yanaginagi', 'ヨルシカ', 'ダズビ', 'Polkadot Stingray', 'Aimyong']
}
};
default:
break;
}
callback(null ,send);
}
];
async.waterfall(task, function(err,result){
console.log(send);
res.json(send);
});
});