Toggle navigation
Toggle navigation
This project
Loading...
Sign in
은승우
/
LINEBOT
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
나혜원
2019-12-05 19:47:03 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e38a2e13b04bdf82102ad3259a6dc6ef35c5dbdf
e38a2e13
1 parent
a9e0b4a5
add concert function
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
34 deletions
app.js
app.js
View file @
e38a2e1
...
...
@@ -5,7 +5,7 @@ const line = require('@line/bot-sdk');
var
request
=
require
(
'request'
);
var
https
=
require
(
'https'
);
var
http
=
require
(
'http'
);
/*
const
lex
=
require
(
'greenlock-express'
).
create
({
version
:
'draft-11'
,
// 버전2
store
:
require
(
'greenlock-store-fs'
),
...
...
@@ -30,7 +30,7 @@ https.createServer(lex.httpsOptions, lex.middleware(app)).listen((process.env.SS
http
.
createServer
(
lex
.
middleware
(
require
(
'redirect-https'
)())).
listen
(
process
.
env
.
PORT
||
80
,()
=>
{
console
.
log
(
"server on 80"
);
});
*/
//번역 api_url
var
translate_api_url
=
'https://openapi.naver.com/v1/papago/n2mt'
;
...
...
@@ -70,7 +70,7 @@ for(var i = 0; i < data_list.length; i++){
}
for
(
var
i
=
0
;
i
<
concert_list
.
length
;
i
++
){
console
.
log
(
i
+
1
,
'
)
'
,
concert_list
[
i
],
'\n'
);
console
.
log
(
i
+
1
,
'
.
'
,
concert_list
[
i
],
'\n'
);
}
//콘서트 목록
...
...
@@ -102,41 +102,55 @@ function handleEvent(event) {
console
.
log
(
showlist
.
text
);
client
.
replyMessage
(
event
.
replyToken
,
showlist
).
then
(
resolve
).
catch
(
reject
);
});
}
else
if
(
isNaN
(
event
.
message
.
text
)){
var
selectnum
=
1
;
var
concert_name
=
concert_list
[
selectnum
];
var
$
=
cheerio
.
load
(
concert_name
);
var
keyword
=
$
.
text
();
console
.
log
(
keyword
);
//키워드 추출
var
options
=
{
method
:
'GET'
,
url
:
'https://www.googleapis.com/youtube/v3/search'
,
qs
:
{
key
:
'AIzaSyB4b-n8SSv73CLDKvFigpLPYA6yWG2JQ9A'
,
part
:
'id'
,
maxResults
:
'3'
,
order
:
'viewCount'
,
q
:
keyword
,
type
:
'video'
},
};
//youtube api
request
(
options
,
function
(
error
,
result
,
body
){
if
(
error
)
throw
new
Error
(
error
);
//var temp = body.replace('{','');
//var temp = temp.replace('}','');
var
temp1
=
body
.
split
(
':'
);
for
(
var
i
=
0
;
i
<
temp1
.
length
;
i
++
){
console
.
log
(
i
,
temp1
[
i
],
'\n'
);
var
selectnum
=
(
event
.
message
.
text
*
1
);
if
(
selectnum
>=
0
||
selectnum
<=
27
){
result
.
text
=
'목록에 존재하지 않는 콘서트입니다.'
;
client
.
replyMessage
(
event
.
replyToken
,
result
).
then
(
resolve
).
catch
(
reject
);
}
return
new
Promise
(
function
(
resolve
,
reject
){
var
concert_name
=
concert_list
[
selectnum
-
1
];
var
$
=
cheerio
.
load
(
concert_name
);
var
keyword
=
$
.
text
();
console
.
log
(
keyword
);
//console.log(temp1);
});
//search on youtube
var
options
=
{
method
:
'GET'
,
url
:
'https://www.googleapis.com/youtube/v3/search'
,
qs
:
{
key
:
'AIzaSyB4b-n8SSv73CLDKvFigpLPYA6yWG2JQ9A'
,
part
:
'id'
,
maxResults
:
'1'
,
order
:
'relevance'
,
q
:
keyword
,
type
:
'video'
}
};
var
videourl
=
{
type
:
'url'
,
label
:
'관련 영상'
,
url
:
''
};
request
(
options
,
function
(
error
,
result
,
body
){
if
(
error
)
throw
new
Error
(
error
);
var
temp
=
body
.
split
(
':'
);
videourl
.
url
+=
"https://www.youtube.com/watch?v="
+
temp1
[
13
].
substr
(
2
,
11
);
});
console
.
log
(
videourl
.
url
);
client
.
replyMessage
(
event
.
replyToken
,
videourl
).
then
(
resolve
).
catch
(
reject
);
})};
app
.
post
(
'/webhook'
,
line
.
middleware
(
config
),
(
req
,
res
)
=>
{
console
.
log
(
res
.
statusCode
);
Promise
.
all
(
req
.
body
.
events
.
map
(
handleEvent2
))
.
then
((
result
)
=>
res
.
json
(
result
))
.
catch
((
err
)
=>
{
console
.
log
(
err
);
})
});
return
new
Promise
(
function
(
resolve
,
reject
)
{
//언어 감지 option
...
...
Please
register
or
login
to post a comment