오수빈

make array of hospital

...@@ -10,24 +10,34 @@ let ANIMAL_INFO_API_KEY = process.env.REACT_APP_API_KEY; ...@@ -10,24 +10,34 @@ let ANIMAL_INFO_API_KEY = process.env.REACT_APP_API_KEY;
10 let user_gu; 10 let user_gu;
11 let user_latitude; 11 let user_latitude;
12 let user_longitude; 12 let user_longitude;
13 +let hospital_list = [];
13 14
14 router.get('/hospital', function (req, res) { 15 router.get('/hospital', function (req, res) {
15 -
16 let pet_url = `http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03?serviceKey=${ANIMAL_INFO_API_KEY}&numOfRows=10&pageNo=1&keyword=%EB%8F%99%EB%AC%BC%EB%B3%91%EC%9B%90&where=%EA%B0%95%EB%B6%81%EA%B5%AC`; 16 let pet_url = `http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03?serviceKey=${ANIMAL_INFO_API_KEY}&numOfRows=10&pageNo=1&keyword=%EB%8F%99%EB%AC%BC%EB%B3%91%EC%9B%90&where=%EA%B0%95%EB%B6%81%EA%B5%AC`;
17 -
18 request(pet_url, function(err, response, body){ 17 request(pet_url, function(err, response, body){
19 if(err) { 18 if(err) {
20 console.log(`err => ${err}`) 19 console.log(`err => ${err}`)
21 } 20 }
22 else { 21 else {
23 if(res.statusCode == 200) { 22 if(res.statusCode == 200) {
24 - var result = body; 23 + var result = convert.xml2json(body, {compact: true, spaces: 4});
25 - console.log(`body data => ${result}`); 24 + var petJson = JSON.parse(result)
26 - var xmlToJson = convert.xml2json(result, {compact: true, spaces: 4}); 25 + var numRows = petJson.response.body.numOfRows._text;
27 - console.log(`xml to json => ${xmlToJson}`); 26 + var itemList = petJson.response.body.items;
27 + for (i=0; i<numRows; i++){
28 + if (itemList.item[i].state._text == '정상'){
29 + hospital_list.push(itemList.item[i]);
30 + }
31 + }
32 +
33 + var titles = '';
34 +
35 + for(i=0; i<hospital_list.length; i++){
36 + titles = titles+hospital_list[i].title._text+'\n';
37 + }
28 } 38 }
29 } 39 }
30 - res.send("finish"); 40 + res.send(titles);
31 }) 41 })
32 }); 42 });
33 43
......