Showing
1 changed file
with
202 additions
and
11 deletions
| ... | @@ -7,8 +7,22 @@ require('dotenv').config(); | ... | @@ -7,8 +7,22 @@ require('dotenv').config(); |
| 7 | let SIGUN_CODE; | 7 | let SIGUN_CODE; |
| 8 | let SIGUNDONG_CODE; | 8 | let SIGUNDONG_CODE; |
| 9 | 9 | ||
| 10 | +var express = require('express'); | ||
| 11 | +var router = express.Router(); | ||
| 12 | +var request = require('request'); | ||
| 13 | +require('dotenv').config(); | ||
| 14 | + | ||
| 15 | +/* GET home page. */ | ||
| 16 | +let SIGUN_CODE; | ||
| 17 | +let SIGUNDONG_CODE; | ||
| 18 | +let x=0; | ||
| 19 | +let y=0; | ||
| 20 | +var GyeongGi_apikey=process.env.GyeongGi_apikey; | ||
| 21 | + | ||
| 22 | + | ||
| 10 | // 사용자가 index 페이지에서 주소를 입력하고 넘어오면 | 23 | // 사용자가 index 페이지에서 주소를 입력하고 넘어오면 |
| 11 | -router.post('/', function(req, res) { | 24 | +router.post('/', function (req, res) { |
| 25 | + console.log(req.body); | ||
| 12 | let userLocation = req.body.userLocation; | 26 | let userLocation = req.body.userLocation; |
| 13 | // let userSi = req.body.si | 27 | // let userSi = req.body.si |
| 14 | // let userDong = req.body.dong; | 28 | // let userDong = req.body.dong; |
| ... | @@ -31,31 +45,208 @@ router.post('/', function(req, res) { | ... | @@ -31,31 +45,208 @@ router.post('/', function(req, res) { |
| 31 | if (!err && res.statusCode == 200) { | 45 | if (!err && res.statusCode == 200) { |
| 32 | var result = JSON.parse(body); | 46 | var result = JSON.parse(body); |
| 33 | console.log('result', result); | 47 | console.log('result', result); |
| 34 | - xyList.push(result.documents[0].address.x); | 48 | + x=result.documents[0].address.x; |
| 35 | - xyList.push(result.documents[0].address.y); | 49 | + y=result.documents[0].address.y; |
| 36 | - console.log(xyList); | 50 | + |
| 51 | + | ||
| 37 | } | 52 | } |
| 38 | }) | 53 | }) |
| 39 | res.render('category', { userLocation: req.body.userLocation }); | 54 | res.render('category', { userLocation: req.body.userLocation }); |
| 40 | }); | 55 | }); |
| 41 | 56 | ||
| 42 | -router.get('/food', function(req, res) { | 57 | +router.get('/food', function (req, res) { |
| 43 | res.send('This is food'); | 58 | res.send('This is food'); |
| 44 | }); | 59 | }); |
| 45 | -router.get('/school', function(req, res) { | 60 | +router.get('/school', function (req, res) { |
| 61 | + var academynum = 0; | ||
| 62 | + var librarynum = 0; | ||
| 63 | + var total_academic = 0; | ||
| 64 | + function callback(cb) { | ||
| 65 | + cb(); | ||
| 66 | + } | ||
| 67 | + let AcademyOptions = { | ||
| 68 | + url: "https://openapi.gg.go.kr/TninsttInstutM?Type=json&SIGUN_CD=" + SGCD + "&Key=" + GyeongGi_apikey, | ||
| 69 | + } | ||
| 70 | + request(AcademyOptions, function (err, res, body) { | ||
| 71 | + if (!err && res.statusCode == 200) { | ||
| 72 | + var academy_result = JSON.parse(body); | ||
| 73 | + if (academy_result.TninsttInstutM[0].head[1].RESULT.CODE == 'INFO-000') { | ||
| 74 | + academynum = academy_result.TninsttInstutM[0].head[0].list_total_count; | ||
| 75 | + console.log(academynum + "개의 학원이 존재합니다."); | ||
| 76 | + } | ||
| 77 | + else { | ||
| 78 | + | ||
| 79 | + "학원이 존재하지 않습니다."; | ||
| 80 | + } | ||
| 81 | + } | ||
| 82 | + }) | ||
| 83 | + let LibraryOptions = { | ||
| 84 | + url: "https://openapi.gg.go.kr/Tbggibllbrm?Type=json&SIGUN_CD=" + SGCD + "&Key=" + GyeongGi_apikey, | ||
| 85 | + | ||
| 86 | + } | ||
| 87 | + request(LibraryOptions, function (err, res, body) { | ||
| 88 | + if (!err && res.statusCode == 200) { | ||
| 89 | + var library_result = JSON.parse(body); | ||
| 90 | + //console.log(result.Tbggibllbrm[0].head[0].list_total_count); | ||
| 91 | + library_result = library_result.Tbggibllbrm[0]; | ||
| 92 | + if (result.head[1].RESULT.CODE == 'INFO-000') { | ||
| 93 | + librarynum = library_result.head[0].list_total_count; | ||
| 94 | + console.log(librarynum + "개의 도서관이 존재합니다."); | ||
| 95 | + } | ||
| 96 | + else { | ||
| 97 | + | ||
| 98 | + "도서관이 존재하지 않습니다."; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + } | ||
| 102 | + }) | ||
| 103 | + callback(function () { | ||
| 104 | + total_academic = librarynum + academynum; | ||
| 105 | + }) | ||
| 106 | + | ||
| 46 | res.send('This is school'); | 107 | res.send('This is school'); |
| 47 | }); | 108 | }); |
| 48 | -router.get('/park', function(req, res) { | 109 | +router.get('/park', function (req, res) { |
| 110 | + var cityparknum = 0; | ||
| 111 | + let ParkOptions = { | ||
| 112 | + url: "https://openapi.gg.go.kr/CityPark?Type=json&SIGUN_CD=" + SGCD + "&Key=" + GyeongGi_apikey, | ||
| 113 | + } | ||
| 114 | + request(ParkOptions, function (err, res, body) { | ||
| 115 | + if (!err && res.statusCode == 200) { | ||
| 116 | + var park_result = JSON.parse(body); | ||
| 117 | + if (park_result.CityPark[0].head[1].RESULT.CODE == 'INFO-000') { | ||
| 118 | + cityparknum = park_result.CityPark[0].head[0].list_total_count; | ||
| 119 | + console.log(cityparknum + "개의 도시공원이 존재합니다."); | ||
| 120 | + } | ||
| 121 | + else { | ||
| 122 | + | ||
| 123 | + console.log("주변에 도시공원이 없습니다."); | ||
| 124 | + } | ||
| 125 | + } | ||
| 126 | + }) | ||
| 127 | + | ||
| 49 | res.send('This is park'); | 128 | res.send('This is park'); |
| 50 | }); | 129 | }); |
| 51 | -router.get('/transport', function(req, res) { | 130 | +router.get('/transport', function (req, res) { |
| 52 | - res.send('This is transport'); | 131 | + function callback(cb) { |
| 132 | + cb(); | ||
| 133 | + } | ||
| 134 | + var BusCnt = 0; | ||
| 135 | + var busStationList = []; | ||
| 136 | + var subwayStationList = []; | ||
| 137 | + var SubwayCnt = 0; | ||
| 138 | + var TotalCnt = 0; | ||
| 139 | + // res.send('This is transport'); | ||
| 140 | + var apikey=process.env.ODSAY_APIKEY | ||
| 141 | + let BusOptions = { | ||
| 142 | + url: 'https://api.odsay.com/v1/api/pointSearch?lang=0&x=' + x + '&y=' + y + '&radius=500&stationClass=1&apiKey=' + apikey, | ||
| 143 | + encoding: 'UTF-8', | ||
| 144 | + } | ||
| 145 | + request(BusOptions, function (err, res, body) { | ||
| 146 | + if (!err && res.statusCode == 200) { | ||
| 147 | + var bus_result = JSON.parse(body); | ||
| 148 | + BusCnt = info_result.result.count; | ||
| 149 | + console.log("버스정류장 개수:" + BusCnt); | ||
| 150 | + for (var i = 0; i < BusCnt; i++) { | ||
| 151 | + busStationList.push(bus_result.result.station[i].stationName); | ||
| 152 | + } | ||
| 153 | + console.log(busStationList); | ||
| 154 | + callback(function () { | ||
| 155 | + let SubwayOptions = { | ||
| 156 | + url: 'https://api.odsay.com/v1/api/pointSearch?lang=0&x=' + x + '&y=' + y + '&radius=1000&stationClass=2&apiKey=' + apikey, | ||
| 157 | + encoding: 'UTF-8', | ||
| 158 | + } | ||
| 159 | + request(BusOptions, function (err, res, body) { | ||
| 160 | + if (!err && res.statusCode == 200) { | ||
| 161 | + var subway_result = JSON.parse(body); | ||
| 162 | + SubwayCnt = subway_result.result.count; | ||
| 163 | + console.log("지하철역 개수:" + SubwayCnt); | ||
| 164 | + for (var i = 0; i < SubwayCnt; i++) { | ||
| 165 | + subwayStationList.push(subway_result.result.station[i].stationName); | ||
| 166 | + } | ||
| 167 | + console.log(subwayStationList); | ||
| 168 | + callback(function () { | ||
| 169 | + //console.log(BusCnt,SubwayCnt); | ||
| 170 | + TotalCnt = BusCnt + SubwayCnt; | ||
| 171 | + console.log("총 정류장 개수:", TotalCnt); | ||
| 172 | + }) | ||
| 173 | + } | ||
| 174 | + }) | ||
| 175 | + }) | ||
| 176 | + } | ||
| 177 | + }) | ||
| 178 | + | ||
| 179 | + res.send(BusCnt); | ||
| 53 | }); | 180 | }); |
| 54 | -router.get('/safe', function(req, res) { | 181 | +router.get('/safe', function (req, res) { |
| 182 | + var secretlightnum = 0; //보안등 | ||
| 183 | + var safebellnum = 0; //비상벨 | ||
| 184 | + var cctvnum = 0; //cctv개수 | ||
| 185 | + var total_safe = 0; | ||
| 186 | + function callback(cb) { | ||
| 187 | + cb(); | ||
| 188 | + } | ||
| 189 | + let SecretLightOptions = { | ||
| 190 | + url: "https://openapi.gg.go.kr/SECRTLGT?Type=json&SIGUN_CD=" + SGCD + "&Key=" + GyeongGi_apikey; | ||
| 191 | + encoding: 'UTF-8', | ||
| 192 | + } | ||
| 193 | + request(SecretLightOptions, function (err, res, body) { | ||
| 194 | + if (!err && res.statusCode == 200) { | ||
| 195 | + secretlight_result = JSON.parse(xhr.responseText); | ||
| 196 | + if (secretlight_result.SECRTLGT[0].head[1].RESULT.CODE == 'INFO-000') { | ||
| 197 | + secretlightnum = secretlight_result.SECRTLGT[0].head[0].list_total_count; | ||
| 198 | + console.log(secretlightnum + "개의 보안등이 존재합니다."); | ||
| 199 | + } | ||
| 200 | + else { | ||
| 201 | + console.log("주변에 보안등이 없습니다."); | ||
| 202 | + } | ||
| 203 | + } | ||
| 204 | + }) | ||
| 205 | + | ||
| 206 | + let SafeBellOptions = { | ||
| 207 | + url: "https://openapi.gg.go.kr/Safeemrgncbell?Type=json&SIGUN_CD=" + SGCD + "&Key=" + GyeongGi_apikey, | ||
| 208 | + | ||
| 209 | + } | ||
| 210 | + request(SafeBellOptions, function (err, res, body) { | ||
| 211 | + if (!err && res.statusCode == 200) { | ||
| 212 | + safebell_result = JSON.parse(body); | ||
| 213 | + | ||
| 214 | + if (safebell_result.Safeemrgncbell[0].head[1].RESULT.CODE == 'INFO-000') { | ||
| 215 | + safebellnum = safebell_result.Safeemrgncbell[0].head[0].list_total_count; | ||
| 216 | + console.log(safebellnum + "개의 안전 비상벨이 존재합니다."); | ||
| 217 | + } | ||
| 218 | + else { | ||
| 219 | + | ||
| 220 | + console.log("주변에 안전 비상벨이 없습니다."); | ||
| 221 | + } | ||
| 222 | + } | ||
| 223 | + }) | ||
| 224 | + | ||
| 225 | + let CCTVOptions = { | ||
| 226 | + url: url = "https://openapi.gg.go.kr/CCTV?Type=json&SIGUN_CD=" + SGCD + "&Key=" + GyeongGi_apikey, | ||
| 227 | + } | ||
| 228 | + request(CCTVOptions, function (err, res, body) { | ||
| 229 | + if (!err && res.statusCode == 200) { | ||
| 230 | + cctv_result = JSON.parse(body); | ||
| 231 | + if (cctv_result.CCTV[0].head[1].RESULT.CODE == 'INFO-000') { | ||
| 232 | + cctvnum = cctv_result.CCTV[0].head[0].list_total_count; | ||
| 233 | + console.log(cctvnum + "개의 CCTV가 존재합니다."); | ||
| 234 | + } | ||
| 235 | + else { | ||
| 236 | + | ||
| 237 | + console.log("주변에 CCTV가 없습니다."); | ||
| 238 | + } | ||
| 239 | + } | ||
| 240 | + }) | ||
| 241 | + callback(function () { | ||
| 242 | + total_safe = safebellnum + secretlightnum + cctvnum; | ||
| 243 | + }) | ||
| 244 | + | ||
| 55 | res.send('This is safe'); | 245 | res.send('This is safe'); |
| 56 | }); | 246 | }); |
| 57 | 247 | ||
| 58 | -router.get('/culture', function(req, res) { | 248 | + |
| 249 | +router.get('/culture', function (req, res) { | ||
| 59 | res.send('This is culture'); | 250 | res.send('This is culture'); |
| 60 | }); | 251 | }); |
| 61 | 252 | ... | ... |
-
Please register or login to post a comment