Showing
1 changed file
with
30 additions
and
30 deletions
... | @@ -13,35 +13,35 @@ let user_longitude; | ... | @@ -13,35 +13,35 @@ let user_longitude; |
13 | let hospital_list = []; | 13 | let hospital_list = []; |
14 | 14 | ||
15 | router.get('/hospital', function (req, res) { | 15 | router.get('/hospital', function (req, res) { |
16 | - //api | 16 | + //api |
17 | - let pet_url = `http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03?serviceKey=${ANIMAL_INFO_API_KEY}&numOfRows=100&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 | + let pet_url = `http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03?serviceKey=${ANIMAL_INFO_API_KEY}&numOfRows=100&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`; |
18 | - request(pet_url, function(err, response, body){ | 18 | + request(pet_url, function (err, response, body) { |
19 | - if(err) { | 19 | + if (err) { |
20 | - console.log(`err => ${err}`) | 20 | + console.log(`err => ${err}`) |
21 | + } | ||
22 | + else { | ||
23 | + if (res.statusCode == 200) { | ||
24 | + var result = convert.xml2json(body, { compact: true, spaces: 4 }); | ||
25 | + var petJson = JSON.parse(result) | ||
26 | + var itemList = petJson.response.body.items; | ||
27 | + var numRows = itemList.item.length; //개수 | ||
28 | + for (i = 0; i < numRows; i++) { | ||
29 | + // state 정상인 것만 추리기 | ||
30 | + if (itemList.item[i].state._text == '정상') { | ||
31 | + hospital_list.push(itemList.item[i]); | ||
32 | + } | ||
21 | } | 33 | } |
22 | - else { | 34 | + |
23 | - if(res.statusCode == 200) { | 35 | + //테스트용 console.log |
24 | - var result = convert.xml2json(body, {compact: true, spaces: 4}); | 36 | + var titles = ''; |
25 | - var petJson = JSON.parse(result) | 37 | + for (i = 0; i < hospital_list.length; i++) { |
26 | - var itemList = petJson.response.body.items; | 38 | + titles = titles + hospital_list[i].title._text + '\n'; |
27 | - var numRows = itemList.item.length; //개수 | 39 | + } |
28 | - for (i=0; i<numRows; i++){ | 40 | + console.log(titles); |
29 | - // state 정상인 것만 추리기 | ||
30 | - if (itemList.item[i].state._text == '정상'){ | ||
31 | - hospital_list.push(itemList.item[i]); | ||
32 | - } | ||
33 | - } | ||
34 | - | ||
35 | - //테스트용 console.log | ||
36 | - var titles = ''; | ||
37 | - for(i=0; i<hospital_list.length; i++){ | ||
38 | - titles = titles+hospital_list[i].title._text+'\n'; | ||
39 | - } | ||
40 | - console.log(titles); | ||
41 | } | 41 | } |
42 | - } | ||
43 | - res.send("finish"); | ||
44 | - }) | ||
45 | - }); | ||
46 | - | ||
47 | - module.exports = router; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
42 | + } | ||
43 | + res.send("finish"); | ||
44 | + }) | ||
45 | +}); | ||
46 | + | ||
47 | +module.exports = router; | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment