Showing
8 changed files
with
193 additions
and
17 deletions
client/src/chatbot/Check.js
0 → 100644
1 | +function CheckString(inputString){ | ||
2 | + var from = 0; | ||
3 | + var len = 0; | ||
4 | + for(var i = 0; i < inputString.length; i++){ | ||
5 | + if(inputString[i] === '_'){ | ||
6 | + from = i; | ||
7 | + break; | ||
8 | + } | ||
9 | + } | ||
10 | + | ||
11 | + len = inputString.length - from; | ||
12 | + return inputString.substr(from,len); | ||
13 | +} | ||
14 | + | ||
15 | +export default CheckString; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -5,8 +5,9 @@ import { saveMessage } from '../_actions/message_actions'; | ... | @@ -5,8 +5,9 @@ import { saveMessage } from '../_actions/message_actions'; |
5 | import Message from './Sections/Message'; | 5 | import Message from './Sections/Message'; |
6 | import { List, Icon, Avatar } from 'antd'; | 6 | import { List, Icon, Avatar } from 'antd'; |
7 | import Card from "./Sections/Card"; | 7 | import Card from "./Sections/Card"; |
8 | -var username = prompt('이름을 알려주세요!'); | 8 | +import CheckString from './Check'; |
9 | -if(username === null) username = "유저" | 9 | +const username = "유저"; |
10 | + | ||
10 | function Chatbot() { | 11 | function Chatbot() { |
11 | const dispatch = useDispatch(); | 12 | const dispatch = useDispatch(); |
12 | const messagesFromRedux = useSelector(state => state.message.messages) | 13 | const messagesFromRedux = useSelector(state => state.message.messages) |
... | @@ -42,6 +43,29 @@ function Chatbot() { | ... | @@ -42,6 +43,29 @@ function Chatbot() { |
42 | } | 43 | } |
43 | try { | 44 | try { |
44 | if(inputString[0] === '@'){ | 45 | if(inputString[0] === '@'){ |
46 | + inputString = CheckString(inputString); | ||
47 | + if(inputString === '최신'){ | ||
48 | + | ||
49 | + } | ||
50 | + else if(inputString === '인기'){ | ||
51 | + | ||
52 | + } | ||
53 | + else if(inputString === '다운'){ | ||
54 | + | ||
55 | + } | ||
56 | + else { | ||
57 | + conversation = { | ||
58 | + who: '소통이', | ||
59 | + content: { | ||
60 | + text: { | ||
61 | + text: "잘못된 입력입니다. 다시 입력해주세요!" | ||
62 | + } | ||
63 | + } | ||
64 | + } | ||
65 | + | ||
66 | + dispatch(saveMessage(conversation)) | ||
67 | + } | ||
68 | + | ||
45 | const response = await Axios.post('/api/crawling/textQuery', textQueryVariables) | 69 | const response = await Axios.post('/api/crawling/textQuery', textQueryVariables) |
46 | let conversations = {} | 70 | let conversations = {} |
47 | let pushConversations = [] | 71 | let pushConversations = [] |
... | @@ -189,10 +213,10 @@ function Chatbot() { | ... | @@ -189,10 +213,10 @@ function Chatbot() { |
189 | 213 | ||
190 | return ( | 214 | return ( |
191 | <div style={{ | 215 | <div style={{ |
192 | - height: 620, width: 700, | 216 | + height: 650, width: 700, |
193 | border: '3px solid black', borderRadius: '7px' | 217 | border: '3px solid black', borderRadius: '7px' |
194 | }}> | 218 | }}> |
195 | - <div style={{ height: 564, width: '100%', overflow: 'auto' }}> | 219 | + <div style={{ height: 594, width: '100%', overflow: 'auto' }}> |
196 | 220 | ||
197 | 221 | ||
198 | {renderMessage(messagesFromRedux)} | 222 | {renderMessage(messagesFromRedux)} | ... | ... |
... | @@ -10,6 +10,9 @@ app.use(bodyParser.json()); | ... | @@ -10,6 +10,9 @@ app.use(bodyParser.json()); |
10 | 10 | ||
11 | app.use('/api/crawling', require('./server/routes/crawling')); | 11 | app.use('/api/crawling', require('./server/routes/crawling')); |
12 | app.use('/api/dialogflow', require('./server/routes/dialogflow')); | 12 | app.use('/api/dialogflow', require('./server/routes/dialogflow')); |
13 | +app.use('/api/latest',require('./server/routes/latest')); | ||
14 | +app.use('/api/popular',require('./server/routes/popular')); | ||
15 | +app.use('/api/download',require('./server/routes/download')); | ||
13 | 16 | ||
14 | // Serve static assets if in production | 17 | // Serve static assets if in production |
15 | if (process.env.NODE_ENV === "production") { | 18 | if (process.env.NODE_ENV === "production") { | ... | ... |
... | @@ -21,7 +21,6 @@ | ... | @@ -21,7 +21,6 @@ |
21 | "dialogflow": "^0.8.2", | 21 | "dialogflow": "^0.8.2", |
22 | "dialogflow-fulfillment": "^0.6.1", | 22 | "dialogflow-fulfillment": "^0.6.1", |
23 | "express": "^4.16.4", | 23 | "express": "^4.16.4", |
24 | - "mongoose": "^5.4.20", | ||
25 | "cheerio": "^1.0.0-rc.3", | 24 | "cheerio": "^1.0.0-rc.3", |
26 | "axios" : "^0.19.2" | 25 | "axios" : "^0.19.2" |
27 | }, | 26 | }, | ... | ... |
server/models/Opinion.js
deleted
100644 → 0
server/routes/download.js
0 → 100644
1 | +const express = require('express'); | ||
2 | +const router = express.Router(); | ||
3 | +const uuid = require('uuid'); //uuid 제대로 이해하고 다시 작성하기. | ||
4 | + | ||
5 | +const axios = require('axios'); | ||
6 | +const cheerio = require('cheerio'); | ||
7 | + | ||
8 | +//@가수명 으로 입력이 들어왔을 때, 가수명만 받아서 | ||
9 | + | ||
10 | +router.post('/textQuery', async(req,res)=>{ | ||
11 | + const result = req.body.text; | ||
12 | + var name = result.substring(1) | ||
13 | + | ||
14 | + var url = 'https://tv.naver.com/search/clip?query=' //naverTV의 링크 | ||
15 | + var sort = '&sort=date' | ||
16 | + url = url + name + sort | ||
17 | + url = encodeURI(url) | ||
18 | + console.log("url is ",url) | ||
19 | + const getHtml = async() => { | ||
20 | + try{ | ||
21 | + return await axios.get(url); //axios.get 함수를 이용해서 비동기로 네이버티비의 해당 가수의 최신 영상 html 파일을 가져온다. | ||
22 | + } catch(error){ | ||
23 | + console.log("error! check your code"); | ||
24 | + } | ||
25 | + }; | ||
26 | + | ||
27 | + getHtml() | ||
28 | + .then(html => { | ||
29 | + let videoList = []; | ||
30 | + const $ = cheerio.load(html.data); | ||
31 | + const $bodyList = $("div.src_wrap div.thl ").children("div.thl_a"); | ||
32 | + | ||
33 | + $bodyList.each(function(i, elem){ | ||
34 | + videoList[i] = { | ||
35 | + description : "naverTV", | ||
36 | + image : $(this).find('a.cds_thm').children('img').attr('src'), | ||
37 | + title : $(this).find('a.cds_thm').attr('title'), | ||
38 | + link : "https://tv.naver.com/" + $(this).find('a.cds_thm').attr('href') | ||
39 | + } | ||
40 | + }) | ||
41 | + | ||
42 | + data = videoList.filter(n => n.title); | ||
43 | + data = JSON.stringify(data.slice(0,3)) | ||
44 | + | ||
45 | + res.send(data); | ||
46 | + }) | ||
47 | +}) | ||
48 | + | ||
49 | +module.exports = router; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
server/routes/latest.js
0 → 100644
1 | +const express = require('express'); | ||
2 | +const router = express.Router(); | ||
3 | +const uuid = require('uuid'); //uuid 제대로 이해하고 다시 작성하기. | ||
4 | + | ||
5 | +const axios = require('axios'); | ||
6 | +const cheerio = require('cheerio'); | ||
7 | + | ||
8 | +//@가수명 으로 입력이 들어왔을 때, 가수명만 받아서 | ||
9 | + | ||
10 | +router.post('/textQuery', async(req,res)=>{ | ||
11 | + const result = req.body.text; | ||
12 | + var name = result.substring(1) | ||
13 | + | ||
14 | + var url = 'https://tv.naver.com/search/clip?query=' //naverTV의 링크 | ||
15 | + var sort = '&sort=date' | ||
16 | + url = url + name + sort | ||
17 | + url = encodeURI(url) | ||
18 | + console.log("url is ",url) | ||
19 | + const getHtml = async() => { | ||
20 | + try{ | ||
21 | + return await axios.get(url); //axios.get 함수를 이용해서 비동기로 네이버티비의 해당 가수의 최신 영상 html 파일을 가져온다. | ||
22 | + } catch(error){ | ||
23 | + console.log("error! check your code"); | ||
24 | + } | ||
25 | + }; | ||
26 | + | ||
27 | + getHtml() | ||
28 | + .then(html => { | ||
29 | + let videoList = []; | ||
30 | + const $ = cheerio.load(html.data); | ||
31 | + const $bodyList = $("div.src_wrap div.thl ").children("div.thl_a"); | ||
32 | + | ||
33 | + $bodyList.each(function(i, elem){ | ||
34 | + videoList[i] = { | ||
35 | + description : "naverTV", | ||
36 | + image : $(this).find('a.cds_thm').children('img').attr('src'), | ||
37 | + title : $(this).find('a.cds_thm').attr('title'), | ||
38 | + link : "https://tv.naver.com/" + $(this).find('a.cds_thm').attr('href') | ||
39 | + } | ||
40 | + }) | ||
41 | + | ||
42 | + data = videoList.filter(n => n.title); | ||
43 | + data = JSON.stringify(data.slice(0,3)) | ||
44 | + | ||
45 | + res.send(data); | ||
46 | + }) | ||
47 | +}) | ||
48 | + | ||
49 | +module.exports = router; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
server/routes/popular.js
0 → 100644
1 | +const express = require('express'); | ||
2 | +const router = express.Router(); | ||
3 | +const uuid = require('uuid'); //uuid 제대로 이해하고 다시 작성하기. | ||
4 | + | ||
5 | +const axios = require('axios'); | ||
6 | +const cheerio = require('cheerio'); | ||
7 | + | ||
8 | +//@가수명 으로 입력이 들어왔을 때, 가수명만 받아서 | ||
9 | + | ||
10 | +router.post('/textQuery', async(req,res)=>{ | ||
11 | + const result = req.body.text; | ||
12 | + var name = result.substring(1) | ||
13 | + | ||
14 | + var url = 'https://tv.naver.com/search/clip?query=' //naverTV의 링크 | ||
15 | + var sort = '&sort=date' | ||
16 | + url = url + name + sort | ||
17 | + url = encodeURI(url) | ||
18 | + console.log("url is ",url) | ||
19 | + const getHtml = async() => { | ||
20 | + try{ | ||
21 | + return await axios.get(url); //axios.get 함수를 이용해서 비동기로 네이버티비의 해당 가수의 최신 영상 html 파일을 가져온다. | ||
22 | + } catch(error){ | ||
23 | + console.log("error! check your code"); | ||
24 | + } | ||
25 | + }; | ||
26 | + | ||
27 | + getHtml() | ||
28 | + .then(html => { | ||
29 | + let videoList = []; | ||
30 | + const $ = cheerio.load(html.data); | ||
31 | + const $bodyList = $("div.src_wrap div.thl ").children("div.thl_a"); | ||
32 | + | ||
33 | + $bodyList.each(function(i, elem){ | ||
34 | + videoList[i] = { | ||
35 | + description : "naverTV", | ||
36 | + image : $(this).find('a.cds_thm').children('img').attr('src'), | ||
37 | + title : $(this).find('a.cds_thm').attr('title'), | ||
38 | + link : "https://tv.naver.com/" + $(this).find('a.cds_thm').attr('href') | ||
39 | + } | ||
40 | + }) | ||
41 | + | ||
42 | + data = videoList.filter(n => n.title); | ||
43 | + data = JSON.stringify(data.slice(0,3)) | ||
44 | + | ||
45 | + res.send(data); | ||
46 | + }) | ||
47 | +}) | ||
48 | + | ||
49 | +module.exports = router; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment