Showing
3 changed files
with
57 additions
and
52 deletions
... | @@ -142,6 +142,13 @@ let sigun = [{ | ... | @@ -142,6 +142,13 @@ let sigun = [{ |
142 | }, | 142 | }, |
143 | ] | 143 | ] |
144 | 144 | ||
145 | +let userArea = function(target, targetKey, user) { | ||
146 | + if (target[targetKey].includes(user)) { | ||
147 | + return true; | ||
148 | + } else { | ||
149 | + return false; | ||
150 | + } | ||
151 | +} | ||
145 | 152 | ||
146 | // 사용자가 index 페이지에서 주소를 입력하고 넘어오면 | 153 | // 사용자가 index 페이지에서 주소를 입력하고 넘어오면 |
147 | router.post('/', function(req, res) { | 154 | router.post('/', function(req, res) { |
... | @@ -205,7 +212,7 @@ router.get('/food', function(req, res) { | ... | @@ -205,7 +212,7 @@ router.get('/food', function(req, res) { |
205 | for (let i = 0; i < food_result.PlaceThatDoATasteyFoodSt[1].row.length; i++) { | 212 | for (let i = 0; i < food_result.PlaceThatDoATasteyFoodSt[1].row.length; i++) { |
206 | // 상호명, 음식명, 전화번호, 도로명주소(REFINE_ROADNM_ADDR), 지번 주소(REFINE_LOTNO_ADDR) | 213 | // 상호명, 음식명, 전화번호, 도로명주소(REFINE_ROADNM_ADDR), 지번 주소(REFINE_LOTNO_ADDR) |
207 | store = food_result.PlaceThatDoATasteyFoodSt[1].row[i]; | 214 | store = food_result.PlaceThatDoATasteyFoodSt[1].row[i]; |
208 | - if (store['REFINE_LOTNO_ADDR'].includes(user_dong)) { | 215 | + if (userArea(store, 'REFINE_LOTNO_ADDR', user_dong)) { |
209 | console.log('store', store); | 216 | console.log('store', store); |
210 | stores.push(store); | 217 | stores.push(store); |
211 | } | 218 | } |
... | @@ -222,7 +229,7 @@ router.get('/food', function(req, res) { | ... | @@ -222,7 +229,7 @@ router.get('/food', function(req, res) { |
222 | for (let i = 0; i < fast_food_result.Genrestrtfastfood[1].row.length; i++) { | 229 | for (let i = 0; i < fast_food_result.Genrestrtfastfood[1].row.length; i++) { |
223 | fast_food_store = fast_food_result.Genrestrtfastfood[1].row[i]; | 230 | fast_food_store = fast_food_result.Genrestrtfastfood[1].row[i]; |
224 | // 폐업인 지점 제외 | 231 | // 폐업인 지점 제외 |
225 | - if (fast_food_store['BSN_STATE_NM'] != '폐업' && fast_food_store['REFINE_LOTNO_ADDR'].includes(user_dong)) { | 232 | + if (fast_food_store['BSN_STATE_NM'] != '폐업' && userArea(fast_food_store, 'REFINE_LOTNO_ADDR', user_dong)) { |
226 | console.log('fast_store_name', fast_food_store); | 233 | console.log('fast_store_name', fast_food_store); |
227 | fast_food_stores.push(fast_food_store); | 234 | fast_food_stores.push(fast_food_store); |
228 | } | 235 | } |
... | @@ -248,11 +255,14 @@ router.get('/school', function(req, res) { | ... | @@ -248,11 +255,14 @@ router.get('/school', function(req, res) { |
248 | if (!err && res.statusCode == 200) { | 255 | if (!err && res.statusCode == 200) { |
249 | let library_result = JSON.parse(body); | 256 | let library_result = JSON.parse(body); |
250 | console.log(library_result); | 257 | console.log(library_result); |
251 | - let library_names = []; | 258 | + let librarys = []; |
252 | for (let i = 0; i < library_result.Tbggibllbrm[1].row.length; i++) { | 259 | for (let i = 0; i < library_result.Tbggibllbrm[1].row.length; i++) { |
253 | - library_name = library_result.Tbggibllbrm[1].row[i]; | 260 | + library = library_result.Tbggibllbrm[1].row[i]; |
254 | - console.log('library_name', library_name); | 261 | + if (userArea(library, 'REFINE_LOTNO_ADDR', user_dong)) { |
255 | - library_names.push(library_name); | 262 | + console.log('library', library); |
263 | + librarys.push(library); | ||
264 | + } | ||
265 | + | ||
256 | } | 266 | } |
257 | request({ | 267 | request({ |
258 | url: institute_url + qs, | 268 | url: institute_url + qs, |
... | @@ -261,13 +271,15 @@ router.get('/school', function(req, res) { | ... | @@ -261,13 +271,15 @@ router.get('/school', function(req, res) { |
261 | if (!err && res.statusCode == 200) { | 271 | if (!err && res.statusCode == 200) { |
262 | let institute_result = JSON.parse(body); | 272 | let institute_result = JSON.parse(body); |
263 | console.log(institute_result); | 273 | console.log(institute_result); |
264 | - let institute_names = []; | 274 | + let institutes = []; |
265 | for (let i = 0; i < institute_result.TninsttInstutM[1].row.length; i++) { | 275 | for (let i = 0; i < institute_result.TninsttInstutM[1].row.length; i++) { |
266 | - institute_name = institute_result.TninsttInstutM[1].row[i]; | 276 | + institute = institute_result.TninsttInstutM[1].row[i]; |
267 | - console.log('institute_name', institute_name); | 277 | + if (userArea(institute, 'REFINE_LOTNO_ADDR', user_dong)) { |
268 | - institute_names.push(institute_name); | 278 | + console.log('institute', institute); |
279 | + institutes.push(institute); | ||
280 | + } | ||
269 | } | 281 | } |
270 | - res.render('school_result', { library_names: library_names, institute_names: institute_names }); | 282 | + res.render('school_result', { librarys: librarys, institutes: institutes }); |
271 | } | 283 | } |
272 | }) | 284 | }) |
273 | } | 285 | } |
... | @@ -286,12 +298,14 @@ router.get('/park', function(req, res) { | ... | @@ -286,12 +298,14 @@ router.get('/park', function(req, res) { |
286 | if (!err && res.statusCode == 200) { | 298 | if (!err && res.statusCode == 200) { |
287 | let city_park_result = JSON.parse(body); | 299 | let city_park_result = JSON.parse(body); |
288 | console.log('park', city_park_result) | 300 | console.log('park', city_park_result) |
289 | - let city_park_names = []; | 301 | + let city_parks = []; |
290 | for (let i = 0; i < city_park_result.CityPark[1].row.length; i++) { | 302 | for (let i = 0; i < city_park_result.CityPark[1].row.length; i++) { |
291 | - city_park_name = city_park_result.CityPark[1].row[i]; | 303 | + city_park = city_park_result.CityPark[1].row[i]; |
292 | - city_park_names.push(city_park_name); | 304 | + if (userArea(city_park, 'REFINE_LOTNO_ADDR', user_dong)) { |
305 | + city_parks.push(city_park); | ||
306 | + } | ||
293 | } | 307 | } |
294 | - res.render('park_result', { city_park_names: city_park_names }); | 308 | + res.render('park_result', { city_parks: city_parks }); |
295 | } | 309 | } |
296 | 310 | ||
297 | // if (park_result.CityPark[0].head[1].RESULT.CODE == 'INFO-000') { | 311 | // if (park_result.CityPark[0].head[1].RESULT.CODE == 'INFO-000') { |
... | @@ -322,8 +336,10 @@ router.get('/safe', function(req, res) { | ... | @@ -322,8 +336,10 @@ router.get('/safe', function(req, res) { |
322 | console.log(cctv_result); | 336 | console.log(cctv_result); |
323 | for (let i = 0; i < cctv_result.CCTV[1].row.length; i++) { | 337 | for (let i = 0; i < cctv_result.CCTV[1].row.length; i++) { |
324 | cctv = cctv_result.CCTV[1].row[i]; | 338 | cctv = cctv_result.CCTV[1].row[i]; |
325 | - console.log('cctv', cctv); | 339 | + if (userArea(cctv, 'REFINE_LOTNO_ADDR', user_dong)) { |
326 | - cctvs.push(cctv); | 340 | + console.log('cctv', cctv); |
341 | + cctvs.push(cctv); | ||
342 | + } | ||
327 | } | 343 | } |
328 | request({ | 344 | request({ |
329 | url: light_url + qs, | 345 | url: light_url + qs, |
... | @@ -335,8 +351,10 @@ router.get('/safe', function(req, res) { | ... | @@ -335,8 +351,10 @@ router.get('/safe', function(req, res) { |
335 | console.log(light_result); | 351 | console.log(light_result); |
336 | for (let i = 0; i < light_result.SECRTLGT[1].row.length; i++) { | 352 | for (let i = 0; i < light_result.SECRTLGT[1].row.length; i++) { |
337 | light = light_result.SECRTLGT[1].row[i]; | 353 | light = light_result.SECRTLGT[1].row[i]; |
338 | - console.log('light', light); | 354 | + if (userArea(light, 'REFINE_LOTNO_ADDR', user_dong)) { |
339 | - lights.push(light); | 355 | + console.log('light', light); |
356 | + lights.push(light); | ||
357 | + } | ||
340 | } | 358 | } |
341 | res.render('safe_result', { cctvs: cctvs, lights: lights }); | 359 | res.render('safe_result', { cctvs: cctvs, lights: lights }); |
342 | } | 360 | } |
... | @@ -361,7 +379,7 @@ router.get('/culture', function(req, res) { | ... | @@ -361,7 +379,7 @@ router.get('/culture', function(req, res) { |
361 | for (let i = 0; i < sing_result.Songclub[1].row.length; i++) { | 379 | for (let i = 0; i < sing_result.Songclub[1].row.length; i++) { |
362 | sing = sing_result.Songclub[1].row[i]; | 380 | sing = sing_result.Songclub[1].row[i]; |
363 | // 폐업인 지점 제외 | 381 | // 폐업인 지점 제외 |
364 | - if (!sing['BSN_STATE_NM'].includes('폐업')) { | 382 | + if (!sing['BSN_STATE_NM'].includes('폐업') && userArea(sing, 'REFINE_LOTNO_ADDR', user_dong)) { |
365 | console.log('sing', sing); | 383 | console.log('sing', sing); |
366 | sings.push(sing); | 384 | sings.push(sing); |
367 | } | 385 | } |
... | @@ -386,24 +404,18 @@ router.get('/shop', function(req, res) { | ... | @@ -386,24 +404,18 @@ router.get('/shop', function(req, res) { |
386 | for (let i = 0; i < shop_result.MrktStoreM[1].row.length; i++) { | 404 | for (let i = 0; i < shop_result.MrktStoreM[1].row.length; i++) { |
387 | shop = shop_result.MrktStoreM[1].row[i]; | 405 | shop = shop_result.MrktStoreM[1].row[i]; |
388 | // 폐업인 지점 제외 | 406 | // 폐업인 지점 제외 |
389 | - console.log('shop', shop); | 407 | + if (userArea(shop, 'REFINE_LOTNO_ADDR', user_dong)) { |
390 | - shops.push(shop); | 408 | + console.log('shop', shop); |
409 | + shops.push(shop); | ||
410 | + } | ||
391 | } | 411 | } |
392 | res.render('shop_result', { shops: shops }); | 412 | res.render('shop_result', { shops: shops }); |
393 | } | 413 | } |
394 | - // var shop_result = JSON.parse(body); | 414 | + |
395 | - // if (shop_result.MrktStoreM[0].head[1].RESULT.CODE == 'INFO-000') { | ||
396 | - // mallnum = shop_result.MrktStoreM[0].head[0].list_total_count; | ||
397 | - // console.log(mallnum + "개의 쇼핑몰이 존재합니다."); | ||
398 | - // res.send(String(mallnum) + "개의 쇼핑몰이 존재합니다."); | ||
399 | - // } else { | ||
400 | - // res.send("쇼핑몰이 없습니다."); | ||
401 | - // } | ||
402 | }) | 415 | }) |
403 | }); | 416 | }); |
404 | 417 | ||
405 | router.get('/gym', function(req, res) { | 418 | router.get('/gym', function(req, res) { |
406 | - let gymnum = 0; | ||
407 | let gym_url = 'https://openapi.gg.go.kr/PhysicaFitnessTrainingPlace'; | 419 | let gym_url = 'https://openapi.gg.go.kr/PhysicaFitnessTrainingPlace'; |
408 | let qs = `?Type=json&KEY=${GYEONGI_API_KEY}&SIGUN_CD=${SIGUN_CODE}`; | 420 | let qs = `?Type=json&KEY=${GYEONGI_API_KEY}&SIGUN_CD=${SIGUN_CODE}`; |
409 | request({ | 421 | request({ |
... | @@ -416,21 +428,14 @@ router.get('/gym', function(req, res) { | ... | @@ -416,21 +428,14 @@ router.get('/gym', function(req, res) { |
416 | console.log(gym_result.PhysicaFitnessTrainingPlace[1]); | 428 | console.log(gym_result.PhysicaFitnessTrainingPlace[1]); |
417 | for (let i = 0; i < gym_result.PhysicaFitnessTrainingPlace[1].row.length; i++) { | 429 | for (let i = 0; i < gym_result.PhysicaFitnessTrainingPlace[1].row.length; i++) { |
418 | gym = gym_result.PhysicaFitnessTrainingPlace[1].row[i]; | 430 | gym = gym_result.PhysicaFitnessTrainingPlace[1].row[i]; |
419 | - console.log('gym', gym); | 431 | + console.log(gym); |
420 | - gyms.push(gym); | 432 | + if (userArea(gym, 'REFINE_LOTNO_ADDR', user_dong)) { |
433 | + console.log('gym', gym); | ||
434 | + gyms.push(gym); | ||
435 | + } | ||
421 | } | 436 | } |
422 | res.render('gym_result', { gyms: gyms }); | 437 | res.render('gym_result', { gyms: gyms }); |
423 | } | 438 | } |
424 | - // if (gym_result.PhysicaFitnessTrainingPlace[0].head[1].RESULT.CODE == 'INFO-000') { | ||
425 | - | ||
426 | - // gymnum = gym_result.PhysicaFitnessTrainingPlace[0].head[0].list_total_count; | ||
427 | - // console.log(gymnum + "개의 체육관이 존재합니다."); | ||
428 | - // res.send(String(gymnum) + "개의 체육관이 존재합니다."); | ||
429 | - // } else { | ||
430 | - | ||
431 | - // console.log("주변에 체육관이 없습니다."); | ||
432 | - // res.send("주변에 체육관이 없습니다."); | ||
433 | - // } | ||
434 | }) | 439 | }) |
435 | }); | 440 | }); |
436 | 441 | ... | ... |
... | @@ -8,14 +8,14 @@ | ... | @@ -8,14 +8,14 @@ |
8 | 8 | ||
9 | <body> | 9 | <body> |
10 | <h1>🌳 도시공원 현황 </h1> | 10 | <h1>🌳 도시공원 현황 </h1> |
11 | - <%for (var i =0; i <city_park_names.length; i++){%> | 11 | + <%for (var i =0; i <city_parks.length; i++){%> |
12 | <li> | 12 | <li> |
13 | - <%=city_park_names[i].PARK_NM%> | 13 | + <%=city_parks[i].PARK_NM%> |
14 | </li> | 14 | </li> |
15 | 15 | ||
16 | <%}%> | 16 | <%}%> |
17 | <h3>총 도시공원 개수 : | 17 | <h3>총 도시공원 개수 : |
18 | - <%=city_park_names.length%> | 18 | + <%=city_parks.length%> |
19 | </h3> | 19 | </h3> |
20 | 20 | ||
21 | </body> | 21 | </body> | ... | ... |
... | @@ -8,24 +8,24 @@ | ... | @@ -8,24 +8,24 @@ |
8 | 8 | ||
9 | <body> | 9 | <body> |
10 | <h1>📚 도서관 현황 </h1> | 10 | <h1>📚 도서관 현황 </h1> |
11 | - <%for (var i =0; i <library_names.length; i++){%> | 11 | + <%for (var i =0; i <librarys.length; i++){%> |
12 | <li> | 12 | <li> |
13 | - <%=library_names[i].LIBRRY_NM%> | 13 | + <%=librarys[i].LIBRRY_NM%> |
14 | </li> | 14 | </li> |
15 | 15 | ||
16 | <%}%> | 16 | <%}%> |
17 | <h3>총 도서관 개수 : | 17 | <h3>총 도서관 개수 : |
18 | - <%=library_names.length%> | 18 | + <%=librarys.length%> |
19 | </h3> | 19 | </h3> |
20 | <h1>📒 학원 현황 </h1> | 20 | <h1>📒 학원 현황 </h1> |
21 | - <%for (var i =0; i <institute_names.length; i++){%> | 21 | + <%for (var i =0; i <institutes.length; i++){%> |
22 | <li> | 22 | <li> |
23 | - <%=institute_names[i].FACLT_NM%> | 23 | + <%=institutes[i].FACLT_NM%> |
24 | </li> | 24 | </li> |
25 | 25 | ||
26 | <%}%> | 26 | <%}%> |
27 | <h3>학원 및 교습소 개수 : | 27 | <h3>학원 및 교습소 개수 : |
28 | - <%=institute_names.length%> | 28 | + <%=institutes.length%> |
29 | </h3> | 29 | </h3> |
30 | 30 | ||
31 | </body> | 31 | </body> | ... | ... |
-
Please register or login to post a comment