Suyeon Jung

Complete school category

...@@ -5,6 +5,7 @@ require('dotenv').config(); ...@@ -5,6 +5,7 @@ require('dotenv').config();
5 5
6 /* GET home page. */ 6 /* GET home page. */
7 let SIGUN_CODE; 7 let SIGUN_CODE;
8 +let GYEONGI_API_KEY = process.env.GYEONGGI_APIKEY;
8 let user_latitude; 9 let user_latitude;
9 let user_logitude; 10 let user_logitude;
10 let sigun = [{ 11 let sigun = [{
...@@ -180,7 +181,6 @@ router.post('/', function(req, res) { ...@@ -180,7 +181,6 @@ router.post('/', function(req, res) {
180 router.get('/food', function(req, res) { 181 router.get('/food', function(req, res) {
181 182
182 // 맛집 리스트 조회 183 // 맛집 리스트 조회
183 - let GYEONGI_API_KEY = process.env.GYEONGGI_APIKEY;
184 let sigun_cd = SIGUN_CODE; 184 let sigun_cd = SIGUN_CODE;
185 let url = 'https://openapi.gg.go.kr/PlaceThatDoATasteyFoodSt'; 185 let url = 'https://openapi.gg.go.kr/PlaceThatDoATasteyFoodSt';
186 let fastfood_url = 'https://openapi.gg.go.kr/Genrestrtfastfood' 186 let fastfood_url = 'https://openapi.gg.go.kr/Genrestrtfastfood'
...@@ -193,7 +193,7 @@ router.get('/food', function(req, res) { ...@@ -193,7 +193,7 @@ router.get('/food', function(req, res) {
193 if (!err && res.statusCode == 200) { 193 if (!err && res.statusCode == 200) {
194 let food_result = JSON.parse(body); 194 let food_result = JSON.parse(body);
195 // console.log('food_result', food_result.PlaceThatDoATasteyFoodSt[1]); 195 // console.log('food_result', food_result.PlaceThatDoATasteyFoodSt[1]);
196 - let store_names = [] 196 + let store_names = [];
197 for (let i = 0; i < food_result.PlaceThatDoATasteyFoodSt[1].row.length; i++) { 197 for (let i = 0; i < food_result.PlaceThatDoATasteyFoodSt[1].row.length; i++) {
198 // 상호명, 음식명, 전화번호, 도로명주소(REFINE_ROADNM_ADDR), 지번 주소(REFINE_LOTNO_ADDR) 198 // 상호명, 음식명, 전화번호, 도로명주소(REFINE_ROADNM_ADDR), 지번 주소(REFINE_LOTNO_ADDR)
199 store_name = food_result.PlaceThatDoATasteyFoodSt[1].row[i]; 199 store_name = food_result.PlaceThatDoATasteyFoodSt[1].row[i];
...@@ -211,12 +211,13 @@ router.get('/food', function(req, res) { ...@@ -211,12 +211,13 @@ router.get('/food', function(req, res) {
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 if (fast_store_name['BSN_STATE_NM'] != '폐업') { 215 if (fast_store_name['BSN_STATE_NM'] != '폐업') {
215 console.log('fast_store_name', fast_store_name); 216 console.log('fast_store_name', fast_store_name);
216 fast_store_names.push(fast_store_name); 217 fast_store_names.push(fast_store_name);
217 } 218 }
218 } 219 }
219 - res.render('result', { store_names: store_names, fast_store_names: fast_store_names }); 220 + res.render('food_result', { store_names: store_names, fast_store_names: fast_store_names });
220 } 221 }
221 222
222 }) 223 })
...@@ -225,7 +226,44 @@ router.get('/food', function(req, res) { ...@@ -225,7 +226,44 @@ router.get('/food', function(req, res) {
225 }); 226 });
226 }); 227 });
227 router.get('/school', function(req, res) { 228 router.get('/school', function(req, res) {
228 - res.send('This is school'); 229 +
230 + let library_url = 'https://openapi.gg.go.kr/Tbggibllbrm';
231 + let institute_url = 'https://openapi.gg.go.kr/TninsttInstutM';
232 + let qs = `?KEY=${GYEONGI_API_KEY}&SIGUN_CD=${SIGUN_CODE}&Type=json`;
233 +
234 + request({
235 + url: library_url + qs,
236 + method: 'GET'
237 + }, function(err, response, body) {
238 + if (!err && res.statusCode == 200) {
239 + let library_result = JSON.parse(body);
240 + console.log(library_result);
241 + let library_names = [];
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];
245 + console.log('library_name', library_name);
246 + library_names.push(library_name);
247 + }
248 + request({
249 + url: institute_url + qs,
250 + method: 'GET'
251 + }, function(err, response, body) {
252 + if (!err && res.statusCode == 200) {
253 + let institute_result = JSON.parse(body);
254 + console.log(institute_result);
255 + let institute_names = [];
256 + 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];
259 + console.log('institute_name', institute_name);
260 + institute_names.push(institute_name);
261 + }
262 + res.render('school_result', { library_names: library_names, institute_names: institute_names });
263 + }
264 + })
265 + }
266 + })
229 }); 267 });
230 router.get('/park', function(req, res) { 268 router.get('/park', function(req, res) {
231 let GYEONGI_API_KEY = process.env.GYEONGGI_APIKEY; 269 let GYEONGI_API_KEY = process.env.GYEONGGI_APIKEY;
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
36 <img src="/img/school.jpg" class="card-img-top" alt="..."> 36 <img src="/img/school.jpg" class="card-img-top" alt="...">
37 <div class="card-body"> 37 <div class="card-body">
38 <h5 class="card-title">학군</h5> 38 <h5 class="card-title">학군</h5>
39 - <p class="card-text">주변 학교, 학원 환경</p> 39 + <p class="card-text">주변 학원 및 도서관 현황</p>
40 <a href="/category/school" class="btn btn-primary">검사!</a> 40 <a href="/category/school" class="btn btn-primary">검사!</a>
41 </div> 41 </div>
42 </div> 42 </div>
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
24 </li> 24 </li>
25 25
26 <%}%> 26 <%}%>
27 - <h3>총 맛집 개수 : 27 + <h3>패스트푸드점 개수 :
28 <%=fast_store_names.length%> 28 <%=fast_store_names.length%>
29 </h3> 29 </h3>
30 30
......
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 <library_names.length; i++){%>
12 + <li>
13 + <%=library_names[i].LIBRRY_NM%>
14 + </li>
15 +
16 + <%}%>
17 + <h3>총 도서관 개수 :
18 + <%=library_names.length%>
19 + </h3>
20 + <h1>📒 학원 현황 </h1>
21 + <%for (var i =0; i <institute_names.length; i++){%>
22 + <li>
23 + <%=institute_names[i].FACLT_NM%>
24 + </li>
25 +
26 + <%}%>
27 + <h3>학원 및 교습소 개수 :
28 + <%=institute_names.length%>
29 + </h3>
30 +
31 +</body>
32 +
33 +</html>
...\ No newline at end of file ...\ No newline at end of file