Toggle navigation
Toggle navigation
This project
Loading...
Sign in
서민정
/
SEARCH-AND-CHAT
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
2
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
서민정
2020-05-19 16:06:25 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
72bdb346c061c1191c3b460fab7bc9c2bb831fa1
72bdb346
1 parent
ccf04f7a
update send crawling json to front
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
39 deletions
client/src/chatbot/chatbot.js
server/cheerio/video.js
server/routes/crawling.js
server/routes/dialogflow.js
client/src/chatbot/chatbot.js
View file @
72bdb34
...
...
@@ -40,19 +40,27 @@ function Chatbot() {
}
try
{
if
(
inputString
[
0
]
===
'@'
){
await
Axios
.
post
(
'/api/crawling/textQuery'
,
textQueryVariables
)
const
response
=
await
Axios
.
post
(
'/api/crawling/textQuery'
,
textQueryVariables
)
console
.
log
(
"res"
,
response
)
for
(
let
content
of
response
.
data
){
console
.
log
(
content
)
}
}
else
{
//I will send request to the textQuery ROUTE
const
response
=
await
Axios
.
post
(
'/api/dialogflow/textQuery'
,
textQueryVariables
)
for
(
let
content
of
response
.
data
.
fulfillmentMessages
)
{
conversation
=
{
who
:
'소통이'
,
content
:
content
}
console
.
log
(
"conversation: "
,
conversation
)
dispatch
(
saveMessage
(
conversation
))
}
}
...
...
server/cheerio/video.js
View file @
72bdb34
...
...
@@ -11,7 +11,7 @@ const cheerio = require('cheerio');
}
*/
function
video
(
name
){
module
.
exports
=
function
video
(
name
){
console
.
log
(
"My favorite singer"
,
name
)
var
url
=
'https://tv.naver.com/search/clip?query='
//naverTV의 링크
var
sort
=
'&sort=date'
...
...
@@ -43,11 +43,9 @@ function video(name){
})
var
data
=
videoList
.
filter
(
n
=>
n
.
title
);
data
=
data
.
slice
(
0
,
3
)
data
=
JSON
.
stringify
(
data
.
slice
(
0
,
3
)
)
return
data
;
})
//.then(res=>console.log(res));
}
module
.
exports
=
video
;
\ No newline at end of file
...
...
server/routes/crawling.js
View file @
72bdb34
const
express
=
require
(
'express'
);
const
router
=
express
.
Router
();
const
uuid
=
require
(
'uuid'
);
//uuid 제대로 이해하고 다시 작성하기.
const
getvideo
=
require
(
'../cheerio/video'
);
//const video = require('../cheerio/video');
const
axios
=
require
(
'axios'
);
const
cheerio
=
require
(
'cheerio'
);
//@가수명 으로 입력이 들어왔을 때, 가수명만 받아서
router
.
post
(
'/textQuery'
,
async
(
req
,
res
)
=>
{
router
.
post
(
'/textQuery'
,
async
(
req
,
res
)
=>
{
const
result
=
req
.
body
.
text
;
console
.
log
(
result
.
substring
(
1
));
var
videoList
=
getvideo
(
result
.
substring
(
1
));
/*
const request = {
session: sessionPath,
queryInput: {
text: {
// The query to send to the dialogflow agent
text: req.body.text,
// The language used by the client (en-US)
languageCode: languageCode,
},
},
var
name
=
result
.
substring
(
1
)
var
url
=
'https://tv.naver.com/search/clip?query='
//naverTV의 링크
var
sort
=
'&sort=date'
url
=
url
+
name
+
sort
url
=
encodeURI
(
url
)
console
.
log
(
"url is "
,
url
)
const
getHtml
=
async
()
=>
{
try
{
return
await
axios
.
get
(
url
);
//axios.get 함수를 이용해서 비동기로 네이버티비의 해당 가수의 최신 영상 html 파일을 가져온다.
}
catch
(
error
){
console
.
log
(
"error! check your code"
);
}
};
// Send request and log result
const responses = await sessionClient.detectIntent(request);
console.log('Detected intent');
const result = responses[0].queryResult;
console.log(` Query: ${result.queryText}`);
console.log(` Response: ${result.fulfillmentText}`);
*/
res
.
send
(
result
)
res
.
send
(
videoList
);
getHtml
()
.
then
(
html
=>
{
let
videoList
=
[];
const
$
=
cheerio
.
load
(
html
.
data
);
const
$bodyList
=
$
(
"div.src_wrap div.thl "
).
children
(
"div.thl_a"
);
$bodyList
.
each
(
function
(
i
,
elem
){
videoList
[
i
]
=
{
description
:
"naverTV"
,
image
:
$
(
this
).
find
(
'a.cds_thm'
).
children
(
'img'
).
attr
(
'src'
),
title
:
$
(
this
).
find
(
'a.cds_thm'
).
attr
(
'title'
),
link
:
"https://tv.naver.com/"
+
$
(
this
).
find
(
'a.cds_thm'
).
attr
(
'href'
)
}
})
data
=
videoList
.
filter
(
n
=>
n
.
title
);
data
=
JSON
.
stringify
(
data
.
slice
(
0
,
3
))
res
.
send
(
data
);
})
})
module
.
exports
=
router
;
\ No newline at end of file
...
...
server/routes/dialogflow.js
View file @
72bdb34
...
...
@@ -37,6 +37,7 @@ router.post('/textQuery', async (req, res) => {
console
.
log
(
` Query:
${
result
.
queryText
}
`
);
console
.
log
(
` Response:
${
result
.
fulfillmentText
}
`
);
res
.
send
(
result
)
})
...
...
Please
register
or
login
to post a comment