Commit b4b32464 authored by Kim, Chaerin's avatar Kim, Chaerin
Browse files

.

parent 8d491db5
...@@ -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';
import queryString from 'query-string' import queryString from 'query-string'
...@@ -17,6 +17,7 @@ function Search(props) { ...@@ -17,6 +17,7 @@ function Search(props) {
const [place, setPlace] = useState([{ name: "", category: "", address: "" }]) const [place, setPlace] = useState([{ name: "", category: "", address: "" }])
const [imgUrl, setImgUrl] = useState([]) const [imgUrl, setImgUrl] = useState([])
const [association, setAssociation] = useState([]) const [association, setAssociation] = useState([])
const getImg = () => { const getImg = () => {
axios.get(`/api/search/imges?keyword=${search}`) axios.get(`/api/search/imges?keyword=${search}`)
.then(res => { .then(res => {
...@@ -39,15 +40,15 @@ function Search(props) { ...@@ -39,15 +40,15 @@ function Search(props) {
}) })
} }
const getAssociation =() => { const getAssociation = () => {
axios.get(`/api/search/association?keyword=${search}`) axios.get(`/api/search/association?keyword=${search}`)
.then(res => { .then(res => {
console.log("Associations = ", res.data) console.log("Associations = ", res.data)
setAssociation(res.data) setAssociation(res.data)
}) })
.catch(err => { .catch(err => {
console.log("search.associations 에러 발생", err) console.log("search.associations 에러 발생", err)
}) })
} }
...@@ -61,11 +62,13 @@ function Search(props) { ...@@ -61,11 +62,13 @@ function Search(props) {
} else { } else {
setMobile(false) setMobile(false)
} }
}, []);
if (state) {
props.history.push('/search?keyword=' + search)
setState(false)
console.log("search야", search)
}
}, [search]);
const places = [{ const places = [{
...@@ -91,10 +94,14 @@ function Search(props) { ...@@ -91,10 +94,14 @@ function Search(props) {
}] }]
if (state !== false) { if (state !== false) {
return <Redirect to={{ // console.log(queryString.parse(props.location.search))
pathname: `/search?keyword=${search}`, // = {keyword:search}
state: { id: search }, // return <Redirect to={{
}} />; // pathname: `/search?keyword=${search}`,
// state: { id: search },
// }} />;
// history.pushState(null, null, "?"+queryParams.toString());
// return <Redirect to={`/search?keyword=${search}`} />;
} }
const handlePage = (num) => { const handlePage = (num) => {
...@@ -107,6 +114,7 @@ function Search(props) { ...@@ -107,6 +114,7 @@ function Search(props) {
} }
const handleSubmit = (e) => { const handleSubmit = (e) => {
// e.preventDefault()
setState(true); setState(true);
} }
...@@ -121,14 +129,6 @@ function Search(props) { ...@@ -121,14 +129,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,28 +150,8 @@ function Search(props) { ...@@ -150,28 +150,8 @@ function Search(props) {
</InputGroup> </InputGroup>
</Form> </Form>
</Row> </Row>
{/* {time.toString()}**** */}
{time.toLocaleString()}****
{/* {time.toLocaleDateString()}****
{time.toLocaleTimeString()}**** */}
<Col md={6} >
<Card align="center" border="info" style={{ margin: "3%" }}>
<Card.Title style={{ margin: "3%", fontSize: '200%', fontWeight: 'bold' }} >{place[0].name}</Card.Title>
<Card.Img variant="top" style={{ padding: "5%", width: "100%", height: "340px" }} src={imgUrl} />
<Card.Body >
<Card.Text style={{ overflow: 'auto', fontSize: '25px', width: '100%', height: "80px" }} >
{place[0].address}{place[0].category} </Card.Text>
<Button variant="primary" onClick={() => {
// const showArr = [false, false, false, false]
// showArr[index] = true
// setShowSet(showArr)
}}>{place[0].name} 자세히 살펴보기</Button>
{/* <Place search={place} show={show} onHide={() => setShowSet([false, false, false, false])} /> */}
</Card.Body>
</Card>
</Col>
{time.toLocaleString()}
<Row className="d-flex flex-wrap"> <Row className="d-flex flex-wrap">
{pagePlace.map((place, index) => { {pagePlace.map((place, index) => {
return ( return (
...@@ -187,15 +167,13 @@ function Search(props) { ...@@ -187,15 +167,13 @@ function Search(props) {
showArr[index] = true showArr[index] = true
setShowSet(showArr) setShowSet(showArr)
}}>{place.name} 자세히 살펴보기</Button> }}>{place.name} 자세히 살펴보기</Button>
<Place search={place} index={index} show={showSet[index]} onHide={() => setShowSet([false, false, false, false])} /> <Place place={place} index={index} show={showSet[index]} onHide={() => setShowSet([false, false, false, false])} />
</Card.Body> </Card.Body>
</Card> </Card>
</Col> </Col>
) )
})} })}
</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,85 +2,93 @@ import Places from '../models/Place.js' ...@@ -2,85 +2,93 @@ 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) => {
const url = "https://search.naver.com/search.naver?sm=tab_hty.top&where=nexearch&query=" + encodeURI(req.query.keyword) let DuplicateCheckPlace = await Places.findOne({ name: req.query.keyword })
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 = {} if (DuplicateCheckPlace) {
$1('.ct_box_area').each(function (i) { res.send(DuplicateCheckPlace)
console.log("11111111111111111111111Place################ 기존플레이스줄력중")
}
// console.log($1('.biz_name').text()) else {
// console.log($1('.category').text()) console.log("2222222222222222222222222222222222222222222222222222222")
// console.log($1('.addr').text()) const url = "https://search.naver.com/search.naver?sm=tab_hty.top&where=nexearch&query=" + encodeURI(req.query.keyword)
// console.log($1('.t?ime highlight').text()) const editUrl = /(http(s)?:\/\/)([a-z0-9\w]+\.*)+[a-z0-9]{2,4}/gi
axios.get(url)
.then(async (response) => {
places[i] = { name: $1('.biz_name').text(), category: $1('.category').text(), address: $1('.addr').text() } 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.query.keyword) + "+site:tistory.com/&sxsrf=ALeKk023Dv08KQDodRmpB5222lQuzw2Vaw:1610612821100&source=lnms&tbm=isch"
axios.get(imgUrl) let DuplicateCheckImg = await Places.findOne({ name: req.query.keyword })
.then(async (response) => {
const html = response.data
let name = req.query.keyword
let $1 = cheerio.load(html);
let images = $1('.RAyV4b').find('img').attr('src') if (DuplicateCheckImg) {
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.query.keyword) + "+site:tistory.com/&sxsrf=ALeKk023Dv08KQDodRmpB5222lQuzw2Vaw:1610612821100&source=lnms&tbm=isch"
// let images = [] axios.get(imgUrl)
.then(async (response) => {
const html = response.data
let name = req.query.keyword
let $1 = cheerio.load(html);
// $1('.RAyV4b').each(function (i) { let images = $1('.RAyV4b').find('img').attr('src')
// images[i] = { imgUrl: $(this).find('img').atrr('src') }
// })
// console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%', images)
// 여기서 있는건 찾아와서 추가를 시켜야한다. //사진만 업데이트
let Place = await Places.findOne({ name: req.query.keyword })
Place.times.push(new Date().toLocaleString())
await Places.updateOne({ name: req.query.keyword }, { img: images, times: Place.times })
//사진만 업데이트 res.send(images)
let Place = await Places.findOne({ name: req.query.keyword }) })
Place.times.push(new Date().toLocaleString())
await Places.updateOne({ name: req.query.keyword }, { img: images, times: Place.times }) } else {
console.log("IMG에러")
}
}
const newPlaces = await new Places(
).save()
res.send(images)
})
} }
const searchAssociation = async (req, res) => { const searchAssociation = async (req, res) => {
let Place = await Places.findOne({ name: req.query.keyword }) let Place = await Places.findOne({ name: req.query.keyword })
// if (!Place) {
// res.send([])
// }
if (!Place) { if (!Place) {
res.send([]) res.status(404).send({ error: "Place.address is null" })
}
else {
let addresse = Place.address.split(' ')[0]
let AssociationsId = []
let addressPlaces = new RegExp(`${addresse}`)
console.log("여기보세요", addressPlaces)
let responsePlaces = await Places.find({ address: addressPlaces })
res.send(responsePlaces)
} }
let addresse = Place.address.split(' ')[0]
// let AssociationsId = []
let addressPlaces = new RegExp(`${addresse}`)
let responsePlaces = await Places.find({ address: addressPlaces })
res.send(responsePlaces)
// responsePlaces.map(Association => { // responsePlaces.map(Association => {
// AssociationsId.push(Association._id) // AssociationsId.push(Association._id)
// }) // })
......
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