Showing
4 changed files
with
54 additions
and
39 deletions
| ... | @@ -40,19 +40,27 @@ function Chatbot() { | ... | @@ -40,19 +40,27 @@ function Chatbot() { |
| 40 | } | 40 | } |
| 41 | try { | 41 | try { |
| 42 | if(inputString[0] === '@'){ | 42 | if(inputString[0] === '@'){ |
| 43 | - await Axios.post('/api/crawling/textQuery', textQueryVariables) | 43 | + const response = await Axios.post('/api/crawling/textQuery', textQueryVariables) |
| 44 | + console.log("res",response) | ||
| 45 | + | ||
| 46 | + for(let content of response.data){ | ||
| 47 | + console.log(content) | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + | ||
| 51 | + | ||
| 44 | 52 | ||
| 45 | } else { | 53 | } else { |
| 46 | //I will send request to the textQuery ROUTE | 54 | //I will send request to the textQuery ROUTE |
| 47 | const response = await Axios.post('/api/dialogflow/textQuery', textQueryVariables) | 55 | const response = await Axios.post('/api/dialogflow/textQuery', textQueryVariables) |
| 48 | - | 56 | + |
| 49 | for (let content of response.data.fulfillmentMessages) { | 57 | for (let content of response.data.fulfillmentMessages) { |
| 50 | - | 58 | + |
| 51 | conversation = { | 59 | conversation = { |
| 52 | who: '소통이', | 60 | who: '소통이', |
| 53 | content: content | 61 | content: content |
| 54 | } | 62 | } |
| 55 | - | 63 | + console.log("conversation: ",conversation) |
| 56 | dispatch(saveMessage(conversation)) | 64 | dispatch(saveMessage(conversation)) |
| 57 | } | 65 | } |
| 58 | } | 66 | } | ... | ... |
| ... | @@ -11,7 +11,7 @@ const cheerio = require('cheerio'); | ... | @@ -11,7 +11,7 @@ const cheerio = require('cheerio'); |
| 11 | } | 11 | } |
| 12 | */ | 12 | */ |
| 13 | 13 | ||
| 14 | -function video(name){ | 14 | +module.exports = function video(name){ |
| 15 | console.log("My favorite singer",name) | 15 | console.log("My favorite singer",name) |
| 16 | var url = 'https://tv.naver.com/search/clip?query=' //naverTV의 링크 | 16 | var url = 'https://tv.naver.com/search/clip?query=' //naverTV의 링크 |
| 17 | var sort = '&sort=date' | 17 | var sort = '&sort=date' |
| ... | @@ -43,11 +43,9 @@ function video(name){ | ... | @@ -43,11 +43,9 @@ function video(name){ |
| 43 | }) | 43 | }) |
| 44 | 44 | ||
| 45 | var data = videoList.filter(n => n.title); | 45 | var data = videoList.filter(n => n.title); |
| 46 | - data = data.slice(0,3) | 46 | + data = JSON.stringify(data.slice(0,3)) |
| 47 | 47 | ||
| 48 | return data; | 48 | return data; |
| 49 | }) | 49 | }) |
| 50 | //.then(res=>console.log(res)); | 50 | //.then(res=>console.log(res)); |
| 51 | } | 51 | } |
| 52 | - | ||
| 53 | -module.exports = video; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| 1 | const express = require('express'); | 1 | const express = require('express'); |
| 2 | const router = express.Router(); | 2 | const router = express.Router(); |
| 3 | const uuid = require('uuid'); //uuid 제대로 이해하고 다시 작성하기. | 3 | const uuid = require('uuid'); //uuid 제대로 이해하고 다시 작성하기. |
| 4 | -const getvideo = require('../cheerio/video'); | 4 | +//const video = require('../cheerio/video'); |
| 5 | + | ||
| 6 | +const axios = require('axios'); | ||
| 7 | +const cheerio = require('cheerio'); | ||
| 8 | + | ||
| 5 | //@가수명 으로 입력이 들어왔을 때, 가수명만 받아서 | 9 | //@가수명 으로 입력이 들어왔을 때, 가수명만 받아서 |
| 6 | 10 | ||
| 7 | -router.post('/textQuery',async(req,res)=>{ | 11 | +router.post('/textQuery', async(req,res)=>{ |
| 8 | const result = req.body.text; | 12 | const result = req.body.text; |
| 9 | - console.log(result.substring(1)); | 13 | + var name = result.substring(1) |
| 10 | - var videoList = getvideo(result.substring(1)); | 14 | + |
| 11 | - | 15 | + var url = 'https://tv.naver.com/search/clip?query=' //naverTV의 링크 |
| 12 | - /* | 16 | + var sort = '&sort=date' |
| 13 | - const request = { | 17 | + url = url + name + sort |
| 14 | - session: sessionPath, | 18 | + url = encodeURI(url) |
| 15 | - queryInput: { | 19 | + console.log("url is ",url) |
| 16 | - text: { | 20 | + const getHtml = async() => { |
| 17 | - // The query to send to the dialogflow agent | 21 | + try{ |
| 18 | - text: req.body.text, | 22 | + return await axios.get(url); //axios.get 함수를 이용해서 비동기로 네이버티비의 해당 가수의 최신 영상 html 파일을 가져온다. |
| 19 | - // The language used by the client (en-US) | 23 | + } catch(error){ |
| 20 | - languageCode: languageCode, | 24 | + console.log("error! check your code"); |
| 21 | - }, | 25 | + } |
| 22 | - }, | ||
| 23 | }; | 26 | }; |
| 24 | 27 | ||
| 25 | - // Send request and log result | 28 | + getHtml() |
| 26 | - const responses = await sessionClient.detectIntent(request); | 29 | + .then(html => { |
| 27 | - console.log('Detected intent'); | 30 | + let videoList = []; |
| 28 | - const result = responses[0].queryResult; | 31 | + const $ = cheerio.load(html.data); |
| 29 | - console.log(` Query: ${result.queryText}`); | 32 | + const $bodyList = $("div.src_wrap div.thl ").children("div.thl_a"); |
| 30 | - console.log(` Response: ${result.fulfillmentText}`); | 33 | + |
| 31 | - */ | 34 | + $bodyList.each(function(i, elem){ |
| 32 | - res.send(result) | 35 | + videoList[i] = { |
| 33 | - | 36 | + description : "naverTV", |
| 34 | - | 37 | + image : $(this).find('a.cds_thm').children('img').attr('src'), |
| 35 | - | 38 | + title : $(this).find('a.cds_thm').attr('title'), |
| 36 | - | 39 | + link : "https://tv.naver.com/" + $(this).find('a.cds_thm').attr('href') |
| 37 | - | 40 | + } |
| 38 | - | 41 | + }) |
| 39 | - res.send(videoList); | 42 | + |
| 43 | + data = videoList.filter(n => n.title); | ||
| 44 | + data = JSON.stringify(data.slice(0,3)) | ||
| 45 | + | ||
| 46 | + res.send(data); | ||
| 47 | + }) | ||
| 40 | }) | 48 | }) |
| 41 | 49 | ||
| 42 | module.exports = router; | 50 | module.exports = router; |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -37,6 +37,7 @@ router.post('/textQuery', async (req, res) => { | ... | @@ -37,6 +37,7 @@ router.post('/textQuery', async (req, res) => { |
| 37 | console.log(` Query: ${result.queryText}`); | 37 | console.log(` Query: ${result.queryText}`); |
| 38 | console.log(` Response: ${result.fulfillmentText}`); | 38 | console.log(` Response: ${result.fulfillmentText}`); |
| 39 | 39 | ||
| 40 | + | ||
| 40 | res.send(result) | 41 | res.send(result) |
| 41 | }) | 42 | }) |
| 42 | 43 | ... | ... |
-
Please register or login to post a comment