Suyeon Jung

Fix error

......@@ -143,8 +143,8 @@ let sigun = [{
sigun_name: '화성시',
sigun_code: 41590
},
]
]
// 결과 중 사용자 근처인지 검사하기 위한 함수
let userArea = function(target, targetKey, user) {
if (target[targetKey].includes(user)) {
return true;
......@@ -160,9 +160,15 @@ router.post('/', function(req, res) {
user_gu = req.body.gu;
user_dong = req.body.dong;
userLocation = `${user_sigun} ${user_gu} ${user_dong}`;
console.log(user_sigun);
console.log(user_gu);
console.log(user_dong);
if (user_gu == '') {
user_target = user_dong;
} else {
user_target = user_gu;
}
console.log('user_sigun', user_sigun);
console.log('user_gu', user_gu);
console.log('user_dong', user_dong);
let KAKAO_API_KEY = process.env.KAKAO_APIKEY;
let kakaoOptions = {
url: 'https://dapi.kakao.com/v2/local/search/address.json',
......@@ -189,8 +195,8 @@ router.post('/', function(req, res) {
var result = JSON.parse(body);
console.log('result', result);
user_latitude = result.documents[0].address.x;
user_logitude = result.documents[0].address.y;
console.log('위도, 경도', user_latitude, user_logitude);
user_longitude = result.documents[0].address.y;
console.log('위도, 경도', user_latitude, user_longitude);
}
})
res.render('category', { userLocation: userLocation });
......@@ -215,7 +221,7 @@ router.get('/food', function(req, res) {
for (let i = 0; i < food_result.PlaceThatDoATasteyFoodSt[1].row.length; i++) {
// 상호명, 음식명, 전화번호, 도로명주소(REFINE_ROADNM_ADDR), 지번 주소(REFINE_LOTNO_ADDR)
store = food_result.PlaceThatDoATasteyFoodSt[1].row[i];
if (userArea(store, 'REFINE_LOTNO_ADDR', user_dong)) {
if (userArea(store, 'REFINE_LOTNO_ADDR', user_target)) {
console.log('store', store);
stores.push(store);
}
......@@ -232,12 +238,12 @@ router.get('/food', function(req, res) {
for (let i = 0; i < fast_food_result.Genrestrtfastfood[1].row.length; i++) {
fast_food_store = fast_food_result.Genrestrtfastfood[1].row[i];
// 폐업인 지점 제외
if (fast_food_store['BSN_STATE_NM'] != '폐업' && userArea(fast_food_store, 'REFINE_LOTNO_ADDR', user_dong)) {
if (fast_food_store['BSN_STATE_NM'] != '폐업' && userArea(fast_food_store, 'REFINE_LOTNO_ADDR', user_target)) {
console.log('fast_store_name', fast_food_store);
fast_food_stores.push(fast_food_store);
}
}
res.render('food_result', { stores: stores, fast_food_stores: fast_food_stores });
res.render('result', { category: 'food', stores: stores, fast_food_stores: fast_food_stores, userLocation: userLocation, grade: 'A' });
}
})
......@@ -261,7 +267,7 @@ router.get('/school', function(req, res) {
let librarys = [];
for (let i = 0; i < library_result.Tbggibllbrm[1].row.length; i++) {
library = library_result.Tbggibllbrm[1].row[i];
if (userArea(library, 'REFINE_LOTNO_ADDR', user_dong)) {
if (userArea(library, 'REFINE_LOTNO_ADDR', user_target)) {
console.log('library', library);
librarys.push(library);
}
......@@ -277,12 +283,12 @@ router.get('/school', function(req, res) {
let institutes = [];
for (let i = 0; i < institute_result.TninsttInstutM[1].row.length; i++) {
institute = institute_result.TninsttInstutM[1].row[i];
if (userArea(institute, 'REFINE_LOTNO_ADDR', user_dong)) {
if (userArea(institute, 'REFINE_LOTNO_ADDR', user_target)) {
console.log('institute', institute);
institutes.push(institute);
}
}
res.render('school_result', { librarys: librarys, institutes: institutes });
res.render('result', { category: 'school', librarys: librarys, institutes: institutes, userLocation: userLocation, grade: 'A' });
}
})
}
......@@ -304,66 +310,57 @@ router.get('/park', function(req, res) {
let city_parks = [];
for (let i = 0; i < city_park_result.CityPark[1].row.length; i++) {
city_park = city_park_result.CityPark[1].row[i];
if (userArea(city_park, 'REFINE_LOTNO_ADDR', user_dong)) {
if (userArea(city_park, 'REFINE_LOTNO_ADDR', user_target)) {
city_parks.push(city_park);
}
}
res.render('park_result', { city_parks: city_parks });
res.render('result', { category: 'park', city_parks: city_parks, userLocation: userLocation, grade: 'A' });
}
// if (park_result.CityPark[0].head[1].RESULT.CODE == 'INFO-000') {
// cityparknum = park_result.CityPark[0].head[0].list_total_count;
// console.log(cityparknum + "개의 도시공원이 존재합니다.");
// res.send(String(cityparknum) + "개의 도시공원이 존재합니다.");
// } else {
// res.send("도시공원이 없습니다.");
// }
})
});
router.get('/transport', function (req, res) {
let apikey=process.env.ODSAY_APIKEY
router.get('/transport', function(req, res) {
let bus_url = 'https://api.odsay.com/v1/api/pointSearch?lang=0&x=' + user_latitude + '&y=' + user_logitude + '&radius=500&stationClass=1&apiKey=' + apikey;
let subway_url = 'https://api.odsay.com/v1/api/pointSearch?lang=0&x=' + user_latitude + '&y=' + user_logitude + '&radius=1000&stationClass=2&apiKey=' + apikey;
let bus_url = 'https://api.odsay.com/v1/api/pointSearch?';
let subway_url = 'https://api.odsay.com/v1/api/pointSearch?';
let qs = `?lang=0&x=${user_latitude}&y=${user_longitude}&radius=1000&stationClass=2&apiKey=${ODSAY_API_KEY}`;
let busCnt = 0;
let subwayCnt=0;
let subwayCnt = 0;
console.log(bus_url);
request({
url: bus_url,
url: bus_url + qs,
method: 'GET'
}, function (err, response, body) {
}, function(err, response, body) {
if (!err && res.statusCode == 200) {
//console.log("inside");
let bus_result = JSON.parse(body);
//console.log(bus_result);
// console.log('bus_result', bus_result.result.station);
let busStations = [];
busCnt = bus_result.result.count;
console.log('in!');
for (var i = 0; i < busCnt; i++) {
busStations.push(bus_result.result.station[i].stationName);
console.log(bus_result.result)
for (let i = 0; i < bus_result.result.station.length; i++) {
station = bus_result.result.station[i];
console.log('station', station)
busStations.push(station);
}
console.log(busStations);
console.log('busStations', busStations);
request({
url: subway_url,
url: subway_url + qs,
method: 'GET'
}, function (err, response, body) {
}, function(err, response, body) {
if (!err && res.statusCode == 200) {
let subway_result = JSON.parse(body);
let subwayStations = [];
subwayCnt = subway_result.result.count;
console.log("지하철역 개수:" + subwayCnt);
console.log('in3!');
for (var i = 0; i < subwayCnt; i++) {
console.log(subway_result.result.station[i]);
subwayStations.push(subway_result.result.station[i].stationName);
console.log('subway_result', subway_result);
for (let i = 0; i < subway_result.result.station.length; i++) {
station = subway_result.result.station[i];
subwayStations.push(station);
}
console.log(busStations);
console.log(subwayStations);
res.render('transport',{busCnt:busCnt, busStations:busStations, subwayCnt:subwayCnt, subwayStations:subwayStations, total:busCnt+subwayCnt})
console.log('subwayStaions', subwayStations);
res.render('result', { category: 'transport', busStations: busStations, subwayStations: subwayStations, userLocation: userLocation, grade: 'A' })
}
})
......@@ -371,7 +368,6 @@ router.get('/transport', function (req, res) {
})
});
router.get('/safe', function(req, res) {
let cctv_url = 'https://openapi.gg.go.kr/CCTV';
......@@ -387,7 +383,7 @@ router.get('/safe', function(req, res) {
console.log(cctv_result);
for (let i = 0; i < cctv_result.CCTV[1].row.length; i++) {
cctv = cctv_result.CCTV[1].row[i];
if (userArea(cctv, 'REFINE_LOTNO_ADDR', user_dong)) {
if (userArea(cctv, 'REFINE_LOTNO_ADDR', user_target)) {
console.log('cctv', cctv);
cctvs.push(cctv);
}
......@@ -402,12 +398,12 @@ router.get('/safe', function(req, res) {
console.log(light_result);
for (let i = 0; i < light_result.SECRTLGT[1].row.length; i++) {
light = light_result.SECRTLGT[1].row[i];
if (userArea(light, 'REFINE_LOTNO_ADDR', user_dong)) {
if (userArea(light, 'REFINE_LOTNO_ADDR', user_target)) {
console.log('light', light);
lights.push(light);
}
}
res.render('safe_result', { cctvs: cctvs, lights: lights });
res.render('result', { category: 'safe', cctvs: cctvs, lights: lights, userLocation: userLocation, grade: 'A' });
}
})
}
......@@ -416,26 +412,26 @@ router.get('/safe', function(req, res) {
});
router.get('/culture', function(req, res) {
// 노래방
let sing_url = 'https://openapi.gg.go.kr/Songclub';
// 영화관
let movie_url = 'https://openapi.gg.go.kr/MovieTheater';
let qs = `?Type=json&KEY=${GYEONGI_API_KEY}&SIGUN_CD=${SIGUN_CODE}`;
request({
url: sing_url + qs,
url: movie_url + qs,
method: 'GET'
}, function(err, response, body) {
if (!err && res.statusCode == 200) {
let sing_result = JSON.parse(body);
console.log(sing_result);
let sings = [];
for (let i = 0; i < sing_result.Songclub[1].row.length; i++) {
sing = sing_result.Songclub[1].row[i];
let movie_result = JSON.parse(body);
console.log(movie_result);
let movies = [];
for (let i = 0; i < movie_result.MovieTheater[1].row.length; i++) {
movie = movie_result.MovieTheater[1].row[i];
// 폐업인 지점 제외
if (!sing['BSN_STATE_NM'].includes('폐업') && userArea(sing, 'REFINE_LOTNO_ADDR', user_dong)) {
console.log('sing', sing);
sings.push(sing);
if (!movie['BSN_STATE_NM'].includes('폐업') && userArea(movie, 'REFINE_LOTNO_ADDR', user_target)) {
console.log('movie', movie);
movies.push(movie);
}
}
res.render('culture_result', { sings: sings });
res.render('result', { category: 'culture', movies: movies, userLocation: userLocation, grade: 'A' });
}
});
});
......@@ -455,12 +451,12 @@ router.get('/shop', function(req, res) {
for (let i = 0; i < shop_result.MrktStoreM[1].row.length; i++) {
shop = shop_result.MrktStoreM[1].row[i];
// 폐업인 지점 제외
if (userArea(shop, 'REFINE_LOTNO_ADDR', user_dong)) {
if (userArea(shop, 'REFINE_LOTNO_ADDR', user_target)) {
console.log('shop', shop);
shops.push(shop);
}
}
res.render('shop_result', { shops: shops });
res.render('result', { category: 'shop', shops: shops, userLocation: userLocation, grade: 'A' });
}
})
......@@ -480,12 +476,12 @@ router.get('/gym', function(req, res) {
for (let i = 0; i < gym_result.PhysicaFitnessTrainingPlace[1].row.length; i++) {
gym = gym_result.PhysicaFitnessTrainingPlace[1].row[i];
console.log(gym);
if (userArea(gym, 'REFINE_LOTNO_ADDR', user_dong)) {
if (userArea(gym, 'REFINE_LOTNO_ADDR', user_target)) {
console.log('gym', gym);
gyms.push(gym);
}
}
res.render('gym_result', { gyms: gyms });
res.render('result', { category: 'gym', gyms: gyms, userLocation: userLocation, grade: 'A' });
}
})
});
......
......@@ -10,70 +10,6 @@
<link rel='stylesheet' href='/css/category.css'>
<title>📝 결과</title>
<h1>
🥘 맛집 현황</h1>
<table class="table">
<thead class="thead-dark">
<tr>
<th>음식점명</th>
<th>전화번호</th>
<th>대표음식</th>
<th>도로명주소</th>
</tr>
</thead>
<tbody>
<%for (var i =0; i <stores.length; i++){%>
<tr>
<td>
<%=stores[i].RESTRT_NM%>
</td>
<td>
<%=stores[i].TASTFDPLC_TELNO%>
</td>
<td>
<%=stores[i].REPRSNT_FOOD_NM%>
</td>
<td>
<%=stores[i].REFINE_ROADNM_ADDR%>
</td>
</tr>
<%}%>
</tbody>
</table>
<h3>총 맛집 개수 :
<%=stores.length%>
</h3>
<h1>🍔 패스트푸드점 현황 </h1>
<table class="table">
<thead class="thead-dark">
<tr>
<th>사업장명</th>
<th>도로명주소</th>
</tr>
</thead>
<tbody>
<%for (var i =0; i <fast_food_stores.length; i++){%>
<tr>
<td>
<%=fast_food_stores[i].BIZPLC_NM%>
</td>
<td>
<%=fast_food_stores[i].REFINE_ROADNM_ADDR%>
</td>
</tr>
<%}%>
</tbody>
</table>
<h3>패스트푸드점 개수 :
<%=fast_food_stores.length%>
</h3>
</head>
<body>
......
<h1>
🥘 맛집 현황</h1>
<table class="table">
<thead class="thead-dark">
<thead>
<tr>
<th>음식점명</th>
<th>전화번호</th>
......@@ -29,13 +29,10 @@
</tbody>
</table>
<h3>총 맛집 개수 :
<%=stores.length%>
</h3>
<h1>🍔 패스트푸드점 현황 </h1>
<table class="table">
......