Eunsu486

Modifyinf files

......@@ -10,57 +10,7 @@ let ANIMAL_INFO_API_KEY = process.env.REACT_APP_API_KEY;
let gu_select;
//동물병원
// router.post('/hospital', function (req, res) {
// //gu 받아오기
// var body = req.body;
// var gu_select = body.user_gu;
// var menu = '동물병원';
// // encoding for url
// var menu_encode = urlencode(menu);
// var gu_select_encode = urlencode(gu_select);
// //api
// 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}`;
// request(pet_url, function (err, response, body) {
// if (err) {
// console.log(`err => ${err}`)
// }
// else {
// if (res.statusCode == 200) {
// var hospital_list = [];
// var titles = '';
// var result = convert.xml2json(body, { compact: true, spaces: 4 });
// var petJson = JSON.parse(result);
// var itemList = petJson.response.body.items;
// var numRows = petJson.response.body.totalCount._text; //개수
// if (numRows == 1) {
// // state 정상인 것만 추리기
// if (itemList.item.state._text == '정상') {
// appliance_list.push(itemList.item);
// }
// }
// else if (numRows == 0) { }
// else {
// for (i = 0; i < numRows; i++) {
// // state 정상인 것만 추리기
// if (itemList.item[i].state._text == '정상') {
// appliance_list.push(itemList.item[i]);
// }
// }
// }
// //테스트용 console.log
// for (i = 0; i < hospital_list.length; i++) {
// titles = titles + hospital_list[i].title._text + '\n';
// }
// if (titles == '') { console.log('nothing'); }
// else { console.log(titles); }
// }
// }
// res.render('result', { category: 'hospital', titles: titles, hospital_list: hospital_list });
// })
// });
// 사용자가 index 페이지에서 주소를 입력하고 넘어오면
// 사용자가 index 페이지에서 주소선택. 입력값받아오는 함수
router.post('/', function (req, res) {
var body = req.body;
gu_select = body.user_gu;
......@@ -68,6 +18,7 @@ router.post('/', function (req, res) {
});
//동물병원 함수
router.get('/hospital', function (req, res) {
//api
var gu_select_encode = urlencode(gu_select);
......@@ -104,65 +55,50 @@ router.get('/hospital', function (req, res) {
//동물약국
router.get('/medicine', function (req, res) {
//gu 받아오기
var body = req.body;
var gu_select = body.user_gu;
//api
var gu_select_encode = urlencode(gu_select);
var menu = '동물약국';
// encoding for url
var menu_encode = urlencode(menu);
var gu_select_encode = urlencode(gu_select);
//api
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}`;
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}`;
request(pet_url, function (err, response, body) {
if (err) {
console.log(`err => ${err}`)
}
else {
if (res.statusCode == 200) {
var medicine_list = [];
var titles = '';
let category_list = [];
var result = convert.xml2json(body, { compact: true, spaces: 4 });
var petJson = JSON.parse(result);
var petJson = JSON.parse(result)
var itemList = petJson.response.body.items;
var numRows = petJson.response.body.totalCount._text; //개수
if (numRows == 1) {
var numRows = itemList.item.length; //개수
for (i = 0; i < numRows; i++) {
// state 정상인 것만 추리기
if (itemList.item.state._text == '정상') {
appliance_list.push(itemList.item);
}
}
else if (numRows == 0) { }
else {
for (i = 0; i < numRows; i++) {
// state 정상인 것만 추리기
if (itemList.item[i].state._text == '정상') {
appliance_list.push(itemList.item[i]);
}
if (itemList.item[i].state._text == '정상') {
category_list.push(itemList.item[i]);
}
}
//테스트용 console.log
for (i = 0; i < medicine_list.length; i++) {
titles = titles + medicine_list[i].title._text + '\n';
var titles = '';
for (i = 0; i < category_list.length; i++) {
titles = titles + category_list[i].title._text + '\n';
}
if (titles == '') { console.log('nothing'); }
else { console.log(titles); }
console.log(titles);
res.render('result', { category: 'medicine', titles: titles, category_list: category_list });
}
}
res.render('result', { category: 'medicine', titles: titles, medicine_list: medicine_list });
})
});
//의료기기
router.get('/appliance', function (req, res) {
//gu 받아오기
var body = req.body;
var gu_select = body.user_gu;
var menu = "동물의료기기 판매 및 임대업체";
// encoding for url
var menu_encode = urlencode(menu);
var gu_select_encode = urlencode(gu_select);
//api
var gu_select_encode = urlencode(gu_select);
var menu = '동물의료기기판매및임대업체';
var menu_encode = urlencode(menu);
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}`;
request(pet_url, function (err, response, body) {
if (err) {
......@@ -170,47 +106,33 @@ router.get('/appliance', function (req, res) {
}
else {
if (res.statusCode == 200) {
var appliance_list = [];
var titles = '';
let category_list = [];
var result = convert.xml2json(body, { compact: true, spaces: 4 });
var petJson = JSON.parse(result);
var petJson = JSON.parse(result)
var itemList = petJson.response.body.items;
var numRows = petJson.response.body.totalCount._text; //개수
//-------------------------------------------------
if (numRows == 1) {
var numRows = itemList.item.length; //개수
for (i = 0; i < numRows; i++) {
// state 정상인 것만 추리기
if (itemList.item.state._text == '정상') {
appliance_list.push(itemList.item);
}
}
else if (numRows == 0) { }
else {
for (i = 0; i < numRows; i++) {
// state 정상인 것만 추리기
if (itemList.item[i].state._text == '정상') {
appliance_list.push(itemList.item[i]);
}
if (itemList.item[i].state._text == '정상') {
category_list.push(itemList.item[i]);
}
}
//-----------------------------------------------
//테스트용 console.log
for (i = 0; i < appliance_list.length; i++) {
titles = titles + appliance_list[i].title._text + '\n';
var titles = '';
for (i = 0; i < category_list.length; i++) {
titles = titles + category_list[i].title._text + '\n';
}
if (titles == '') { console.log('nothing'); }
else { console.log(titles); }
console.log(titles);
res.render('result', { category: 'appliance', titles: titles, category_list: category_list });
}
}
res.render('result', { category: 'appliance', titles: titles, appliance_list: appliance_list });
})
});
//체육시설
router.post('/park', function (req, res) {
//gu 받아오기
var body = req.body;
var gu_select = body.user_gu;
var menu = ["생활체육관", "학교체육시설", "풋살장", "축구장"];
// encoding for url
var menu_encode = [];
......
......@@ -15,5 +15,5 @@
</tbody>
</table>
<p class="sum">총 개수 :
<%=appliance_list.length%>
<%=category_list.length%>
</p>
\ No newline at end of file
......
......@@ -16,5 +16,5 @@
</tbody>
</table>
<p class="sum">총 동물약국 개수 :
<%-medicine_list.length%>
<%-category_list.length%>
</p>
\ No newline at end of file
......