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 20:45:39 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
38a5ec3182d988b38a7f411dfe509cb3e9119aef
38a5ec31
1 parent
4380c0cb
Update app.js
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
0 deletions
app.js
app.js
View file @
38a5ec3
...
...
@@ -86,6 +86,65 @@ function handleEvent(event) {
// ignore non-text-message event
return
Promise
.
resolve
(
null
);
}
else
if
(
event
.
type
==
'message'
&&
event
.
message
.
type
==
"text"
&&
event
.
message
.
text
.
indexOf
(
'http'
)
!=-
1
)
{
return
new
Promise
(
async
(
resolve
,
reject
)
=>
{
var
cheerio
=
require
(
'cheerio'
);
var
uriBase
=
'https://koreacentral.api.cognitive.microsoft.com/vision/v2.1/ocr'
;
var
imageUrl
=
event
.
message
.
text
;
var
options
=
{
uri
:
uriBase
,
qs
:
{
'language'
:
'unk'
,
'detectOrientation'
:
'true'
,
},
headers
:
{
'Content-Type'
:
'application/json'
,
'Ocp-Apim-Subscription-Key'
:
'979dc5d63344438fa4701c62feebb7dc'
},
body
:
'{"url": '
+
'"'
+
imageUrl
+
'"}'
,
};
request
.
post
(
options
,
function
(
error
,
response
,
body
)
{
var
data
=
JSON
.
stringify
(
body
);
var
text
=
''
;
while
(
data
.
indexOf
(
'text\\'
)
!=-
1
)
{
data
=
data
.
substring
(
data
.
indexOf
(
'text\\'
)
+
9
);
text
+=
data
.
substring
(
0
,
data
.
indexOf
(
"\\"
))
+
" "
;
}
text
=
text
.
substring
(
text
.
length
/
10
+
1
,
text
.
length
/
8
+
2
);
console
.
log
(
text
);
var
url
=
"https://www.genie.co.kr/search/searchLyrics?query="
+
text
;
request
(
url
,
function
(
error
,
response
,
html
)
{
console
.
log
(
url
);
var
$
=
cheerio
.
load
(
html
);
const
$bodyList
=
$
(
'#body-content > div.search_lyrics > div.music-list-wrap.type-lyrics > table > tbody > tr'
);
var
songList
=
[];
$bodyList
.
each
(
function
(
i
,
elem
){
if
(
i
<
20
){
songList
.
push
({
singer
:
$
(
this
).
find
(
"td.info"
).
find
(
"a.artist.ellipsis"
).
text
().
trim
(),
song
:
$
(
this
).
find
(
"td.info"
).
find
(
"a.title.ellipsis"
).
text
().
trim
(),
});
}
})
var
resultm
=
''
;
for
(
var
i
=
0
;
i
<
songList
.
length
;
i
++
){
if
(
songList
[
i
].
singer
!=
''
){
resultm
+=
songList
[
i
].
singer
+
", "
+
songList
[
i
].
song
+
"\n"
;
}
}
var
result
=
{
type
:
'text'
,
text
:
resultm
};
client
.
replyMessage
(
event
.
replyToken
,
result
).
then
(
resolve
).
catch
(
reject
);
});
});
});
}
return
new
Promise
(
function
(
resolve
,
reject
)
{
//언어 감지 option
var
detect_options
=
{
...
...
Please
register
or
login
to post a comment