Eunsu486

Modify input function

......@@ -15,14 +15,12 @@ router.post('/', function (req, res) {
var body = req.body;
gu_select = body.user_gu;
console.log(gu_select);
res.send('Good');
});
//동물병원 함수
router.get('/hospital', function (req, res) {
//api
var gu_select_encode = urlencode(gu_select);
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=${gu_select_encode}`;
request(pet_url, function (err, response, body) {
if (err) {
......@@ -52,15 +50,12 @@ router.get('/hospital', function (req, res) {
}
})
});
//동물약국
router.get('/medicine', function (req, res) {
//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) {
......@@ -90,15 +85,12 @@ router.get('/medicine', function (req, res) {
}
})
});
//의료기기
router.get('/appliance', function (req, res) {
//api
var gu_select_encode = urlencode(gu_select);
var menu = '동물의료기기판매및임대업체';
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) {
......@@ -106,40 +98,48 @@ router.get('/appliance', function (req, res) {
}
else {
if (res.statusCode == 200) {
let category_list = [];
let appliance_list = [];
var result = convert.xml2json(body, { compact: true, spaces: 4 });
var petJson = JSON.parse(result)
var itemList = petJson.response.body.items;
var numRows = itemList.item.length; //개수
for (i = 0; i < numRows; i++) {
var numRows = petJson.response.body.totalCount._text; //개수
if (numRows == 1) {
// state 정상인 것만 추리기
if (itemList.item[i].state._text == '정상') {
category_list.push(itemList.item[i]);
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
var titles = '';
for (i = 0; i < category_list.length; i++) {
titles = titles + category_list[i].title._text + '\n';
for (i = 0; i < appliance_list.length; i++) {
titles = titles + appliance_list[i].title._text + '\n';
}
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) {
router.get('/park', function (req, res) {
var gu_select_encode = urlencode(gu_select);
var menu = ["생활체육관", "학교체육시설", "풋살장", "축구장"];
// encoding for url
var menu_encode = [];
for (var j = 0; j < menu.length; j++) {
menu_encode[j] = urlencode(menu[j]);
}
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=100&pageNo=1&keyword=${menu_encode[0]}&where=${gu_select_encode}`;
request(pet_url, function (err, response, body) {
......