서민정

update crawling videos sorted by related

...@@ -3,7 +3,7 @@ function CheckString(inputString){ ...@@ -3,7 +3,7 @@ function CheckString(inputString){
3 var len = 0; 3 var len = 0;
4 for(var i = 0; i < inputString.length; i++){ 4 for(var i = 0; i < inputString.length; i++){
5 if(inputString[i] === '_'){ 5 if(inputString[i] === '_'){
6 - from = i; 6 + from = i+1;
7 break; 7 break;
8 } 8 }
9 } 9 }
......
...@@ -43,30 +43,21 @@ function Chatbot() { ...@@ -43,30 +43,21 @@ function Chatbot() {
43 } 43 }
44 try { 44 try {
45 if(inputString[0] === '@'){ 45 if(inputString[0] === '@'){
46 + console.log("첫번째 i", inputString);
46 inputString = CheckString(inputString); 47 inputString = CheckString(inputString);
47 - if(inputString === '최신'){ 48 + console.log("두번째 i",inputString);
48 - 49 + let response;
49 - } 50 + if(inputString === '최신'){ //@가수명_최신
50 - else if(inputString === '인기'){ 51 + response = await Axios.post('/api/latest/textQuery', textQueryVariables)
51 -
52 - }
53 - else if(inputString === '다운'){
54 -
55 - }
56 - else {
57 - conversation = {
58 - who: '소통이',
59 - content: {
60 - text: {
61 - text: "잘못된 입력입니다. 다시 입력해주세요!"
62 - }
63 } 52 }
53 + else if(inputString === '정확도'){ //@가수명_정확도
54 + response = await Axios.post('/api/related/textQuery', textQueryVariables)
64 } 55 }
65 - 56 + else if(inputString === '소식'){ //@가수명_소식
66 - dispatch(saveMessage(conversation)) 57 + response = await Axios.post('/api/news/textQuery', textQueryVariables)
67 } 58 }
68 59
69 - const response = await Axios.post('/api/crawling/textQuery', textQueryVariables) 60 + // const response = await Axios.post('/api/crawling/textQuery', textQueryVariables)
70 let conversations = {} 61 let conversations = {}
71 let pushConversations = [] 62 let pushConversations = []
72 for(var i = 0; i < 3; i++){ 63 for(var i = 0; i < 3; i++){
...@@ -100,7 +91,7 @@ function Chatbot() { ...@@ -100,7 +91,7 @@ function Chatbot() {
100 who: '소통이', 91 who: '소통이',
101 content: { 92 content: {
102 text: { 93 text: {
103 - text: " Error just occured, please check the problem" 94 + text: "잘못된 입력입니다. 다시 입력해주세요!"
104 } 95 }
105 } 96 }
106 } 97 }
......
...@@ -8,11 +8,10 @@ const config = require("./server/config/keys"); ...@@ -8,11 +8,10 @@ const config = require("./server/config/keys");
8 app.use(bodyParser.urlencoded({ extended: true })); 8 app.use(bodyParser.urlencoded({ extended: true }));
9 app.use(bodyParser.json()); 9 app.use(bodyParser.json());
10 10
11 -app.use('/api/crawling', require('./server/routes/crawling'));
12 app.use('/api/dialogflow', require('./server/routes/dialogflow')); 11 app.use('/api/dialogflow', require('./server/routes/dialogflow'));
13 app.use('/api/latest',require('./server/routes/latest')); 12 app.use('/api/latest',require('./server/routes/latest'));
14 -app.use('/api/popular',require('./server/routes/popular')); 13 +app.use('/api/related',require('./server/routes/related'));
15 -app.use('/api/download',require('./server/routes/download')); 14 +app.use('/api/news',require('./server/routes/news'));
16 15
17 // Serve static assets if in production 16 // Serve static assets if in production
18 if (process.env.NODE_ENV === "production") { 17 if (process.env.NODE_ENV === "production") {
......
...@@ -5,11 +5,15 @@ const uuid = require('uuid'); //uuid 제대로 이해하고 다시 작성하기. ...@@ -5,11 +5,15 @@ const uuid = require('uuid'); //uuid 제대로 이해하고 다시 작성하기.
5 const axios = require('axios'); 5 const axios = require('axios');
6 const cheerio = require('cheerio'); 6 const cheerio = require('cheerio');
7 7
8 -//@가수명 으로 입력이 들어왔을 때, 가수명만 받아서 8 +//@가수명_최신 으로 입력이 들어왔을 때, 가수명만 받아서
9 9
10 router.post('/textQuery', async(req,res)=>{ 10 router.post('/textQuery', async(req,res)=>{
11 const result = req.body.text; 11 const result = req.body.text;
12 - var name = result.substring(1) 12 + var i = 0;
13 + for(i; i < result.length; i++){
14 + if(result[i] === '_') break;
15 + }
16 + var name = result.substr(1,i-1);
13 17
14 var url = 'https://tv.naver.com/search/clip?query=' //naverTV의 링크 18 var url = 'https://tv.naver.com/search/clip?query=' //naverTV의 링크
15 var sort = '&sort=date' 19 var sort = '&sort=date'
......
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
...@@ -5,14 +5,20 @@ const uuid = require('uuid'); //uuid 제대로 이해하고 다시 작성하기. ...@@ -5,14 +5,20 @@ const uuid = require('uuid'); //uuid 제대로 이해하고 다시 작성하기.
5 const axios = require('axios'); 5 const axios = require('axios');
6 const cheerio = require('cheerio'); 6 const cheerio = require('cheerio');
7 7
8 -//@가수명 으로 입력이 들어왔을 때, 가수명만 받아서 8 +//@가수명_정확도 으로 입력이 들어왔을 때, 가수명만 받아서
9 9
10 router.post('/textQuery', async(req,res)=>{ 10 router.post('/textQuery', async(req,res)=>{
11 const result = req.body.text; 11 const result = req.body.text;
12 - var name = result.substring(1) 12 +
13 + //가수명 추출
14 + var i = 0;
15 + for(i; i < result.length; i++){
16 + if(result[i] === '_') break;
17 + }
18 + var name = result.substr(1,i-1);
13 19
14 var url = 'https://tv.naver.com/search/clip?query=' //naverTV의 링크 20 var url = 'https://tv.naver.com/search/clip?query=' //naverTV의 링크
15 - var sort = '&sort=date' 21 + var sort = '&sort=rel'
16 url = url + name + sort 22 url = url + name + sort
17 url = encodeURI(url) 23 url = encodeURI(url)
18 console.log("url is ",url) 24 console.log("url is ",url)
......