서민정

Remove unnecessary files and update crawling function

function CheckString(inputString){
var from = 0;
var len = 0;
for(var i = 0; i < inputString.length; i++){
if(inputString[i] === '_'){
from = i;
break;
}
}
len = inputString.length - from;
return inputString.substr(from,len);
}
export default CheckString;
\ No newline at end of file
......@@ -5,8 +5,9 @@ import { saveMessage } from '../_actions/message_actions';
import Message from './Sections/Message';
import { List, Icon, Avatar } from 'antd';
import Card from "./Sections/Card";
var username = prompt('이름을 알려주세요!');
if(username === null) username = "유저"
import CheckString from './Check';
const username = "유저";
function Chatbot() {
const dispatch = useDispatch();
const messagesFromRedux = useSelector(state => state.message.messages)
......@@ -42,6 +43,29 @@ function Chatbot() {
}
try {
if(inputString[0] === '@'){
inputString = CheckString(inputString);
if(inputString === '최신'){
}
else if(inputString === '인기'){
}
else if(inputString === '다운'){
}
else {
conversation = {
who: '소통이',
content: {
text: {
text: "잘못된 입력입니다. 다시 입력해주세요!"
}
}
}
dispatch(saveMessage(conversation))
}
const response = await Axios.post('/api/crawling/textQuery', textQueryVariables)
let conversations = {}
let pushConversations = []
......@@ -189,10 +213,10 @@ function Chatbot() {
return (
<div style={{
height: 620, width: 700,
height: 650, width: 700,
border: '3px solid black', borderRadius: '7px'
}}>
<div style={{ height: 564, width: '100%', overflow: 'auto' }}>
<div style={{ height: 594, width: '100%', overflow: 'auto' }}>
{renderMessage(messagesFromRedux)}
......
......@@ -10,6 +10,9 @@ app.use(bodyParser.json());
app.use('/api/crawling', require('./server/routes/crawling'));
app.use('/api/dialogflow', require('./server/routes/dialogflow'));
app.use('/api/latest',require('./server/routes/latest'));
app.use('/api/popular',require('./server/routes/popular'));
app.use('/api/download',require('./server/routes/download'));
// Serve static assets if in production
if (process.env.NODE_ENV === "production") {
......
......@@ -21,7 +21,6 @@
"dialogflow": "^0.8.2",
"dialogflow-fulfillment": "^0.6.1",
"express": "^4.16.4",
"mongoose": "^5.4.20",
"cheerio": "^1.0.0-rc.3",
"axios" : "^0.19.2"
},
......
const mongoose = require('mongoose');
const opinionSchema = mongoose.Schema({
name: String,
opinion: String,
email: String,
registerDate: Date
});
const Opinion = mongoose.model('Opinion', opinionSchema);
module.exports = { Opinion }
const express = require('express');
const router = express.Router();
const uuid = require('uuid'); //uuid 제대로 이해하고 다시 작성하기.
const axios = require('axios');
const cheerio = require('cheerio');
//@가수명 으로 입력이 들어왔을 때, 가수명만 받아서
router.post('/textQuery', async(req,res)=>{
const result = req.body.text;
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");
}
};
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
const express = require('express');
const router = express.Router();
const uuid = require('uuid'); //uuid 제대로 이해하고 다시 작성하기.
const axios = require('axios');
const cheerio = require('cheerio');
//@가수명 으로 입력이 들어왔을 때, 가수명만 받아서
router.post('/textQuery', async(req,res)=>{
const result = req.body.text;
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");
}
};
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
const express = require('express');
const router = express.Router();
const uuid = require('uuid'); //uuid 제대로 이해하고 다시 작성하기.
const axios = require('axios');
const cheerio = require('cheerio');
//@가수명 으로 입력이 들어왔을 때, 가수명만 받아서
router.post('/textQuery', async(req,res)=>{
const result = req.body.text;
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");
}
};
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