Suyeon Jung

Complete park category

...@@ -208,7 +208,7 @@ router.get('/food', function(req, res) { ...@@ -208,7 +208,7 @@ router.get('/food', function(req, res) {
208 }, function(err, response, body) { 208 }, function(err, response, body) {
209 if (!err && res.statusCode == 200) { 209 if (!err && res.statusCode == 200) {
210 let fast_food_result = JSON.parse(body); 210 let fast_food_result = JSON.parse(body);
211 - let fast_store_names = [] 211 + let fast_store_names = [];
212 for (let i = 0; i < fast_food_result.Genrestrtfastfood[1].row.length; i++) { 212 for (let i = 0; i < fast_food_result.Genrestrtfastfood[1].row.length; i++) {
213 fast_store_name = fast_food_result.Genrestrtfastfood[1].row[i]; 213 fast_store_name = fast_food_result.Genrestrtfastfood[1].row[i];
214 // 폐업인 지점 제외 214 // 폐업인 지점 제외
...@@ -240,7 +240,6 @@ router.get('/school', function(req, res) { ...@@ -240,7 +240,6 @@ router.get('/school', function(req, res) {
240 console.log(library_result); 240 console.log(library_result);
241 let library_names = []; 241 let library_names = [];
242 for (let i = 0; i < library_result.Tbggibllbrm[1].row.length; i++) { 242 for (let i = 0; i < library_result.Tbggibllbrm[1].row.length; i++) {
243 - // 상호명, 음식명, 전화번호, 도로명주소(REFINE_ROADNM_ADDR), 지번 주소(REFINE_LOTNO_ADDR)
244 library_name = library_result.Tbggibllbrm[1].row[i]; 243 library_name = library_result.Tbggibllbrm[1].row[i];
245 console.log('library_name', library_name); 244 console.log('library_name', library_name);
246 library_names.push(library_name); 245 library_names.push(library_name);
...@@ -254,7 +253,6 @@ router.get('/school', function(req, res) { ...@@ -254,7 +253,6 @@ router.get('/school', function(req, res) {
254 console.log(institute_result); 253 console.log(institute_result);
255 let institute_names = []; 254 let institute_names = [];
256 for (let i = 0; i < institute_result.TninsttInstutM[1].row.length; i++) { 255 for (let i = 0; i < institute_result.TninsttInstutM[1].row.length; i++) {
257 - // 상호명, 음식명, 전화번호, 도로명주소(REFINE_ROADNM_ADDR), 지번 주소(REFINE_LOTNO_ADDR)
258 institute_name = institute_result.TninsttInstutM[1].row[i]; 256 institute_name = institute_result.TninsttInstutM[1].row[i];
259 console.log('institute_name', institute_name); 257 console.log('institute_name', institute_name);
260 institute_names.push(institute_name); 258 institute_names.push(institute_name);
...@@ -266,23 +264,33 @@ router.get('/school', function(req, res) { ...@@ -266,23 +264,33 @@ router.get('/school', function(req, res) {
266 }) 264 })
267 }); 265 });
268 router.get('/park', function(req, res) { 266 router.get('/park', function(req, res) {
269 - let GYEONGI_API_KEY = process.env.GYEONGGI_APIKEY; 267 + // let cityparknum = 0;
270 - let sigun_cd = SIGUN_CODE; 268 + let citypark_url = 'https://openapi.gg.go.kr/CityPark';
271 - let cityparknum = 0; 269 +
272 - let url = 'https://openapi.gg.go.kr/CityPark'; 270 + let qs = `?Type=json&KEY=${GYEONGI_API_KEY}&SIGUN_CD=${SIGUN_CODE}`;
273 - let qs = `?Type=json&KEY=${GYEONGI_API_KEY}&SIGUN_CD=${sigun_cd}`;
274 request({ 271 request({
275 - url: url + qs, 272 + url: citypark_url + qs,
276 method: 'GET' 273 method: 'GET'
277 }, function(err, response, body) { 274 }, function(err, response, body) {
278 - var park_result = JSON.parse(body); 275 + // console.log('park_result', park_result.CityPark[0].head);
279 - if (park_result.CityPark[0].head[1].RESULT.CODE == 'INFO-000') { 276 + if (!err && res.statusCode == 200) {
280 - cityparknum = park_result.CityPark[0].head[0].list_total_count; 277 + let city_park_result = JSON.parse(body);
281 - console.log(cityparknum + "개의 도시공원이 존재합니다."); 278 + console.log('park', city_park_result)
282 - res.send(String(cityparknum) + "개의 도시공원이 존재합니다."); 279 + let city_park_names = [];
283 - } else { 280 + for (let i = 0; i < city_park_result.CityPark[1].row.length; i++) {
284 - res.send("도시공원이 없습니다."); 281 + city_park_name = city_park_result.CityPark[1].row[i];
282 + city_park_names.push(city_park_name);
283 + }
284 + res.render('park_result', { city_park_names: city_park_names });
285 } 285 }
286 +
287 + // if (park_result.CityPark[0].head[1].RESULT.CODE == 'INFO-000') {
288 + // cityparknum = park_result.CityPark[0].head[0].list_total_count;
289 + // console.log(cityparknum + "개의 도시공원이 존재합니다.");
290 + // res.send(String(cityparknum) + "개의 도시공원이 존재합니다.");
291 + // } else {
292 + // res.send("도시공원이 없습니다.");
293 + // }
286 }) 294 })
287 }); 295 });
288 296
......
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 <city_park_names.length; i++){%>
12 + <li>
13 + <%=city_park_names[i].PARK_NM%>
14 + </li>
15 +
16 + <%}%>
17 + <h3>총 도시공원 개수 :
18 + <%=city_park_names.length%>
19 + </h3>
20 +
21 +</body>
22 +
23 +</html>
...\ No newline at end of file ...\ No newline at end of file