Commit 36865695 authored by Lee SeoYeon's avatar Lee SeoYeon
Browse files

Merge remote-tracking branch 'origin/BAE' into lsy

parents b3319022 609d4441
...@@ -28,7 +28,7 @@ function App() { ...@@ -28,7 +28,7 @@ function App() {
<Container className="vh-100 d-flex justify-content-md-center align-items-center"> <Container className="vh-100 d-flex justify-content-md-center align-items-center">
<Col md={6} style={{ marginTop: 140 }}> <Col md={6} style={{ marginTop: 140 }}>
<Nav className="justify-content-end" bg="#fff" variant="light" > <Nav className="justify-content-end" bg="#fff" variant="light" >
{user ? <Nav.Link onClick={() => handleLogout()}>로그아웃</Nav.Link> {user ? <Nav.Links={() => handleLogout()}>로그아웃</Nav.Link>
: ( : (
<> <>
<Nav.Link href="/signup">회원가입</Nav.Link> <Nav.Link href="/signup">회원가입</Nav.Link>
......
import axios from 'axios'; import axios from 'axios';
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { Modal, Container, Row, Col, Button, Badge, Card, Accordion, Carousel } from 'react-bootstrap'; import { Modal, Container, Row, Button, } from 'react-bootstrap';
function Place(props) { function Place(props) {
const [reviews, setReviews] = useState([]) const [reviews, setReviews] = useState([{ title: "", link: "", summery: "", content: "" }])
const getReview = () => { //review를 서버에 연결해서 const getReview = () => {
axios.get(`/api/review/${props.search.name}`) axios.get(`/api/review/${props.search.name}`)//review를 서버에 연결해서
.then(res => { .then(res => {s
console.log("place res.data", res.data) console.log("place res.data", res.data)
setReviews(res.data) setReviews(res.data)
}) })
...@@ -24,8 +24,6 @@ function Place(props) { ...@@ -24,8 +24,6 @@ function Place(props) {
size="xl" size="xl"
keyboard="true" keyboard="true"
variant="backdrop.in" variant="backdrop.in"
// show={lgShow}
// onHide={() => setLgShow(false)}
aria-labelledby="example-modal-sizes-title-lg"> aria-labelledby="example-modal-sizes-title-lg">
<Modal.Header closeButton> <Modal.Header closeButton>
<Modal.Title id="contained-modal-title-vcenter" style={{ fontSize: '40px' }}> <Modal.Title id="contained-modal-title-vcenter" style={{ fontSize: '40px' }}>
......
...@@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react'; ...@@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react';
import { Link, Redirect } from 'react-router-dom'; import { Link, Redirect } from 'react-router-dom';
import ohuh from '../ohuh-sm.PNG'; import ohuh from '../ohuh-sm.PNG';
import Place from '../Components/Place'; import Place from '../Components/Place';
import { Container, Form, Row, Col, Card, Image, InputGroup, FormControl, Button, Pagination } from 'react-bootstrap'; import { Container, Form, Row, Col, Card, Image, InputGroup, FormControl, Button} from 'react-bootstrap';
import Paginations from '../Components/Paginations'; import Paginations from '../Components/Paginations';
import axios from 'axios'; import axios from 'axios';
...@@ -121,14 +121,6 @@ function Search(props) { ...@@ -121,14 +121,6 @@ function Search(props) {
const pagePlace = paginate(association, index, association.length) const pagePlace = paginate(association, index, association.length)
// function times (){
// let time = new Date()
// console.log(time)
// return time
// }
// console.log(times())
let time = new Date() let time = new Date()
return ( return (
...@@ -150,11 +142,7 @@ function Search(props) { ...@@ -150,11 +142,7 @@ function Search(props) {
</InputGroup> </InputGroup>
</Form> </Form>
</Row> </Row>
{/* {time.toString()}**** */}
{time.toLocaleString()} {time.toLocaleString()}
{/* {time.toLocaleDateString()}****
{time.toLocaleTimeString()}**** */}
<Row className="d-flex flex-wrap"> <Row className="d-flex flex-wrap">
{pagePlace.map((place, index) => { {pagePlace.map((place, index) => {
return ( return (
...@@ -177,8 +165,6 @@ function Search(props) { ...@@ -177,8 +165,6 @@ function Search(props) {
) )
})} })}
</Row> </Row>
{/* {console.log(showSet)} */}
{/* show가 전부 true로 바뀌어서 전부 다 보이게 되는 것이다. */}
<Row className="mt-2 d-flex justify-content-center"> <Row className="mt-2 d-flex justify-content-center">
<Paginations index={index} endPage={endPage} handlePage={handlePage}></Paginations> <Paginations index={index} endPage={endPage} handlePage={handlePage}></Paginations>
</Row> </Row>
......
...@@ -2,68 +2,74 @@ import Places from '../models/Place.js' ...@@ -2,68 +2,74 @@ import Places from '../models/Place.js'
import cheerio from 'cheerio' import cheerio from 'cheerio'
import fs from 'fs' import fs from 'fs'
import axios from 'axios'; import axios from 'axios';
import { time } from 'console';
const searchPlace = async (req, res) => { const searchPlace = async (req, res) => {
//url 설정
const url = "https://search.naver.com/search.naver?sm=tab_hty.top&where=nexearch&query=" + encodeURI(req.params.search)
const editUrl = /(http(s)?:\/\/)([a-z0-9\w]+\.*)+[a-z0-9]{2,4}/gi
axios.get(url)
.then(async (response) => {
const html = response.data
// console.log(html)
fs.writeFileSync("googleReview", html, { encoding: 'utf-8' })
let $1 = cheerio.load(html);
let places = {} let DuplicateCheckPlace = await Places.findOne({ name: req.params.search })
$1('.ct_box_area').each(function (i) {
if (DuplicateCheckPlace) {
res.send(DuplicateCheckPlace)
// console.log($1('.biz_name').text()) onsole.log("11111111111111111111111Place################ 기존플레이스줄력중")
// console.log($1('.category').text()) }
// console.log($1('.addr').text()) else {
// console.log($1('.t?ime highlight').text()) console.log("2222222222222222222222222222222222222222222222222222222")
const url = "https://search.naver.com/search.naver?sm=tab_hty.top&where=nexearch&query=" + encodeURI(req.params.search)
const editUrl = /(http(s)?:\/\/)([a-z0-9\w]+\.*)+[a-z0-9]{2,4}/gi
places[i] = { name: $1('.biz_name').text(), category: $1('.category').text(), address: $1('.addr').text() } axios.get(url)
.then(async (response) => {
const html = response.data
fs.writeFileSync("googleReview", html, { encoding: 'utf-8' })
let $1 = cheerio.load(html);
let places = {}
$1('.ct_box_area').each(function (i) {
places[i] = { name: $1('.biz_name').text(), category: $1('.category').text(), address: $1('.addr').text() }
})
// 값이 비어있거나 에러가 생겼을 때를 대비해 try catch를 해야함
const newPlaces = await new Places(places[0]
).save()
res.send(places)
}) })
// 값이 비어있거나 에러가 생겼을 때를 대비해 try catch를 해야함 }
const newPlaces = await new Places(places[0]
).save()
res.send(places)
})
} }
const searchImg = async (req, res) => { const searchImg = async (req, res) => {
const imgUrl = "https://www.google.com/search?q=" + encodeURI(req.params.search) + "+site:tistory.com/&sxsrf=ALeKk023Dv08KQDodRmpB5222lQuzw2Vaw:1610612821100&source=lnms&tbm=isch"
axios.get(imgUrl) let DuplicateCheckImg = await Places.findOne({ name: req.params.search })
.then(async (response) => {
const html = response.data
let name = req.params.search
let $1 = cheerio.load(html);
let images = $1('.RAyV4b').find('img').attr('src')
// let images = [] if (DuplicateCheckImg.img !== "https://t1.daumcdn.net/thumb/R600x0/?fname=http%3A%2F%2Ft1.daumcdn.net%2Fqna%2Fimage%2F4b035cdf8372d67108f7e8d339660479dfb41bbd" ) {
res.send(DuplicateCheckImg)
console.log("333333333333333333333333333IMG@@@@@@@@@@@@@@@@@@@ 기존이미지줄력중")
}
else if (DuplicateCheckImg.img === "https://t1.daumcdn.net/thumb/R600x0/?fname=http%3A%2F%2Ft1.daumcdn.net%2Fqna%2Fimage%2F4b035cdf8372d67108f7e8d339660479dfb41bbd" ) {
console.log("4444444444444444444444444444444444444444444444444")
const imgUrl = "https://www.google.com/search?q=" + encodeURI(req.params.search) + "+site:tistory.com/&sxsrf=ALeKk023Dv08KQDodRmpB5222lQuzw2Vaw:1610612821100&source=lnms&tbm=isch"
// $1('.RAyV4b').each(function (i) { axios.get(imgUrl)
// images[i] = { imgUrl: $(this).find('img').atrr('src') } .then(async (response) => {
// }) const html = response.data
// console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%', images) let name = req.params.search
let $1 = cheerio.load(html);
// 여기서 있는건 찾아와서 추가를 시켜야한다. let images = $1('.RAyV4b').find('img').attr('src')
//사진만 업데이트
let Place = await Places.findOne({ name: req.params.search })
Place.times.push(new Date().toLocaleString())
await Places.updateOne({ name: req.params.search }, { img: images, times: Place.times })
const newPlaces = await new Places(
).save()
res.send(images)
})
//사진만 업데이트 } else {
let Place = await Places.findOne({ name: req.params.search }) console.log("IMG에러")
Place.times.push(new Date().toLocaleString()) }
await Places.updateOne({ name: req.params.search }, { img: images, times: Place.times })
const newPlaces = await new Places(
).save()
res.send(images)
})
} }
......
import Review from '../models/Review.js' import Review from '../models/Review.js'
import cheerio from "cheerio"; //크롤링 import cheerio from "cheerio";
import fs from 'fs' import fs from 'fs'
import axios from 'axios'; import axios from 'axios';
// const Iconv = iconv.Iconv
const search = async (req, res, next) => { const search = async (req, res, next) => {
//**************************구글 크롤링 할 때************************/ //**************************구글 크롤링 할 때************************/
try { try {
let reviews = [] let reviews = []
let content = [] let content = []
// Review.find()
const url = "https://www.google.com/search?q=" + encodeURI(req.params.search) + "+site%3Atistory.com&page_no=1" const url = "https://www.google.com/search?q=" + encodeURI(req.params.search) + "+site%3Atistory.com&page_no=1"
const response1 = await axios.get(url) const response1 = await axios.get(url)
...@@ -39,7 +36,7 @@ const search = async (req, res, next) => { ...@@ -39,7 +36,7 @@ const search = async (req, res, next) => {
res.send(reviews) res.send(reviews)
} catch (error) { } catch (error) {
// console.log(error) // console.log(error)
res.send(error) // res.send(error)
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment