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

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

parents 555bea50 f5339224
[0111/154710.316:ERROR:directory_reader_win.cc(43)] FindFirstFile: 지정된 경로를 찾을 수 없습니다. (0x3)
[0112/191834.168:ERROR:directory_reader_win.cc(43)] FindFirstFile: 지정된 경로를 찾을 수 없습니다. (0x3)
[0114/234147.078:ERROR:directory_reader_win.cc(43)] FindFirstFile: 지정된 경로를 찾을 수 없습니다. (0x3)
......@@ -19,6 +19,7 @@ function Place(props) {
getReview();
}, [])
return (
<Modal {...props}
size="xl"
......@@ -43,8 +44,9 @@ function Place(props) {
</Row>
)
})}
</Container>
</Container>
<<<<<<< HEAD
{/* <Accordion defaultActiveKey="0">
<Accordion.Toggle as={Button} variant="link" eventKey="0">
<a className="mb-2">다음의 블로그 보기</a>
......@@ -87,6 +89,8 @@ function Place(props) {
<div>한라산은 제주도에 있는 해발 1,947.06m, 면적 약 1,820km²의 화산으로, 제주도의 면적 대부분을 차지하고 있다. 정상에 백록담이라는 화산호가 있는데, 백록담이라는 이름은 흰 사슴이 물을 먹는 곳이라는 뜻에서 왔다고 전해진다.</div>
</Carousel.Item>
</Carousel> */}
=======
>>>>>>> origin/Sangjune
</Modal.Body>
<Modal.Footer>
<Button block onClick={props.onHide}>Close</Button>
......
import React, { useState, useEffect } from 'react';
import { Link, Redirect } from 'react-router-dom';
import ohuh from './ohuh-sm.PNG';
import Place from './Components/Place';
import { Container, Form, Row, Col, Card, Image, InputGroup, FormControl, Button, Modal } from 'react-bootstrap';
import Paginations from './pagination.js';
import * as Icon from 'react-bootstrap-icons';
import axios from "axios";
function Search(props) {
const endPage = 10;
const [state, setState] = useState(false);
const [index, setIndex] = useState(1);
const [showSet, setShowSet] = useState([false, false, false, false]);
const [search, setSearch] = useState(props.location.state.id);
const [mobile, setMobile] = useState();
const [show, setShow] = useState(false);
const handleClose = () => setShow(false);
const handleShow = () => setShow(true);
useEffect(() => {
if (window.innerWidth < 960) {
setMobile(true)
} else {
setMobile(false)
}
}, []);
const places = [{
name: "한라산(hallasan)",
address: "제주 서귀포시 토평동 산15-1",
img: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOUAAADcCAMAAAC4YpZBAAAAkFBMVEX4ugAAAAD8vQD/vwD/wQAAAAP9vQD2uQCwhAO9jgVAMAbmrANTPwYQDAONaQDQmwN2WQG3iwMyJwZAMACofgMKCAZOOwTHlgGFYwfwtAKYcgYpHwHXoQXepgTorgTxtQJjSgCgeAUgGANwVAUZEwJeRgOKaAR8XQRbRAcnHgQ3KgZPOwGrgQJINQZrUQYeFwOi9fVkAAAIi0lEQVR4nO2b2XaCSBCG6WpaRFTcIoKAIuJu8v5vN72BoOiYnEzEM/XdJEBD+Omllq4YBoIgCIIgCIIgCIIgCIIgCIIgCIIgCIIgCIIgCIIgCIIgCIIgCIIgCIIgCIIgCIIgCIIgvwpIXv0W3wUectW0RWNvmJxs13ozpaf2A2zr0hCs8HRmRLP6tJ1bnbSGRnwN8ohuXLQzw3RVvTjt+7T6LGfTvyVpgExg9foUWa4S/P7X7eWOXX3WpO4Z0yaofNiXuUqIP2uvs365N+myrs2x9RJhFZ5T6Q/uNGDl8WjO31ol9AtV42yZLnfjXnGiXZJZ+4wmqTx0ajgMfNkmyidv2o5NSk1w7DQ/dSgWKHBrVZ4bNC/t2KlBKaBb3Whj5W8MC2+kTwb51KSJPO7Ywwpeg1S6D97FP6g2/XIb6ujenOdn9ceYma0KDRD5jErw1rLJvtoGAnXnR95Zllpihw2Yh9fk9vKRyvaHbDKtOjvgaguaqCELYUcexrUPeS1P9CVN1JcYR9U28U4PZK3SkwvvevGfvu/PeGbETpTK1dU6Yg3YB4dttMqhbLaz6p7xYp5Raat5SbbXFwBoKXBRRjXRVxoVszyjMtQ+DUusByvLQg5gZgOYvjds227cjHBE8IwlgXNu4Zfe/U7yZY9/uTRMx/vex3o/XtpGQ3TmKkN6G0LnHUdPpGDe96JFXSeBsp9d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EQBEEQBEEQBEEQBEEQBEEQBEEQBEEQBEEQBEEQBEGQ/yH/ALoViVlZW8doAAAAAElFTkSuQmCC",
// img: "https://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/KOCIS_Halla_Mountain_in_Jeju-do_%286387785543%29.jpg/269px-KOCIS_Halla_Mountain_in_Jeju-do_%286387785543%29.jpg?size=200x200",
// }, {
// name: "성산일출봉(sungsan)",
// address: "제주 서귀포시 성산읍 성산리 1",
// img: "https://www.jeju.go.kr/pub/site/geopark/images/sub/sub03/02%EC%A7%80%EC%A7%88%EB%A7%88%EC%9D%84%EC%9D%B4%EC%95%BC%EA%B8%B0/%EC%A7%80%EC%A7%88%EB%A7%88%EC%9D%84/%EC%A7%80%EC%A7%88%EB%A7%88%EC%9D%84_%EC%84%B1%EC%82%B0%EC%9D%BC%EC%B6%9C%EB%B4%89/1412402261.jpg?400/400",
// }, {
// name: "해녀의 집(haenyeo)",
// address: "제주 서귀포시 성산읍 한도로 141-13지번오조리 3 오조해녀의집",
// img: "https://mblogthumb-phinf.pstatic.net/MjAxNjExMTdfMTc0/MDAxNDc5MzU3ODU0ODQy.KZYXCjzsXT3rCsE4HXBfxyCg2buvluBvN_7NxVp7BSwg.loJc89d8JjGXdNCn-4yMd7aMWPjfrZn21TI9Hyzemkog.JPEG.icocam11/20161010_100205.jpg?type=w800",
// }, {
// name: "오설록 티 뮤지엄(osulloc)",
// address: "제주 서귀포시 안덕면 신화역사로 15 오설록지번서광리 1235-1 오설록",
// img: "https://cdnweb01.wikitree.co.kr/webdata/editor/202007/01/img_20200701143323_2ced7627.webp",
// }, {
// name: "오설록 티 뮤지엄(osulloc)",
// address: "제주 서귀포시 안덕면 신화역사로 15 오설록지번서광리 1235-1 오설록",
// img: "https://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/KOCIS_Halla_Mountain_in_Jeju-do_%286387785543%29.jpg/269px-KOCIS_Halla_Mountain_in_Jeju-do_%286387785543%29.jpg",
}]
if (state !== false) {
return <Redirect to={{
pathname: `/search/${search}`,
state: { id: search },
}} />;
}
const handlePage = (num) => {
setIndex(num);
}
// async function bookmarkSave() {
// await axios.put('/api/users', {userId:userId, bookmarkId:bookmarkId})
// }
const handleChange = (e) => {
setSearch(e.target.value);
}
const handleSubmit = (e) => {
setState(true);
}
function paginate(items, pageNumber, itemNumber) {
const page = [];
const startIndex = (pageNumber - 1) * itemNumber
for (var i = 0; i < itemNumber; i++) {
page.push(items[(startIndex + i)])
}
return page
}
const pagePlace = paginate(places, index, 1)
return (
<Container >
<Link to="/" className="d-flex justify-content-center"><Image src={ohuh} /></Link>
<Row className="mb-2" className="d-flex justify-content-center">
<Form style={{ width: "90vw" }} onSubmit={handleSubmit}>
<InputGroup size="lg">
<Link to="/">
<Col>
{/* <Image src={ohuh} fluid width="130px" /> */}
</Col>
</Link>
<FormControl
placeholder="검색어를 입력하세요."
value={search}
aria-label="Large"
aria-describedby="inputGroup-sizing-sm"
onChange={handleChange}
/>
<InputGroup.Append>
<Button type="submit" variant="outline-secondary" style={{ maxHeight: "8vh", maxWidth: "14vh" }} >검색</Button>
</InputGroup.Append>
</InputGroup>
</Form>
</Row>
<Row className="d-flex flex-wrap">
{pagePlace.map((place, index) => {
return (
<Col key={index} md={6} >
<Card align="center" border="info" style={{ margin: "3%" }}>
<Button variant="outline-info" style={{ marginLeft: "60vh" }} onClick={handleShow}><Icon.BookmarkStar size={30} /> <Modal
show={show}
onHide={handleClose}
backdrop="static"
keyboard={false}
>
<Modal.Header closeButton>
<Modal.Title id="contained-modal-title-vcenter" style={{ fontSize: '30px' }}>북마크 추가됨
</Modal.Title>
</Modal.Header><Form>
<Form.Group controlId="formBasicEmail">
<Form.Label style={{ fontSize: '20px' }}>이름</Form.Label>
<Form.Control type="email" />
<Form.Text className="text-muted">
</Form.Text>
</Form.Group>
{/* <Form.Group controlId="formBasicPassword">
<Form.Label style={{ fontSize: '20px' }}>폴더</Form.Label>
<Form.Control type="password" placeholder="Password" />
</Form.Group> */}
<Modal.Footer>
<Button variant="primary" type="submit">저장</Button>
<Button onClick={props.onHide}>삭제</Button>
</Modal.Footer>
</Form></Modal></Button>
<Card.Title style={{ margin: "3%", fontSize: '200%', fontWeight: 'bold' }}>{place.name}
</Card.Title>
<Card.Img variant="top" style={{ padding: "5%", width: "100%", height: "340px" }} src={place.img} />
<Card.Body >
<Card.Text style={{ overflow: 'auto', fontSize: '25px', width: '100%', height: "80px" }} >
{place.address} </Card.Text>
<Button variant="primary" onClick={() => {
const showArr = [false, false, false, false]
showArr[index] = true
setShowSet(showArr)
}}>{place.name} 자세히 살펴보기</Button>
<Place search={place} index={index} show={showSet[index]} onHide={() => setShowSet([false, false, false, false])} />
</Card.Body>
</Card>
</Col>
)
})}
</Row>
{ console.log(showSet)}
{/* show가 전부 true로 바뀌어서 전부 다 보이게 되는 것이다. */}
<Row className="mt-2 d-flex justify-content-center">
<Paginations index={index} endPage={endPage} handlePage={handlePage}></Paginations>
</Row>
</Container>
);
}
export default Search
......@@ -15,7 +15,7 @@ import {
Route,
Redirect,
} from "react-router-dom";
import axios from 'axios';
ReactDOM.render(
......
......@@ -4,13 +4,13 @@ import React from 'react';
function Paginations(props) {
console.log(props)
// console.log(props)
// const [index, setIndex] = useState(1);
return (
<Pagination>
<Pagination.First onClick={() => props.handlePage(1)} />
{props.index === 1 ? "" : <Pagination.Prev onClick={()=>props.handlePage(props.index - 1)} />}
{props.index === 1 ? <Pagination.Prev onClick={()=>props.handlePage(props.index)} /> : <Pagination.Prev onClick={()=>props.handlePage(props.index - 1)} />}
{props.index === props.endPage-1 ? <Pagination.Item onClick={()=>props.handlePage(props.index - 3)}>{props.index - 3}</Pagination.Item> : ""}
{props.index === props.endPage ? <Pagination.Item onClick={()=>props.handlePage(props.index - 4)}>{props.index - 4}</Pagination.Item> : ""}
{props.index === props.endPage ? <Pagination.Item onClick={()=>props.handlePage(props.index - 3)}>{props.index - 3}</Pagination.Item> : ""}
......@@ -25,7 +25,7 @@ function Paginations(props) {
{props.index === 1 ? <Pagination.Item onClick={()=>props.handlePage(props.index + 3)}>{props.index + 3}</Pagination.Item> : ""}
{props.index === 1 ? <Pagination.Item onClick={()=>props.handlePage(props.index + 4)}>{props.index + 4}</Pagination.Item> : ""}
{props.index === 2 ? <Pagination.Item onClick={()=>props.handlePage(props.index + 3)}>{props.index + 3}</Pagination.Item> : ""}
{props.index === props.endPage ? "" : <Pagination.Next onClick={()=>props.handlePage(props.index + 1)} />}
{props.index === props.endPage ? <Pagination.Next onClick={()=>props.handlePage(props.index)} /> : <Pagination.Next onClick={()=>props.handlePage(props.index + 1)} />}
<Pagination.Last onClick={() =>props.handlePage(props.endPage)} />
</Pagination>
......
// import React from 'react';
// import { Row, Col, Card, Button } from "react-bootstrap";
// import Place from './Components/Place';
// function Quadrant(props) {
// <Row className="d-flex flex-wrap">
// <Col md={6} >
// <Card align="center" border="info" style={{ margin: "3%" }}>
// <Card.Title style={{ margin: "3%", fontSize: '200%', fontWeight: 'bold' }} >{props.pagePlace[0].name}</Card.Title>
// <Card.Img variant="top" style={{ padding: "5%", width: "100%", height: "340px" }} src={props.pagePlace[0].img} />
// <Card.Body >
// <Card.Text style={{ overflow: 'auto', fontSize: '25px', width: '100%', height: "80px" }} >
// {props.pagePlace[0].address} </Card.Text>
// <Button variant="primary" onClick={() => props.handleShow(true)}>{props.pagePlace[0].name} 자세히 살펴보기</Button>
// <Place search={props.pagePlace[0]} onHide={() => props.handleShow(false)} />
// </Card.Body>
// </Card>
// </Col>
// <Col md={6} >
// <Card align="center" border="info" style={{ margin: "3%" }}>
// <Card.Title style={{ margin: "3%", fontSize: '200%', fontWeight: 'bold' }} >{props.pagePlace[1].name}</Card.Title>
// <Card.Img variant="top" style={{ padding: "5%", width: "100%", height: "340px" }} src={props.pagePlace[1].img} />
// <Card.Body >
// <Card.Text style={{ overflow: 'auto', fontSize: '25px', width: '100%', height: "80px" }} >
// {props.pagePlace[0].address} </Card.Text>
// <Button variant="primary" onClick={() => props.handleShow(true)}>{props.pagePlace[0].name} 자세히 살펴보기</Button>
// <Place search={props.pagePlace[0]} onHide={() => props.handleShow(false)} />
// </Card.Body>
// </Card>
// </Col>
// <Col md={6} >
// <Card align="center" border="info" style={{ margin: "3%" }}>
// <Card.Title style={{ margin: "3%", fontSize: '200%', fontWeight: 'bold' }} >{props.pagePlace[0].name}</Card.Title>
// <Card.Img variant="top" style={{ padding: "5%", width: "100%", height: "340px" }} src={props.pagePlace[0].img} />
// <Card.Body >
// <Card.Text style={{ overflow: 'auto', fontSize: '25px', width: '100%', height: "80px" }} >
// {props.pagePlace[0].address} </Card.Text>
// <Button variant="primary" onClick={() => props.handleShow(true)}>{props.pagePlace[0].name} 자세히 살펴보기</Button>
// <Place search={props.pagePlace[0]} onHide={() => props.handleShow(false)} />
// </Card.Body>
// </Card>
// </Col>
// <Col md={6} >
// <Card align="center" border="info" style={{ margin: "3%" }}>
// <Card.Title style={{ margin: "3%", fontSize: '200%', fontWeight: 'bold' }} >{props.pagePlace[0].name}</Card.Title>
// <Card.Img variant="top" style={{ padding: "5%", width: "100%", height: "340px" }} src={props.pagePlace[0].img} />
// <Card.Body >
// <Card.Text style={{ overflow: 'auto', fontSize: '25px', width: '100%', height: "80px" }} >
// {props.pagePlace[0].address} </Card.Text>
// <Button variant="primary" onClick={() => props.handleShow(true)}>{props.pagePlace[0].name} 자세히 살펴보기</Button>
// <Place search={props.pagePlace[0]} onHide={() => props.handleShow(false)} />
// </Card.Body>
// </Card>
// </Col>
// </Row>
// }
// export default Quadrant
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
import Place from '../models/Place.js'
import Places from '../models/Place.js'
import cheerio from 'cheerio'
import fs from 'fs'
import axios from 'axios';
import { time } from 'console';
const signup = async (req, res) => {
const { name, email, password } = req.body
console.log(name, email, password)
try {
if (!isLength(name, { min: 3, max: 10 })) {
return res.status(422).send('Name must be 3-10 characters')
}
const newUser = await new User({
name,
email,
password
}).save()
console.log(newUser)
res.json(newUser)
} catch (error) {
console.log(error)
res.status(500).send('User signup error')
}
const searchPlace = async (req, res) => {
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 = {}
$1('.ct_box_area').each(function (i) {
// console.log($1('.biz_name').text())
// console.log($1('.category').text())
// console.log($1('.addr').text())
// console.log($1('.t?ime highlight').text())
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)
})
}
const search = async (req, res) => {
// 정보들 크롤링 해오고 아래에 넣어주기
const url = "https://section.blog.naver.com/Search/Post.nhn?keyword=" + keyword
request(url, function (err, res, html) { // URL로부터 가져온 페이지 소스가 html이란 변수에 담긴다.
if (!err) {
var $ = cheerio.load(html);
// 블로그 title 정보 가져오기
$(".entry-title > a").each(function () {
var post = { "name": "", "address": "", "img": "" };
var data = $(this);
post["title"] = data.text();
post["link"] = data.attr("href");
});
}
})
// try {
// const newPlace = await new Place({
// name: req.params.search,
// address,
// img,
// })
// }
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)
.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 = []
// $1('.RAyV4b').each(function (i) {
// images[i] = { imgUrl: $(this).find('img').atrr('src') }
// })
// console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%', images)
// 여기서 있는건 찾아와서 추가를 시켜야한다.
//사진만 업데이트
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)
})
}
const searchAssociation = async (req, res) => {
let Place = await Places.findOne({ name: req.params.search })
let address = Place.address.split(' ')[0]
// let AssociationsId = []
let addressPlaces = new RegExp(`${address}`)
let responsePlaces = await Places.find({ address: addressPlaces })
res.send(responsePlaces)
// responsePlaces.map(Association => {
// AssociationsId.push(Association._id)
// })
// console.log("Associations = ", Associations)
// res.send(AssociationsId)
}
export default { signup, search }
\ No newline at end of file
export default { searchImg, searchPlace, searchAssociation }
import Review from '../models/Review.js'
import cheerio from "cheerio";
<<<<<<< HEAD
// import jschardet from 'jschardet'
// import iconv from 'iconv'
// import fs from 'fs'
import axios from 'axios';
=======
import jschardet from 'jschardet'
import fs from 'fs'
import axios from 'axios';
import { nextTick } from 'process';
>>>>>>> origin/Sangjune
// const Iconv = iconv.Iconv
const search = async (req, res, next) => {
//**************************구글 크롤링 할 때************************/
try {
let reviews = []
let content = []
const url = "https://www.google.com/search?q=" + encodeURI(req.params.search) + "+site%3Atistory.com&page_no=1"
const response1 = await axios.get(url)
fs.writeFileSync("googleSearch", response1.data, { encoding: 'utf-8' })
// console.log(response1.data)
const $1 = cheerio.load(response1.data);
$1('.kCrYT').each(async function (i) {
......@@ -28,16 +40,36 @@ const search = async (req, res, next) => {
}
})
const promiseReview = await Promise.all(content)
reviews.forEach(async(review, i) => {
reviews.forEach(async (review, i) => {
review["content"] = promiseReview[i]
})
res.send(reviews)
} catch (error) {
console.log(error)
// console.log(error)
res.send(error)
}
}
//***************네이버 크롤링 할 때 ********************* */
// try {
// let reviews = []
// let content = []
// const url = "https://search.naver.com/search.naver?where=view&sm=tab_jum&query=" + encodeURI('한라산')
// const response1 = await axios.get(url)
// // console.log(response1.data)
// const $1 = cheerio.load(response1.data);
// $1('._list').find('.total_wrap').each(async function (i) {
// reviews[i] = { name: $1(this).find('.total_tit').text(), summery: $1(this).find('.dsc_txt').text(), link: $1(this).find('.total_tit').attr('href') }
// })
// res.send(reviews)
// } catch (error) {
// console.log(error)
// res.send(error)
// }
// }
const getReview = async (link) => {
let content = '없음'
if (link) {
......@@ -50,4 +82,5 @@ const getReview = async (link) => {
return content
}
export default { search, getReview }
\ No newline at end of file
export default { search, getReview }
// export default { search, }
......@@ -25,8 +25,15 @@ const PlaceSchema = new mongoose.Schema({
type: Array,
required: true,
},
category: {
type: String,
},
times: {
type: Array
},
}, {
timestamps: true
})
export default mongoose.models.Place || mongoose.model('Place', PlaceSchema)
\ No newline at end of file
export default mongoose.models.Places || mongoose.model('Place', PlaceSchema)
......@@ -30,4 +30,4 @@ const ReviewSchema = new mongoose.Schema({
timestamps: true
})
export default mongoose.models.Review || mongoose.model('Review', ReviewSchema)
\ No newline at end of file
export default mongoose.models.Review || mongoose.model('Review', ReviewSchema)
......@@ -3,8 +3,13 @@ import place from '../controllers/place.controller.js'
const router = express.Router()
router.route('/api/search/:search')
.post(place.signup)
.get(place.search)
router.route('/api/search/imges/:search')
.get(place.searchImg)
router.route('/api/search/places/:search')
.get(place.searchPlace)
router.route('/api/search/association/:search')
.get(place.searchAssociation)
export default router
\ No newline at end of file
......@@ -18,4 +18,4 @@ async function connectDb() {
connection.isConnected = db.connections[0].readyState
}
export default connectDb
\ No newline at end of file
export default connectDb
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