Yuseunggeun

final

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