Showing
1 changed file
with
49 additions
and
47 deletions
... | @@ -11,9 +11,52 @@ let ANIMAL_INFO_API_KEY = process.env.REACT_APP_API_KEY; | ... | @@ -11,9 +11,52 @@ let ANIMAL_INFO_API_KEY = process.env.REACT_APP_API_KEY; |
11 | let user_gu; | 11 | let user_gu; |
12 | let user_latitude; | 12 | let user_latitude; |
13 | let user_longitude; | 13 | let user_longitude; |
14 | -let hospital_list = []; | 14 | +//let hospital_list = []; |
15 | + | ||
16 | +// function list_print(res, menu_encode, gu_select_encode){ | ||
17 | +// //api | ||
18 | +// 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}`; | ||
19 | +// request(pet_url, function(err, response, body){ | ||
20 | +// if(err) { | ||
21 | +// console.log(`err => ${err}`) | ||
22 | +// } | ||
23 | +// else { | ||
24 | +// if(res.statusCode == 200) { | ||
25 | +// var result = convert.xml2json(body, {compact: true, spaces: 4}); | ||
26 | +// var petJson = JSON.parse(result) | ||
27 | +// var itemList = petJson.response.body.items; | ||
28 | +// var numRows = itemList.item.length; //개수 | ||
29 | +// for (i=0; i<numRows; i++){ | ||
30 | +// // state 정상인 것만 추리기 | ||
31 | +// if (itemList.item[i].state._text == '정상'){ | ||
32 | +// hospital_list.push(itemList.item[i]); | ||
33 | +// } | ||
34 | +// } | ||
35 | + | ||
36 | +// //테스트용 console.log | ||
37 | +// var titles = ''; | ||
38 | +// for(i=0; i<hospital_list.length; i++){ | ||
39 | +// titles = titles+hospital_list[i].title._text+'\n'; | ||
40 | +// } | ||
41 | +// console.log(titles); | ||
42 | +// } | ||
43 | +// } | ||
44 | +// res.render('result', { category: 'hospital', titles: titles, hospital_list: hospital_list }); | ||
45 | +// }); | ||
46 | +// } | ||
47 | + | ||
48 | +router.post('/hospital', function(req, res){ | ||
49 | + //gu 받아오기 | ||
50 | + var body = req.body; | ||
51 | + var gu_select = body.user_gu; | ||
52 | + var menu = '동물병원'; | ||
53 | + | ||
54 | + // encoding for url | ||
55 | + var menu_encode = urlencode(menu); | ||
56 | + var gu_select_encode = urlencode(gu_select); | ||
57 | + | ||
58 | + //list_print(res, menu_encode, gu_select_encode); | ||
15 | 59 | ||
16 | -function list_print(res, menu_encode, gu_select_encode){ | ||
17 | //api | 60 | //api |
18 | 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}`; | 61 | 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}`; |
19 | request(pet_url, function(err, response, body){ | 62 | request(pet_url, function(err, response, body){ |
... | @@ -22,6 +65,9 @@ function list_print(res, menu_encode, gu_select_encode){ | ... | @@ -22,6 +65,9 @@ function list_print(res, menu_encode, gu_select_encode){ |
22 | } | 65 | } |
23 | else { | 66 | else { |
24 | if(res.statusCode == 200) { | 67 | if(res.statusCode == 200) { |
68 | + var hospital_list = []; //얘를 전역으로 선언해서 중복이 발생했던 거였어요 ㅠ | ||
69 | + var titles = ''; | ||
70 | + | ||
25 | var result = convert.xml2json(body, {compact: true, spaces: 4}); | 71 | var result = convert.xml2json(body, {compact: true, spaces: 4}); |
26 | var petJson = JSON.parse(result) | 72 | var petJson = JSON.parse(result) |
27 | var itemList = petJson.response.body.items; | 73 | var itemList = petJson.response.body.items; |
... | @@ -34,7 +80,6 @@ function list_print(res, menu_encode, gu_select_encode){ | ... | @@ -34,7 +80,6 @@ function list_print(res, menu_encode, gu_select_encode){ |
34 | } | 80 | } |
35 | 81 | ||
36 | //테스트용 console.log | 82 | //테스트용 console.log |
37 | - var titles = ''; | ||
38 | for(i=0; i<hospital_list.length; i++){ | 83 | for(i=0; i<hospital_list.length; i++){ |
39 | titles = titles+hospital_list[i].title._text+'\n'; | 84 | titles = titles+hospital_list[i].title._text+'\n'; |
40 | } | 85 | } |
... | @@ -42,50 +87,7 @@ function list_print(res, menu_encode, gu_select_encode){ | ... | @@ -42,50 +87,7 @@ function list_print(res, menu_encode, gu_select_encode){ |
42 | } | 87 | } |
43 | } | 88 | } |
44 | res.render('result', { category: 'hospital', titles: titles, hospital_list: hospital_list }); | 89 | res.render('result', { category: 'hospital', titles: titles, hospital_list: hospital_list }); |
45 | - }); | 90 | + }) |
46 | -} | ||
47 | - | ||
48 | -router.post('/hospital', function(req, res){ | ||
49 | - //gu 받아오기 | ||
50 | - var body = req.body; | ||
51 | - var gu_select = body.user_gu; | ||
52 | - var menu = '동물병원'; | ||
53 | - | ||
54 | - // encoding for url | ||
55 | - var menu_encode = urlencode(menu); | ||
56 | - var gu_select_encode = urlencode(gu_select); | ||
57 | - | ||
58 | - list_print(res, menu_encode, gu_select_encode); | ||
59 | - | ||
60 | - // //api | ||
61 | - // 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}`; | ||
62 | - // request(pet_url, function(err, response, body){ | ||
63 | - // if(err) { | ||
64 | - // console.log(`err => ${err}`) | ||
65 | - // } | ||
66 | - // else { | ||
67 | - // if(res.statusCode == 200) { | ||
68 | - // var result = convert.xml2json(body, {compact: true, spaces: 4}); | ||
69 | - // var petJson = JSON.parse(result) | ||
70 | - // var itemList = petJson.response.body.items; | ||
71 | - // var numRows = itemList.item.length; //개수 | ||
72 | - // for (i=0; i<numRows; i++){ | ||
73 | - // // state 정상인 것만 추리기 | ||
74 | - // if (itemList.item[i].state._text == '정상'){ | ||
75 | - // hospital_list.push(itemList.item[i]); | ||
76 | - // } | ||
77 | - // } | ||
78 | - | ||
79 | - // //테스트용 console.log | ||
80 | - // var titles = ''; | ||
81 | - // for(i=0; i<hospital_list.length; i++){ | ||
82 | - // titles = titles+hospital_list[i].title._text+'\n'; | ||
83 | - // } | ||
84 | - // console.log(titles); | ||
85 | - // } | ||
86 | - // } | ||
87 | - // res.render('result', { category: 'hospital', titles: titles, hospital_list: hospital_list }); | ||
88 | - // }) | ||
89 | }); | 91 | }); |
90 | 92 | ||
91 | module.exports = router; | 93 | module.exports = router; |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment