Showing
2 changed files
with
117 additions
and
4 deletions
| ... | @@ -100,6 +100,7 @@ router.get('/rank',function(req,res){ | ... | @@ -100,6 +100,7 @@ router.get('/rank',function(req,res){ |
| 100 | }); | 100 | }); |
| 101 | }); | 101 | }); |
| 102 | 102 | ||
| 103 | +/* | ||
| 103 | router.post('/search',function(req,res,next){ | 104 | router.post('/search',function(req,res,next){ |
| 104 | console.log('Money : ' + req.body.money); | 105 | console.log('Money : ' + req.body.money); |
| 105 | console.log(req.body); | 106 | console.log(req.body); |
| ... | @@ -124,8 +125,68 @@ router.post('/search',function(req,res,next){ | ... | @@ -124,8 +125,68 @@ router.post('/search',function(req,res,next){ |
| 124 | searchlist : Searchlist, | 125 | searchlist : Searchlist, |
| 125 | count : Searchcount | 126 | count : Searchcount |
| 126 | }); | 127 | }); |
| 128 | +});*/ | ||
| 129 | + | ||
| 130 | + | ||
| 131 | +router.post('/search',function(req,res,next){ | ||
| 132 | + var fdata = fs.readFileSync('GraphicCard-Price.json'); //파일읽어오기 | ||
| 133 | + var datastr = fdata.toString(); | ||
| 134 | + var pricejson = JSON.parse(datastr); | ||
| 135 | + | ||
| 136 | + var fdata2 = fs.readFileSync('GraphicCard-Benchmark.json'); //파일읽어오기 | ||
| 137 | + var datastr2 = fdata2.toString(); | ||
| 138 | + var benchmarkjson = JSON.parse(datastr2); | ||
| 139 | + | ||
| 140 | + console.log('Money : ' + req.body.money); | ||
| 141 | + console.log(req.body); | ||
| 142 | + var Money = req.body.money; //입력한 예산 | ||
| 143 | + | ||
| 144 | + var pricelist = new Object(); | ||
| 145 | + var benchmarklist = new Object(); | ||
| 146 | + var itemlist = new Array(); | ||
| 147 | + var Searchcount = 0; | ||
| 148 | + //console.log(pricejson); | ||
| 149 | + for(var key in pricejson){ | ||
| 150 | + var price = Number(pricejson[key]['lprice']); | ||
| 151 | + if(price <= Money){ | ||
| 152 | + //console.log(price); | ||
| 153 | + var tempitem = new Object(); | ||
| 154 | + tempitem = pricejson[key]; | ||
| 155 | + tempitem["benchmark"] = benchmarkjson[key]["benchmark"]; | ||
| 156 | + tempitem['name'] = benchmarkjson[key]['name']; | ||
| 157 | + //console.log(tempitem); | ||
| 158 | + itemlist.push(tempitem); | ||
| 159 | + //pricelist[key] = pricejson[key]; | ||
| 160 | + Searchcount++; | ||
| 161 | + } | ||
| 162 | + } | ||
| 163 | + setTimeout(function(){ | ||
| 164 | + console.log(itemlist); | ||
| 165 | + res.render('result',{ | ||
| 166 | + money: Money, | ||
| 167 | + itemlist: itemlist, | ||
| 168 | + itemcount: Searchcount | ||
| 169 | + }); | ||
| 170 | + }, 1000); | ||
| 171 | + | ||
| 172 | + | ||
| 127 | }); | 173 | }); |
| 128 | 174 | ||
| 175 | + | ||
| 176 | + | ||
| 177 | + | ||
| 178 | + | ||
| 179 | + | ||
| 180 | + | ||
| 181 | + | ||
| 182 | + | ||
| 183 | + | ||
| 184 | + | ||
| 185 | + | ||
| 186 | + | ||
| 187 | + | ||
| 188 | + | ||
| 189 | +/* | ||
| 129 | function searching(name){ | 190 | function searching(name){ |
| 130 | 191 | ||
| 131 | var api_url = 'https://openapi.naver.com/v1/search/shop?query=' + encodeURI(name); // json 결과 | 192 | var api_url = 'https://openapi.naver.com/v1/search/shop?query=' + encodeURI(name); // json 결과 |
| ... | @@ -173,11 +234,8 @@ async function createDB(){ | ... | @@ -173,11 +234,8 @@ async function createDB(){ |
| 173 | }); | 234 | }); |
| 174 | }; | 235 | }; |
| 175 | 236 | ||
| 176 | - | ||
| 177 | createDB(); | 237 | createDB(); |
| 178 | 238 | ||
| 179 | - | ||
| 180 | - | ||
| 181 | router.post('/shop', function(req, res) { | 239 | router.post('/shop', function(req, res) { |
| 182 | var keyword = req.body.word; | 240 | var keyword = req.body.word; |
| 183 | req.query.query = keyword; | 241 | req.query.query = keyword; |
| ... | @@ -201,5 +259,5 @@ router.post('/shop', function(req, res) { | ... | @@ -201,5 +259,5 @@ router.post('/shop', function(req, res) { |
| 201 | } | 259 | } |
| 202 | }); | 260 | }); |
| 203 | }); | 261 | }); |
| 204 | - | 262 | +*/ |
| 205 | module.exports = router; | 263 | module.exports = router; |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
views/result.ejs
0 → 100644
| 1 | +<!DOCTYPE html> | ||
| 2 | +<html> | ||
| 3 | +<head> | ||
| 4 | + <meta charset="utf-8"> | ||
| 5 | + <link rel="stylesheet" href="style.css"> | ||
| 6 | + <link href="https://fonts.googleapis.com/css?family=Cute+Font&display=swap" rel="stylesheet"> | ||
| 7 | + <style> | ||
| 8 | + body{ | ||
| 9 | + background-color: rgb(192, 233, 192); | ||
| 10 | + color:black; | ||
| 11 | + margin: 0; | ||
| 12 | + padding: 0; | ||
| 13 | + } | ||
| 14 | + h1{ | ||
| 15 | + text-align: center; | ||
| 16 | + color: red; | ||
| 17 | + } | ||
| 18 | + img{ | ||
| 19 | + height:200px; | ||
| 20 | + } | ||
| 21 | + #item1{ | ||
| 22 | + color:white; | ||
| 23 | + } | ||
| 24 | + #item2{ | ||
| 25 | + | ||
| 26 | + } | ||
| 27 | + #item3{ | ||
| 28 | + | ||
| 29 | + } | ||
| 30 | + </style> | ||
| 31 | +</head> | ||
| 32 | +<body> | ||
| 33 | + <h1> | ||
| 34 | + 추천 결과 | ||
| 35 | + </h1> | ||
| 36 | + <script> | ||
| 37 | + | ||
| 38 | + </script> | ||
| 39 | + <h2> | ||
| 40 | + <div id = "item1"> | ||
| 41 | + <%= itemlist[0]['name'] %> | ||
| 42 | + <br> | ||
| 43 | + <img src = <%= itemlist[0]['image'] %>> | ||
| 44 | + <br> | ||
| 45 | + 성능 : <%= itemlist[0]['benchmark'] %> | ||
| 46 | + <br> | ||
| 47 | + 가격 : <%= itemlist[0]['lprice'] %>원 | ||
| 48 | + <br> | ||
| 49 | + <a href = <%=itemlist[0]['link']%> target=_blank>구매링크</a> | ||
| 50 | + </div> | ||
| 51 | + </h2> | ||
| 52 | + | ||
| 53 | +</body> | ||
| 54 | + | ||
| 55 | +</html> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment