오수빈

add function medicine and appliance

......@@ -12,6 +12,7 @@ let user_gu;
let user_latitude;
let user_longitude;
//동물병원
router.post('/hospital', function(req, res){
//gu 받아오기
var body = req.body;
......@@ -23,36 +24,296 @@ router.post('/hospital', function(req, res){
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}&where=${gu_select_encode}`;
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 hospital_list = [];
var titles = '';
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 = itemList.item.length; //개수
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 == '정상'){
hospital_list.push(itemList.item[i]);
appliance_list.push(itemList.item[i]);
}
}
}
//-----------------------------------------------
//테스트용 console.log
for(i=0; i<hospital_list.length; i++){
titles = titles+hospital_list[i].title._text+'\n';
}
console.log(titles);
if (titles == '') {console.log('nothing');}
else {console.log(titles); }
}
}
res.render('result', { category: 'hospital', titles: titles, hospital_list: hospital_list });
})
});
module.exports = router;
\ No newline at end of file
//동물약국
router.post('/medicine', 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 medicine_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<medicine_list.length; i++){
titles = titles+medicine_list[i].title._text+'\n';
}
if (titles == '') {console.log('nothing');}
else {console.log(titles); }
}
}
res.render('result', { category: 'medicine', titles: titles, medicine_list: medicine_list });
})
});
//의료기기
router.post('/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
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 appliance_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<appliance_list.length; i++){
titles = titles+appliance_list[i].title._text+'\n';
}
if (titles == '') {console.log('nothing');}
else {console.log(titles); }
}
}
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 = [];
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}`;
//let pet_url = `http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03?serviceKey=${ANIMAL_INFO_API_KEY}&numOfRows=100&pageNo=1&keyword=%EC%83%9D%ED%99%9C%EC%B2%B4%EC%9C%A1%EA%B4%80&where=${gu_select_encode}`;
request(pet_url, function(err, response, body){
if(err) {
console.log(`err => ${err}`)
}
else {
if(res.statusCode == 200) {
var appliance_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]);
}
}
}
//-----------------------------------------------
}
}
//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[1]}&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=%EC%83%9D%ED%99%9C%EC%B2%B4%EC%9C%A1%EA%B4%80&where=${gu_select_encode}`;
request(pet_url, function(err, response, body){
if(err) {
console.log(`err => ${err}`)
}
else {
if(res.statusCode == 200) {
//var appliance_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 = itemList.item.length; //개수
for (i=0; i<numRows; i++){
appliance_list.push(itemList.item[i]);
}
//테스트용 console.log
for(i=0; i<appliance_list.length; i++){
titles = titles+appliance_list[i].title._text+'\n';
}
if (titles == '') {console.log('nothing');}
else {console.log(titles); }
}
}
let pet_url = `http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03?serviceKey=${ANIMAL_INFO_API_KEY}&numOfRows=100&pageNo=1&keyword=${menu_encode[2]}&where=${gu_select_encode}`;
request(pet_url, function(err, response, body){
if(err) {
console.log(`err => ${err}`)
}
else {
if(res.statusCode == 200) {
//var appliance_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<appliance_list.length; i++){
titles = titles+appliance_list[i].title._text+'\n';
}
if (titles == '') {console.log('nothing');}
else {console.log(titles); }
}
}
res.render('result', { category: 'park', titles: titles, appliance_list: appliance_list });
});
});
});
});*/
module.exports = router;
\ No newline at end of file
......
......@@ -91,7 +91,7 @@
<p>
지역 선택
</p>
<form action="/category/hospital" method="post" name="location" id="location">
<form action="/category/park" method="post" name="location" id="location">
<select onchange="sm()" name="user_gu" id="user_gu_select">
<option value='' selected="true" disabled="true">--Please choose an option--</option>
<option value='금천구'>금천구</option>
......
it's appliance page
\ No newline at end of file
it's medicine page
\ No newline at end of file
it's park page
\ No newline at end of file