Showing
5 changed files
with
272 additions
and
8 deletions
... | @@ -12,6 +12,7 @@ let user_gu; | ... | @@ -12,6 +12,7 @@ let user_gu; |
12 | let user_latitude; | 12 | let user_latitude; |
13 | let user_longitude; | 13 | let user_longitude; |
14 | 14 | ||
15 | +//동물병원 | ||
15 | router.post('/hospital', function(req, res){ | 16 | router.post('/hospital', function(req, res){ |
16 | //gu 받아오기 | 17 | //gu 받아오기 |
17 | var body = req.body; | 18 | var body = req.body; |
... | @@ -23,36 +24,296 @@ router.post('/hospital', function(req, res){ | ... | @@ -23,36 +24,296 @@ router.post('/hospital', function(req, res){ |
23 | var gu_select_encode = urlencode(gu_select); | 24 | var gu_select_encode = urlencode(gu_select); |
24 | 25 | ||
25 | //api | 26 | //api |
26 | - let pet_url = `http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03?serviceKey=${ANIMAL_INFO_API_KEY}&numOfRows=100&pageNo=1&keyword=${menu_encode}&where=${gu_select_encode}`; | 27 | + let pet_url = `http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03?serviceKey=${ANIMAL_INFO_API_KEY}&numOfRows=200&pageNo=1&keyword=${menu_encode}&where=${gu_select_encode}`; |
27 | request(pet_url, function(err, response, body){ | 28 | request(pet_url, function(err, response, body){ |
28 | if(err) { | 29 | if(err) { |
29 | console.log(`err => ${err}`) | 30 | console.log(`err => ${err}`) |
30 | } | 31 | } |
31 | else { | 32 | else { |
32 | if(res.statusCode == 200) { | 33 | if(res.statusCode == 200) { |
33 | - var hospital_list = []; //얘를 전역으로 선언해서 중복이 발생했던 거였어요 ㅠ | 34 | + var hospital_list = []; |
34 | var titles = ''; | 35 | var titles = ''; |
35 | 36 | ||
36 | var result = convert.xml2json(body, {compact: true, spaces: 4}); | 37 | var result = convert.xml2json(body, {compact: true, spaces: 4}); |
37 | - var petJson = JSON.parse(result) | 38 | + var petJson = JSON.parse(result); |
38 | var itemList = petJson.response.body.items; | 39 | var itemList = petJson.response.body.items; |
39 | - var numRows = itemList.item.length; //개수 | 40 | + var numRows = petJson.response.body.totalCount._text; //개수 |
41 | + | ||
42 | + //------------------------------------------------- | ||
43 | + if (numRows == 1){ | ||
44 | + // state 정상인 것만 추리기 | ||
45 | + if (itemList.item.state._text == '정상'){ | ||
46 | + appliance_list.push(itemList.item); | ||
47 | + } | ||
48 | + } | ||
49 | + else if (numRows == 0){} | ||
50 | + else { | ||
40 | for (i=0; i<numRows; i++){ | 51 | for (i=0; i<numRows; i++){ |
41 | // state 정상인 것만 추리기 | 52 | // state 정상인 것만 추리기 |
42 | if (itemList.item[i].state._text == '정상'){ | 53 | if (itemList.item[i].state._text == '정상'){ |
43 | - hospital_list.push(itemList.item[i]); | 54 | + appliance_list.push(itemList.item[i]); |
55 | + } | ||
44 | } | 56 | } |
45 | } | 57 | } |
58 | + //----------------------------------------------- | ||
46 | 59 | ||
47 | //테스트용 console.log | 60 | //테스트용 console.log |
48 | for(i=0; i<hospital_list.length; i++){ | 61 | for(i=0; i<hospital_list.length; i++){ |
49 | titles = titles+hospital_list[i].title._text+'\n'; | 62 | titles = titles+hospital_list[i].title._text+'\n'; |
50 | } | 63 | } |
51 | - console.log(titles); | 64 | + if (titles == '') {console.log('nothing');} |
65 | + else {console.log(titles); } | ||
52 | } | 66 | } |
53 | } | 67 | } |
54 | res.render('result', { category: 'hospital', titles: titles, hospital_list: hospital_list }); | 68 | res.render('result', { category: 'hospital', titles: titles, hospital_list: hospital_list }); |
55 | }) | 69 | }) |
56 | }); | 70 | }); |
57 | 71 | ||
58 | - module.exports = router; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
72 | + //동물약국 | ||
73 | +router.post('/medicine', function(req, res){ | ||
74 | + //gu 받아오기 | ||
75 | + var body = req.body; | ||
76 | + var gu_select = body.user_gu; | ||
77 | + var menu = '동물약국'; | ||
78 | + | ||
79 | + // encoding for url | ||
80 | + var menu_encode = urlencode(menu); | ||
81 | + var gu_select_encode = urlencode(gu_select); | ||
82 | + | ||
83 | + //api | ||
84 | + let pet_url = `http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03?serviceKey=${ANIMAL_INFO_API_KEY}&numOfRows=200&pageNo=1&keyword=${menu_encode}&where=${gu_select_encode}`; | ||
85 | + request(pet_url, function(err, response, body){ | ||
86 | + if(err) { | ||
87 | + console.log(`err => ${err}`) | ||
88 | + } | ||
89 | + else { | ||
90 | + if(res.statusCode == 200) { | ||
91 | + var medicine_list = []; | ||
92 | + var titles = ''; | ||
93 | + | ||
94 | + var result = convert.xml2json(body, {compact: true, spaces: 4}); | ||
95 | + var petJson = JSON.parse(result); | ||
96 | + var itemList = petJson.response.body.items; | ||
97 | + var numRows = petJson.response.body.totalCount._text; //개수 | ||
98 | + | ||
99 | + //------------------------------------------------- | ||
100 | + if (numRows == 1){ | ||
101 | + // state 정상인 것만 추리기 | ||
102 | + if (itemList.item.state._text == '정상'){ | ||
103 | + appliance_list.push(itemList.item); | ||
104 | + } | ||
105 | + } | ||
106 | + else if (numRows == 0){} | ||
107 | + else { | ||
108 | + for (i=0; i<numRows; i++){ | ||
109 | + // state 정상인 것만 추리기 | ||
110 | + if (itemList.item[i].state._text == '정상'){ | ||
111 | + appliance_list.push(itemList.item[i]); | ||
112 | + } | ||
113 | + } | ||
114 | + } | ||
115 | + //----------------------------------------------- | ||
116 | + | ||
117 | + //테스트용 console.log | ||
118 | + for(i=0; i<medicine_list.length; i++){ | ||
119 | + titles = titles+medicine_list[i].title._text+'\n'; | ||
120 | + } | ||
121 | + if (titles == '') {console.log('nothing');} | ||
122 | + else {console.log(titles); } | ||
123 | + } | ||
124 | + } | ||
125 | + res.render('result', { category: 'medicine', titles: titles, medicine_list: medicine_list }); | ||
126 | + }) | ||
127 | + }); | ||
128 | + | ||
129 | +//의료기기 | ||
130 | +router.post('/appliance', function(req, res){ | ||
131 | + //gu 받아오기 | ||
132 | + var body = req.body; | ||
133 | + var gu_select = body.user_gu; | ||
134 | + var menu = "동물의료기기 판매 및 임대업체"; | ||
135 | + | ||
136 | + // encoding for url | ||
137 | + var menu_encode = urlencode(menu); | ||
138 | + var gu_select_encode = urlencode(gu_select); | ||
139 | + | ||
140 | + //api | ||
141 | + let pet_url = `http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03?serviceKey=${ANIMAL_INFO_API_KEY}&numOfRows=100&pageNo=1&keyword=${menu_encode}&where=${gu_select_encode}`; | ||
142 | + request(pet_url, function(err, response, body){ | ||
143 | + if(err) { | ||
144 | + console.log(`err => ${err}`) | ||
145 | + } | ||
146 | + else { | ||
147 | + if(res.statusCode == 200) { | ||
148 | + var appliance_list = []; | ||
149 | + var titles = ''; | ||
150 | + | ||
151 | + var result = convert.xml2json(body, {compact: true, spaces: 4}); | ||
152 | + var petJson = JSON.parse(result); | ||
153 | + var itemList = petJson.response.body.items; | ||
154 | + var numRows = petJson.response.body.totalCount._text; //개수 | ||
155 | + | ||
156 | + //------------------------------------------------- | ||
157 | + if (numRows == 1){ | ||
158 | + // state 정상인 것만 추리기 | ||
159 | + if (itemList.item.state._text == '정상'){ | ||
160 | + appliance_list.push(itemList.item); | ||
161 | + } | ||
162 | + } | ||
163 | + else if (numRows == 0){} | ||
164 | + else { | ||
165 | + for (i=0; i<numRows; i++){ | ||
166 | + // state 정상인 것만 추리기 | ||
167 | + if (itemList.item[i].state._text == '정상'){ | ||
168 | + appliance_list.push(itemList.item[i]); | ||
169 | + } | ||
170 | + } | ||
171 | + } | ||
172 | + //----------------------------------------------- | ||
173 | + | ||
174 | + //테스트용 console.log | ||
175 | + for(i=0; i<appliance_list.length; i++){ | ||
176 | + titles = titles+appliance_list[i].title._text+'\n'; | ||
177 | + } | ||
178 | + if (titles == '') {console.log('nothing');} | ||
179 | + else {console.log(titles); } | ||
180 | + | ||
181 | + } | ||
182 | + } | ||
183 | + res.render('result', { category: 'appliance', titles: titles, appliance_list: appliance_list }); | ||
184 | + }) | ||
185 | + }); | ||
186 | + | ||
187 | +/* | ||
188 | +//체육시설 | ||
189 | +router.post('/park', function(req, res){ | ||
190 | + //gu 받아오기 | ||
191 | + var body = req.body; | ||
192 | + var gu_select = body.user_gu; | ||
193 | + var menu = ["생활체육관", "학교체육시설", "풋살장", "축구장"]; | ||
194 | + | ||
195 | + // encoding for url | ||
196 | + var menu_encode = []; | ||
197 | + for (var j = 0; j<menu.length;j++){ | ||
198 | + menu_encode[j]=urlencode(menu[j]); | ||
199 | + } | ||
200 | + var gu_select_encode = urlencode(gu_select); | ||
201 | + | ||
202 | + //api | ||
203 | + let pet_url = `http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03?serviceKey=${ANIMAL_INFO_API_KEY}&numOfRows=100&pageNo=1&keyword=${menu_encode[0]}&where=${gu_select_encode}`; | ||
204 | + //let pet_url = `http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03?serviceKey=${ANIMAL_INFO_API_KEY}&numOfRows=100&pageNo=1&keyword=%EC%83%9D%ED%99%9C%EC%B2%B4%EC%9C%A1%EA%B4%80&where=${gu_select_encode}`; | ||
205 | + request(pet_url, function(err, response, body){ | ||
206 | + if(err) { | ||
207 | + console.log(`err => ${err}`) | ||
208 | + } | ||
209 | + else { | ||
210 | + if(res.statusCode == 200) { | ||
211 | + var appliance_list = []; | ||
212 | + var titles = ''; | ||
213 | + | ||
214 | + var result = convert.xml2json(body, {compact: true, spaces: 4}); | ||
215 | + var petJson = JSON.parse(result) | ||
216 | + | ||
217 | + var itemList = petJson.response.body.items; | ||
218 | + var numRows = petJson.response.body.totalCount._text; //개수 | ||
219 | + | ||
220 | + //------------------------------------------------- | ||
221 | + if (numRows == 1){ | ||
222 | + // state 정상인 것만 추리기 | ||
223 | + if (itemList.item.state._text == '정상'){ | ||
224 | + appliance_list.push(itemList.item); | ||
225 | + } | ||
226 | + } | ||
227 | + else if (numRows == 0){} | ||
228 | + else { | ||
229 | + for (i=0; i<numRows; i++){ | ||
230 | + // state 정상인 것만 추리기 | ||
231 | + if (itemList.item[i].state._text == '정상'){ | ||
232 | + appliance_list.push(itemList.item[i]); | ||
233 | + } | ||
234 | + } | ||
235 | + } | ||
236 | + //----------------------------------------------- | ||
237 | + } | ||
238 | + } | ||
239 | + | ||
240 | + //api | ||
241 | + let pet_url = `http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03?serviceKey=${ANIMAL_INFO_API_KEY}&numOfRows=100&pageNo=1&keyword=${menu_encode[1]}&where=${gu_select_encode}`; | ||
242 | + //let pet_url = `http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03?serviceKey=${ANIMAL_INFO_API_KEY}&numOfRows=100&pageNo=1&keyword=%EC%83%9D%ED%99%9C%EC%B2%B4%EC%9C%A1%EA%B4%80&where=${gu_select_encode}`; | ||
243 | + request(pet_url, function(err, response, body){ | ||
244 | + if(err) { | ||
245 | + console.log(`err => ${err}`) | ||
246 | + } | ||
247 | + else { | ||
248 | + if(res.statusCode == 200) { | ||
249 | + //var appliance_list = []; | ||
250 | + //var titles = ''; | ||
251 | + | ||
252 | + var result = convert.xml2json(body, {compact: true, spaces: 4}); | ||
253 | + var petJson = JSON.parse(result) | ||
254 | + | ||
255 | + var itemList = petJson.response.body.items; | ||
256 | + var numRows = itemList.item.length; //개수 | ||
257 | + for (i=0; i<numRows; i++){ | ||
258 | + appliance_list.push(itemList.item[i]); | ||
259 | + } | ||
260 | + | ||
261 | + //테스트용 console.log | ||
262 | + for(i=0; i<appliance_list.length; i++){ | ||
263 | + titles = titles+appliance_list[i].title._text+'\n'; | ||
264 | + } | ||
265 | + | ||
266 | + if (titles == '') {console.log('nothing');} | ||
267 | + else {console.log(titles); } | ||
268 | + | ||
269 | + } | ||
270 | + } | ||
271 | + let pet_url = `http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03?serviceKey=${ANIMAL_INFO_API_KEY}&numOfRows=100&pageNo=1&keyword=${menu_encode[2]}&where=${gu_select_encode}`; | ||
272 | + request(pet_url, function(err, response, body){ | ||
273 | + if(err) { | ||
274 | + console.log(`err => ${err}`) | ||
275 | + } | ||
276 | + else { | ||
277 | + if(res.statusCode == 200) { | ||
278 | + //var appliance_list = []; | ||
279 | + //var titles = ''; | ||
280 | + | ||
281 | + var result = convert.xml2json(body, {compact: true, spaces: 4}); | ||
282 | + var petJson = JSON.parse(result) | ||
283 | + | ||
284 | + var itemList = petJson.response.body.items; | ||
285 | + var numRows = petJson.response.body.totalCount._text; //개수 | ||
286 | + | ||
287 | + //------------------------------------------------- | ||
288 | + if (numRows == 1){ | ||
289 | + // state 정상인 것만 추리기 | ||
290 | + if (itemList.item.state._text == '정상'){ | ||
291 | + appliance_list.push(itemList.item); | ||
292 | + } | ||
293 | + } | ||
294 | + else if (numRows == 0){} | ||
295 | + else { | ||
296 | + for (i=0; i<numRows; i++){ | ||
297 | + // state 정상인 것만 추리기 | ||
298 | + if (itemList.item[i].state._text == '정상'){ | ||
299 | + appliance_list.push(itemList.item[i]); | ||
300 | + } | ||
301 | + } | ||
302 | + } | ||
303 | + //----------------------------------------------- | ||
304 | + | ||
305 | + //테스트용 console.log | ||
306 | + for(i=0; i<appliance_list.length; i++){ | ||
307 | + titles = titles+appliance_list[i].title._text+'\n'; | ||
308 | + } | ||
309 | + if (titles == '') {console.log('nothing');} | ||
310 | + else {console.log(titles); } | ||
311 | + } | ||
312 | + } | ||
313 | + res.render('result', { category: 'park', titles: titles, appliance_list: appliance_list }); | ||
314 | + }); | ||
315 | + }); | ||
316 | + }); | ||
317 | + });*/ | ||
318 | + | ||
319 | +module.exports = router; | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -91,7 +91,7 @@ | ... | @@ -91,7 +91,7 @@ |
91 | <p> | 91 | <p> |
92 | 지역 선택 | 92 | 지역 선택 |
93 | </p> | 93 | </p> |
94 | - <form action="/category/hospital" method="post" name="location" id="location"> | 94 | + <form action="/category/park" method="post" name="location" id="location"> |
95 | <select onchange="sm()" name="user_gu" id="user_gu_select"> | 95 | <select onchange="sm()" name="user_gu" id="user_gu_select"> |
96 | <option value='' selected="true" disabled="true">--Please choose an option--</option> | 96 | <option value='' selected="true" disabled="true">--Please choose an option--</option> |
97 | <option value='금천구'>금천구</option> | 97 | <option value='금천구'>금천구</option> | ... | ... |
views/results/appliance.ejs
0 → 100644
1 | +it's appliance page | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
views/results/medicine.ejs
0 → 100644
1 | +it's medicine page | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
views/results/park.ejs
0 → 100644
1 | +it's park page | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment