서민정

add web crawling module

...@@ -1323,9 +1323,9 @@ ...@@ -1323,9 +1323,9 @@
1323 }, 1323 },
1324 "dependencies": { 1324 "dependencies": {
1325 "acorn": { 1325 "acorn": {
1326 - "version": "5.7.3", 1326 + "version": "5.7.4",
1327 - "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.3.tgz", 1327 + "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.4.tgz",
1328 - "integrity": "sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw==" 1328 + "integrity": "sha512-1D++VG7BhrtvQpNbBzovKNc1FLGGEE/oGe7b9xJm/RFHMBeUaUGpluV9RLjZa47YFdPcDAenEYuq9pQPcMdLJg=="
1329 } 1329 }
1330 } 1330 }
1331 }, 1331 },
...@@ -8448,9 +8448,9 @@ ...@@ -8448,9 +8448,9 @@
8448 }, 8448 },
8449 "dependencies": { 8449 "dependencies": {
8450 "acorn": { 8450 "acorn": {
8451 - "version": "5.7.3", 8451 + "version": "5.7.4",
8452 - "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.3.tgz", 8452 + "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.4.tgz",
8453 - "integrity": "sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw==" 8453 + "integrity": "sha512-1D++VG7BhrtvQpNbBzovKNc1FLGGEE/oGe7b9xJm/RFHMBeUaUGpluV9RLjZa47YFdPcDAenEYuq9pQPcMdLJg=="
8454 }, 8454 },
8455 "parse5": { 8455 "parse5": {
8456 "version": "4.0.0", 8456 "version": "4.0.0",
...@@ -15942,9 +15942,9 @@ ...@@ -15942,9 +15942,9 @@
15942 }, 15942 },
15943 "dependencies": { 15943 "dependencies": {
15944 "acorn": { 15944 "acorn": {
15945 - "version": "5.7.3", 15945 + "version": "5.7.4",
15946 - "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.3.tgz", 15946 + "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.4.tgz",
15947 - "integrity": "sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw==" 15947 + "integrity": "sha512-1D++VG7BhrtvQpNbBzovKNc1FLGGEE/oGe7b9xJm/RFHMBeUaUGpluV9RLjZa47YFdPcDAenEYuq9pQPcMdLJg=="
15948 }, 15948 },
15949 "eslint-scope": { 15949 "eslint-scope": {
15950 "version": "4.0.3", 15950 "version": "4.0.3",
......
...@@ -6,7 +6,7 @@ const { Title } = Typography; ...@@ -6,7 +6,7 @@ const { Title } = Typography;
6 function App() { 6 function App() {
7 return ( 7 return (
8 <div> 8 <div>
9 - <div style={{ display: 'flex', justifyContent: 'center', marginTop: '2rem' }}> 9 + <div style={{ display: 'flex', justifyContent: 'center', marginTop: '1rem' }}>
10 <Title level={2} >CHATBOT&nbsp;<Icon type="robot" /></Title> 10 <Title level={2} >CHATBOT&nbsp;<Icon type="robot" /></Title>
11 </div> 11 </div>
12 <div style={{ display: 'flex', justifyContent: 'center' }}> 12 <div style={{ display: 'flex', justifyContent: 'center' }}>
......
...@@ -11,7 +11,8 @@ function Chatbot() { ...@@ -11,7 +11,8 @@ function Chatbot() {
11 11
12 useEffect(() => { 12 useEffect(() => {
13 13
14 - eventQuery('welcomeToMyWebsite') 14 + eventQuery('001_Welcome')
15 + eventQuery('002_Intro')
15 16
16 }, []) 17 }, [])
17 18
...@@ -39,7 +40,7 @@ function Chatbot() { ...@@ -39,7 +40,7 @@ function Chatbot() {
39 } 40 }
40 try { 41 try {
41 if(inputString[0] === '@'){ 42 if(inputString[0] === '@'){
42 - const response = await Axios.post('/api/crawling/textQuery', textQueryVariables) 43 + await Axios.post('/api/crawling/textQuery', textQueryVariables)
43 } else { 44 } else {
44 //I will send request to the textQuery ROUTE 45 //I will send request to the textQuery ROUTE
45 const response = await Axios.post('/api/dialogflow/textQuery', textQueryVariables) 46 const response = await Axios.post('/api/dialogflow/textQuery', textQueryVariables)
...@@ -47,7 +48,7 @@ function Chatbot() { ...@@ -47,7 +48,7 @@ function Chatbot() {
47 for (let content of response.data.fulfillmentMessages) { 48 for (let content of response.data.fulfillmentMessages) {
48 49
49 conversation = { 50 conversation = {
50 - who: 'bot', 51 + who: '소통이',
51 content: content 52 content: content
52 } 53 }
53 54
...@@ -57,7 +58,7 @@ function Chatbot() { ...@@ -57,7 +58,7 @@ function Chatbot() {
57 58
58 } catch (error) { 59 } catch (error) {
59 conversation = { 60 conversation = {
60 - who: 'bot', 61 + who: '소통이',
61 content: { 62 content: {
62 text: { 63 text: {
63 text: " Error just occured, please check the problem" 64 text: " Error just occured, please check the problem"
...@@ -77,13 +78,16 @@ function Chatbot() { ...@@ -77,13 +78,16 @@ function Chatbot() {
77 const eventQueryVariables = { 78 const eventQueryVariables = {
78 event 79 event
79 } 80 }
81 +
82 +
83 +
80 try { 84 try {
81 //I will send request to the textQuery ROUTE 85 //I will send request to the textQuery ROUTE
82 const response = await Axios.post('/api/dialogflow/eventQuery', eventQueryVariables) 86 const response = await Axios.post('/api/dialogflow/eventQuery', eventQueryVariables)
83 for (let content of response.data.fulfillmentMessages) { 87 for (let content of response.data.fulfillmentMessages) {
84 88
85 let conversation = { 89 let conversation = {
86 - who: 'bot', 90 + who: '소통이',
87 content: content 91 content: content
88 } 92 }
89 93
...@@ -93,7 +97,7 @@ function Chatbot() { ...@@ -93,7 +97,7 @@ function Chatbot() {
93 97
94 } catch (error) { 98 } catch (error) {
95 let conversation = { 99 let conversation = {
96 - who: 'bot', 100 + who: '소통이',
97 content: { 101 content: {
98 text: { 102 text: {
99 text: " Error just occured, please check the problem" 103 text: " Error just occured, please check the problem"
...@@ -110,7 +114,7 @@ function Chatbot() { ...@@ -110,7 +114,7 @@ function Chatbot() {
110 if (e.key === "Enter") { 114 if (e.key === "Enter") {
111 115
112 if (!e.target.value) { 116 if (!e.target.value) {
113 - return alert('you need to type somthing first') 117 + return alert('you need to type something first')
114 } 118 }
115 119
116 //we will send request to text query route 120 //we will send request to text query route
...@@ -136,7 +140,7 @@ function Chatbot() { ...@@ -136,7 +140,7 @@ function Chatbot() {
136 return <Message key={i} who={message.who} text={message.content.text.text} /> 140 return <Message key={i} who={message.who} text={message.content.text.text} />
137 } else if (message.content && message.content.payload.fields.card) { 141 } else if (message.content && message.content.payload.fields.card) {
138 142
139 - const AvatarSrc = message.who === 'bot' ? <Icon type="robot" /> : <Icon type="smile" /> 143 + const AvatarSrc = message.who === '소통이' ? <Icon type="robot" /> : <Icon type="smile" />
140 144
141 return <div> 145 return <div>
142 <List.Item style={{ padding: '1rem' }}> 146 <List.Item style={{ padding: '1rem' }}>
...@@ -175,10 +179,10 @@ function Chatbot() { ...@@ -175,10 +179,10 @@ function Chatbot() {
175 179
176 return ( 180 return (
177 <div style={{ 181 <div style={{
178 - height: 500, width: 700, 182 + height: 620, width: 700,
179 border: '3px solid black', borderRadius: '7px' 183 border: '3px solid black', borderRadius: '7px'
180 }}> 184 }}>
181 - <div style={{ height: 444, width: '100%', overflow: 'auto' }}> 185 + <div style={{ height: 564, width: '100%', overflow: 'auto' }}>
182 186
183 187
184 {renderMessage(messagesFromRedux)} 188 {renderMessage(messagesFromRedux)}
......
1 +@import url('https://fonts.googleapis.com/css2?family=Nanum+Gothic&display=swap');
1 * { 2 * {
2 word-break: keep-all; 3 word-break: keep-all;
3 overflow-wrap: break-word; 4 overflow-wrap: break-word;
...@@ -12,7 +13,7 @@ body { ...@@ -12,7 +13,7 @@ body {
12 body { 13 body {
13 margin: 0; 14 margin: 0;
14 padding: 0; 15 padding: 0;
15 - font-family: Lato, Helvetica Neue, Arial, Helvetica, sans-serif; 16 + font-family: Nanum Gothic,Lato, Helvetica Neue, Arial, Helvetica, sans-serif;
16 -webkit-font-smoothing: antialiased; 17 -webkit-font-smoothing: antialiased;
17 } 18 }
18 19
......
...@@ -4,15 +4,11 @@ const bodyParser = require("body-parser"); ...@@ -4,15 +4,11 @@ const bodyParser = require("body-parser");
4 const app = express(); 4 const app = express();
5 5
6 const config = require("./server/config/keys"); 6 const config = require("./server/config/keys");
7 -// const mongoose = require("mongoose");
8 -// mongoose.connect(config.mongoURI, { useNewUrlParser: true, useUnifiedTopology: true })
9 -// .then(() => console.log('MongoDB Connected...'))
10 -// .catch(err => console.log(err));
11 7
12 app.use(bodyParser.urlencoded({ extended: true })); 8 app.use(bodyParser.urlencoded({ extended: true }));
13 app.use(bodyParser.json()); 9 app.use(bodyParser.json());
14 10
15 - 11 +app.use('/api/crawling', require('./server/routes/crawling'));
16 app.use('/api/dialogflow', require('./server/routes/dialogflow')); 12 app.use('/api/dialogflow', require('./server/routes/dialogflow'));
17 13
18 // Serve static assets if in production 14 // Serve static assets if in production
......
1 +const axios = require('axios');
2 +const cheerio = require('cheerio');
3 +
4 +/*
5 +한글 utf-8 인코딩해서 searchquery에 저장해야함.
6 +*/
7 +
8 +function video(name){
9 + console.log("My favorite singer",name)
10 + var url = 'https://tv.naver.com/search/clip?query=' //naverTV의 링크
11 + var sort = '&sort=date'
12 +
13 + url = url + name + sort
14 + url = encodeURI(url)
15 + console.log("url is ",url)
16 + const getHtml = async() => {
17 + try{
18 + return await axios.get(url); //axios.get 함수를 이용해서 비동기로 네이버티비의 해당 가수의 최신 영상 html 파일을 가져온다.
19 + } catch(error){
20 + console.log("error! check your code");
21 + }
22 + };
23 +
24 + getHtml()
25 + .then(html => {
26 + let videoList = [];
27 + const $ = cheerio.load(html.data);
28 + const $bodyList = $("div.src_wrap div.thl ").children("div.thl_a");
29 +
30 + $bodyList.each(function(i, elem){
31 + videoList[i] = {
32 + thumbnail : $(this).find('a.cds_thm').children('img').attr('src'),
33 + title : $(this).find('a.cds_thm').attr('title'),
34 + link : "https://tv.naver.com/" + $(this).find('a.cds_thm').attr('href')
35 + }
36 + })
37 +
38 + const data = videoList.filter(n => n.title);
39 + return data;
40 + })
41 + .then(res=>console.log(res));
42 +}
43 +
44 +module.exports = video;
...\ No newline at end of file ...\ No newline at end of file
1 +const express = require('express');
2 +const router = express.Router();
3 +const uuid = require('uuid'); //uuid 제대로 이해하고 다시 작성하기.
4 +const getvideo = require('../cheerio/video');
5 +//@가수명 으로 입력이 들어왔을 때, 가수명만 받아서
6 +
7 +router.post('/textQuery',async(req,res)=>{
8 + const result = req.body.text;
9 + console.log(result.substring(1));
10 + getvideo(result.substring(1));
11 + res.send(result);
12 +})
13 +
14 +module.exports = router;
...\ No newline at end of file ...\ No newline at end of file
...@@ -15,14 +15,9 @@ const languageCode = config.dialogFlowSessionLanguageCode ...@@ -15,14 +15,9 @@ const languageCode = config.dialogFlowSessionLanguageCode
15 const sessionClient = new dialogflow.SessionsClient(); 15 const sessionClient = new dialogflow.SessionsClient();
16 const sessionPath = sessionClient.sessionPath(projectId, sessionId); 16 const sessionPath = sessionClient.sessionPath(projectId, sessionId);
17 17
18 -// We will make two routes
19 -
20 -
21 // Text Query Route 18 // Text Query Route
22 19
23 router.post('/textQuery', async (req, res) => { 20 router.post('/textQuery', async (req, res) => {
24 - //We need to send some information that comes from the client to Dialogflow API
25 - // The text query request.
26 const request = { 21 const request = {
27 session: sessionPath, 22 session: sessionPath,
28 queryInput: { 23 queryInput: {
......