Showing
2 changed files
with
47 additions
and
14 deletions
... | @@ -181,10 +181,9 @@ router.post('/', function(req, res) { | ... | @@ -181,10 +181,9 @@ router.post('/', function(req, res) { |
181 | router.get('/food', function(req, res) { | 181 | router.get('/food', function(req, res) { |
182 | 182 | ||
183 | // 맛집 리스트 조회 | 183 | // 맛집 리스트 조회 |
184 | - let sigun_cd = SIGUN_CODE; | ||
185 | let url = 'https://openapi.gg.go.kr/PlaceThatDoATasteyFoodSt'; | 184 | let url = 'https://openapi.gg.go.kr/PlaceThatDoATasteyFoodSt'; |
186 | let fastfood_url = 'https://openapi.gg.go.kr/Genrestrtfastfood' | 185 | let fastfood_url = 'https://openapi.gg.go.kr/Genrestrtfastfood' |
187 | - let qs = `?KEY=${GYEONGI_API_KEY}&SIGUN_CD=${sigun_cd}&Type=json`; | 186 | + let qs = `?KEY=${GYEONGI_API_KEY}&SIGUN_CD=${SIGUN_CODE}&Type=json`; |
188 | 187 | ||
189 | request({ | 188 | request({ |
190 | url: url + qs, | 189 | url: url + qs, |
... | @@ -295,23 +294,34 @@ router.get('/park', function(req, res) { | ... | @@ -295,23 +294,34 @@ router.get('/park', function(req, res) { |
295 | }); | 294 | }); |
296 | 295 | ||
297 | router.get('/shop', function(req, res) { | 296 | router.get('/shop', function(req, res) { |
298 | - let GYEONGI_API_KEY = process.env.GYEONGGI_APIKEY; | 297 | + |
299 | - let sigun_cd = SIGUN_CODE; | ||
300 | let mallnum = 0; | 298 | let mallnum = 0; |
301 | - let url = 'https://openapi.gg.go.kr/MrktStoreM'; | 299 | + let shop_url = 'https://openapi.gg.go.kr/MrktStoreM'; |
302 | - let qs = `?Type=json&KEY=${GYEONGI_API_KEY}&SIGUN_CD=${sigun_cd}`; | 300 | + let qs = `?Type=json&KEY=${GYEONGI_API_KEY}&SIGUN_CD=${SIGUN_CODE}`; |
303 | request({ | 301 | request({ |
304 | - url: url + qs, | 302 | + url: shop_url + qs, |
305 | method: 'GET' | 303 | method: 'GET' |
306 | }, function(err, response, body) { | 304 | }, function(err, response, body) { |
307 | - var shop_result = JSON.parse(body); | 305 | + if (!err && res.statusCode == 200) { |
308 | - if (shop_result.MrktStoreM[0].head[1].RESULT.CODE == 'INFO-000') { | 306 | + let shop_result = JSON.parse(body); |
309 | - mallnum = shop_result.MrktStoreM[0].head[0].list_total_count; | 307 | + let shops = []; |
310 | - console.log(mallnum + "개의 쇼핑몰이 존재합니다."); | 308 | + for (let i = 0; i < shop_result.MrktStoreM[1].row.length; i++) { |
311 | - res.send(String(mallnum) + "개의 쇼핑몰이 존재합니다."); | 309 | + shop = shop_result.MrktStoreM[1].row[i]; |
312 | - } else { | 310 | + // 폐업인 지점 제외 |
313 | - res.send("쇼핑몰이 없습니다."); | 311 | + console.log('shop', shop); |
312 | + shops.push(shop); | ||
314 | } | 313 | } |
314 | + res.render('shop_result', { shops: shops }); | ||
315 | + | ||
316 | + } | ||
317 | + // var shop_result = JSON.parse(body); | ||
318 | + // if (shop_result.MrktStoreM[0].head[1].RESULT.CODE == 'INFO-000') { | ||
319 | + // mallnum = shop_result.MrktStoreM[0].head[0].list_total_count; | ||
320 | + // console.log(mallnum + "개의 쇼핑몰이 존재합니다."); | ||
321 | + // res.send(String(mallnum) + "개의 쇼핑몰이 존재합니다."); | ||
322 | + // } else { | ||
323 | + // res.send("쇼핑몰이 없습니다."); | ||
324 | + // } | ||
315 | }) | 325 | }) |
316 | }); | 326 | }); |
317 | 327 | ... | ... |
views/shop_result.ejs
0 → 100644
1 | +<!DOCTYPE html> | ||
2 | +<html lang="ko"> | ||
3 | + | ||
4 | +<head> | ||
5 | + <meta charset="UTF-8"> | ||
6 | + <title>✍️ 결과 페이지</title> | ||
7 | +</head> | ||
8 | + | ||
9 | +<body> | ||
10 | + <h1>🛍 쇼핑몰 현황(시장, 상가, 마트) </h1> | ||
11 | + <%for (var i =0; i <shops.length; i++){%> | ||
12 | + <li> | ||
13 | + <%=shops[i].MARKET_NM%> | ||
14 | + </li> | ||
15 | + | ||
16 | + <%}%> | ||
17 | + <h3>총 쇼핑몰 개수 : | ||
18 | + <%=shops.length%> | ||
19 | + </h3> | ||
20 | + | ||
21 | +</body> | ||
22 | + | ||
23 | +</html> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment