Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Chat_Bot
/
KaKao_ChatBot
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
윤준현
2018-12-04 19:50:13 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
df32903acc6c9f32a82bce8dd20edae3b504a422
df32903a
1 parent
5f084400
Good
VeryGood
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
14 deletions
app.js
crawling/Reol.js
app.js
View file @
df32903
...
...
@@ -6,6 +6,7 @@ var bodyParser = require('body-parser');
var
app
=
express
();
// express 객체 저장
var
webcrawl
=
require
(
'./crawling/Reol'
);
var
async
=
require
(
'async'
);
var
singer
;
//body-parser 미들웨어 사용
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
false
}));
...
...
@@ -35,16 +36,28 @@ app.post('/message', function(req,res){
function
(
callback
){
switch
(
msg
){
case
'Reol-Discography'
:
singer
=
'Reol'
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'
:
default
:
if
(
singer
==
'Reol'
){
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
);
})
}
else
if
(
singer
==
"Yonezu"
){
}
else
callback
(
null
,
null
);
break
;
}
},
function
(
discography
,
callback
){
var
index
=
parseInt
(
msg
[
0
])
-
1
;
switch
(
msg
)
{
case
'일본'
:
send
=
{
...
...
@@ -53,7 +66,7 @@ app.post('/message', function(req,res){
},
keyboard
:
{
'type'
:
'buttons'
,
'buttons'
:
[
'Reol'
,
'米津玄師'
,
'
yanaginagi'
,
'ヨルシカ'
,
'ダズビ'
,
'Polkadot Stingray'
,
'Aimyong
'
]
'buttons'
:
[
'Reol'
,
'米津玄師'
,
'
ヨルシカ
'
]
}
};
...
...
@@ -66,7 +79,7 @@ app.post('/message', function(req,res){
},
keyboard
:
{
'type'
:
'buttons'
,
'buttons'
:
[
'
볼빨간 사춘기'
,
'MOT'
,
'Gukkasten'
,
'ZICO'
,
'DEAN'
,
'IU'
,
'Heize
'
]
'buttons'
:
[
'
MOT'
,
'Gukkasten'
,
'ZICO
'
]
}
};
break
;
...
...
@@ -93,23 +106,42 @@ app.post('/message', function(req,res){
};
break
;
case
'Reol-Discography'
:
console
.
log
(
discography
);
send
=
{
'message'
:
{
'text'
:
'앨범 목록입니다.'
},
keyboard
:
{
'type'
:
'buttons'
,
'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
discography
[
0
].
json_album
[
index
]:
var
album
=
'앨범 : '
+
discography
[
0
].
json_album
[
index
].
substr
(
3
);
if
(
singer
==
'Reol'
){
send
=
{
'message'
:
{
'text'
:
album
+
'\n발매년도 : '
+
discography
[
0
].
json_year
[
index
]
+
'\n수록곡 : \n'
+
discography
[
0
].
json_track
[
index
]
},
keyboard
:
{
'type'
:
'buttons'
,
'buttons'
:
[
'Reol-Discography'
,
'초기화면'
]
}
}
}
else
if
(
singer
==
'Yonezu'
){
send
=
{
'message'
:
{
'text'
:
album
+
'\n발매년도 : '
+
discography
[
0
].
json_year
[
index
]
+
'\n수록곡 : \n'
+
discography
[
0
].
json_track
[
index
]
},
keyboard
:
{
'type'
:
'buttons'
,
'buttons'
:
[
'米津玄師-Discography'
,
'초기화면'
]
}
}
}
break
;
/// 米津玄師 ///
case
'米津玄師'
:
send
=
{
...
...
@@ -142,6 +174,18 @@ app.post('/message', function(req,res){
}
};
break
;
case
'초기화면'
:
send
=
{
'message'
:
{
'text'
:
'초기화면으로 돌아갑니다.'
},
keyboard
:
{
'type'
:
'buttons'
,
'buttons'
:
[
'한국'
,
'일본'
]
}
}
break
;
default
:
break
;
}
...
...
crawling/Reol.js
View file @
df32903
...
...
@@ -8,7 +8,7 @@ function crawl_Reol(url,callback){
var
Reol
=
new
Array
();
var
album
,
year
var
album_track
=
new
Array
();
var
album_track
=
''
var
json_album
=
new
Array
(),
json_year
=
new
Array
(),
json_track
=
new
Array
();
$
(
'body > div.content-wrapper > article > div.wiki-content.clearfix > div'
).
each
(
function
(
index
,
ele
)
{
for
(
var
i
=
1
;
i
<=
$
(
'.toc-item'
).
length
;
i
++
)
{
...
...
@@ -23,18 +23,32 @@ function crawl_Reol(url,callback){
//year 가져오기
year
=
$
(
'body > div.content-wrapper > article > div.wiki-content.clearfix > div > div:nth-child('
+
index
+
') > div:nth-child(3) > table > tbody > tr:nth-child(1) > td:nth-child(2)'
).
text
();
//track 가져오기
var
track_num
=
0
;
$
(
'body > div.content-wrapper > article > div.wiki-content.clearfix > div > div:nth-child('
+
index
+
') > div:nth-child(3) > table > tbody'
).
find
(
'tr'
).
each
(
function
(
index
,
ele
)
{
var
track
=
$
(
this
).
children
().
eq
(
1
).
text
();
if
(
track
!=
'1'
&&
track
!=
'곡명'
&&
track
[
4
]
!=
'년'
)
album_track
.
push
(
track
)
if
(
track
!=
'1'
&&
track
!=
'곡명'
&&
track
[
4
]
!=
'년'
){
if
(
track
[
track
.
length
-
1
]
==
'M'
)
track
=
track
.
substr
(
0
,
track
.
length
-
1
);
if
(
track
[
track
.
length
-
1
]
==
']'
)
track
=
track
.
substr
(
0
,
track
.
length
-
2
);
track_num
++
;
album_track
+=
track_num
+
'. '
+
track
+
'\n'
;
}
});
}
else
{
year
=
$
(
'body > div.content-wrapper > article > div.wiki-content.clearfix > div > div:nth-child('
+
index
+
') > div:nth-child(4) > table > tbody > tr:nth-child(1) > td:nth-child(2)'
).
text
();
var
track_num
=
0
;
$
(
'body > div.content-wrapper > article > div.wiki-content.clearfix > div > div:nth-child('
+
index
+
') > div:nth-child(4) > table > tbody'
).
find
(
'tr'
).
each
(
function
(
index
,
ele
)
{
var
track
=
$
(
this
).
children
().
eq
(
1
).
text
();
if
(
track
!=
'1'
&&
track
!=
'곡명'
&&
track
[
4
]
!=
'년'
)
album_track
.
push
(
track
)
if
(
track
!=
'1'
&&
track
!=
'곡명'
&&
track
[
4
]
!=
'년'
){
if
(
track
[
track
.
length
-
1
]
==
'M'
)
track
=
track
.
substr
(
0
,
track
.
length
-
1
);
if
(
track
[
track
.
length
-
1
]
==
']'
)
track
=
track
.
substr
(
0
,
track
.
length
-
2
);
track_num
++
;
album_track
+=
track_num
+
'. '
+
track
+
'\n'
;
}
});
}
if
(
year
!=
''
)
{
...
...
@@ -44,6 +58,7 @@ function crawl_Reol(url,callback){
album_track
=
[];
}
});
Reol
.
push
({
json_album
,
json_year
,
json_track
});
callback
(
Reol
);
});
}
...
...
Please
register
or
login
to post a comment