Yuseunggeun

final

This diff is collapsed. Click to expand it.
# 예산에 따른 컴퓨터 부품 추천 프로그램
### 성능비교 - 벤치마크 사이트 크롤링
### 가격비교 - 네이버 쇼핑 api?
\ No newline at end of file
# 컴퓨터 부품 추천 프로그램
## 주제
찾고자 하는 물품을 검색하면 관련정보를 네이버쇼핑 api를 이용해 출력
예산을 입력하면 예산내로 살 수 있는 부품정보들을 성능순으로 정리하여 추천
## URL
http://www.rec-computerpart.tk
## 개발 환경
- npm, express
- 네이버검색(쇼핑) api
## 설치 방법
1. gitlab clone
```
git clone ssh://git@khuhub.khu.ac.kr:12959/2019102201/Computer-part-Recommand.git
```
2. 모듈 설치
```
npm install
```
3. 네이버검색 api 키 발급, index.js에 id, secret 입력
```
https://developers.naver.com/products/search/
client_id = 'id';
client_secret = 'secret';
```
4. 실행
```
node app.js
```
* * *
## 사용방법
예산입력후 추천 버튼 클릭
검색어 입력후 검색 버튼 클릭
* * *
......
......@@ -12,16 +12,9 @@ app.use(bodyParser.urlencoded({extended:true}));
app.use(bodyParser.json());
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.set('view engine', 'ejs'); //.ejs 사용
app.use('/',index);
//app.use('/main',index);
/*
var fs = require('fs');
var temp = {a:"a",b:"bb"};
var tempjson = JSON.stringify(temp);
fs.writeFileSync("test.json",tempjson);
*/
app.use('/',index); //index.js로 연결
var server = app.listen(3000);
module.exports = app;
\ No newline at end of file
......
This diff is collapsed. Click to expand it.
/*
var express = require('express');
var app = express();
var client_id = 'HH0lbvfI3QtlyR7e9tkw';
var client_secret = 'mvPTEsNs7L';
app.get('/search/shop', function (req, res) {
req.query.query = req.body.keyword;
var api_url = 'https://openapi.naver.com/v1/search/shop?query=' + encodeURI(req.query.query); // json 결과
// var api_url = 'https://openapi.naver.com/v1/search/shop.xml?query=' + encodeURI(req.query.query); // xml 결과
console.log(req.query.query);
console.log(req.body.keyword);
var request = require('request');
var options = {
url: api_url,
headers: {'X-Naver-Client-Id':client_id, 'X-Naver-Client-Secret': client_secret}
};
request.get(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
res.writeHead(200, {'Content-Type': 'text/json;charset=utf-8'});
res.end(body);
} else {
res.status(response.statusCode).end();
console.log('error = ' + response.statusCode);
}
});
});
app.listen(3000, function () {
console.log('http://127.0.0.1:3000/search/blog?query=검색어 app listening on port 3000!');
});
*/
\ No newline at end of file
<!DOCTYPE html>
<html>
<body><!--예산에따른 검색결과-->
<% var bestindex = -1;%>
<% var bestbenchmark = 0;%>
<% for(var i = 1;i <= count;i++ ){%>
<% if(searchlist[i].benchmark > bestbenchmark){%> <!--예산 내에서 가장 성능이 좋은 물품을 찾음-->
<% bestbenchmark = searchlist[i].benchmark;%>
<% bestindex = i;%>
<%}%>
<%}%>
<h2>Search Result <%= money %>$</h2>
<%if(count >= 1){%>
<h4>Best Item</h4>
<h4>
<%= searchlist[bestindex].name+" - ("+searchlist[bestindex].price+"$)-(benchmark:" %> <!--bestitem출력-->
<b><%= searchlist[bestindex].benchmark + ")" %></b>
<%var link = "http://www.videocardbenchmark.net/"+searchlist[bestindex].link.toString(); %>
<a href = <%=link%> target=_blank>link</a>
</h4>
<h4>ItemList</h4>
<%for(var i =1; i<=count;i++){%> <!--나머지 item들 출력-->
<%= i + "." + searchlist[i].name+" - ("+searchlist[i].price+"$)-(benchmark:" %>
<b><%= searchlist[i].benchmark + ")" %></b>
<%link = "http://www.videocardbenchmark.net/"+searchlist[i].link.toString(); %>
<a href = <%=link%> target=_blank>link</a>
<br>
<%}%>
<%}else{%>
<h4>No Item exist</h4>
<%}%>
<form method="GET" action="http://localhost:3000/">
<input type="submit" value="돌아가기">
</form>
</body>
</html>
......@@ -58,17 +58,12 @@
<center>
<h1>그래픽카드 추천 사이트</h1>
<br><br><br><br><br>
<form method="POST" action="http://localhost:3000/search">
<form method="POST" action="http://localhost:3000/recommand">
<input type="text" id="money" name="money" placeholder="예산을 입력하세요(원).">
<input type="submit" id="button" value="추천">
</form>
<!--
<form method="GET" action="http://localhost:3000/rank">
<input type="submit" id='button' value="전체순위">
</form>
-->
<br><br>
<form method="POST" action="http://localhost:3000/shop">
<form method="POST" action="http://localhost:3000/search">
<input type="text" id="word" name="word" placeholder="검색할 키워드를 입력하세요.">
<input type="submit" value="검색">
</form>
......
<!DOCTYPE html>
<html>
<body>
<h1>All Items</h1><!--전체물품을 가성비 순으로 나열-->
<%for(var i =1; i<=count;i++){%>
<%= i + "." + graphic_card_info[i].name+" - ("+graphic_card_info[i].price+"$)-(benchmark:"%>
<b><%= graphic_card_info[i].benchmark + ")" %></b>
<%var link = "http://www.videocardbenchmark.net/"+graphic_card_info[i].link.toString() %>
<a href = <%=link%> target=_blank>link</a>
<br>
<%}%>
<form method="GET" action="http://localhost:3000/">
<input type="submit" value="돌아가기">
</form>
</body>
</html>
......@@ -64,7 +64,7 @@
</head>
<body>
<h1>
추천 결과
추천 결과 - <%= money%>원
</h1>
<center>
<form method="GET" action="http://localhost:3000/">
......
......@@ -64,7 +64,7 @@
</head>
<body>
<h1>
검색 결과
검색 결과 - <%= itemname%>
</h1>
<center>
<form method="GET" action="http://localhost:3000/">
......