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 01:09:46 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
3d2f0e1ebaa0441011085625b4de6a27d9e77d91
3d2f0e1e
1 parent
ca86a129
ocr com?
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
2 deletions
app.js
app.js
View file @
3d2f0e1
...
...
@@ -80,8 +80,59 @@ function handleEvent(event) {
}
else
if
(
event
.
type
==
'message'
&&
event
.
message
.
type
==
'image'
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
var
upload
=
multer
({
dest
:
'photo/'
})
upload
.
single
(
event
.
message
.
image
);
var
cheerio
=
require
(
'cheerio'
);
let
subscriptionKey
=
process
.
env
[
'COMPUTER_VISION_SUBSCRIPTION_KEY'
];
let
endpoint
=
process
.
env
[
'COMPUTER_VISION_ENDPOINT'
];
var
uriBase
=
endpoint
+
'vision/v2.1/ocr'
;
var
options
=
{
uri
:
uriBase
,
qs
:
{
visualFeatures
:
'Categories'
,
details
:
''
,
language
:
'en'
},
headers
:
{
'Content-Type'
:
'application/octet-stream'
,
'Ocp-Apim-Subscription-Key'
:
subscriptionKey
},
body
:
fs
.
readFileSync
(
event
.
message
.
image
)
};
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
(
"\\"
))
+
" "
;
}
console
.
log
(
text
);
text
=
"나의모든날들"
;
console
.
log
(
text
);
var
url
=
"https://www.genie.co.kr/search/searchLyrics?query="
+
encodeURI
(
text
);
request
(
url
,
function
(
error
,
response
,
html
){
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
result
=
''
;
for
(
var
i
=
0
;
i
<
songList
.
length
;
i
++
){
if
(
songList
[
i
].
singer
!=
''
){
result
+=
songList
[
i
].
singer
+
", "
+
songList
[
i
].
song
+
"\n"
;
}
}
client
.
replyMessage
(
event
.
replyToken
,
result
).
then
(
resolve
).
catch
(
reject
);
});
});
})
}
...
...
Please
register
or
login
to post a comment