안지영

Add API code

...@@ -3,14 +3,17 @@ ...@@ -3,14 +3,17 @@
3 "version": "0.0.0", 3 "version": "0.0.0",
4 "private": true, 4 "private": true,
5 "scripts": { 5 "scripts": {
6 - "start": "node ./bin/www" 6 + "start": "nodemon ./bin/www"
7 }, 7 },
8 "dependencies": { 8 "dependencies": {
9 + "axios": "^0.21.0",
9 "cookie-parser": "~1.4.4", 10 "cookie-parser": "~1.4.4",
10 "debug": "~2.6.9", 11 "debug": "~2.6.9",
11 "express": "~4.16.1", 12 "express": "~4.16.1",
12 "http-errors": "~1.6.3", 13 "http-errors": "~1.6.3",
13 "morgan": "~1.9.1", 14 "morgan": "~1.9.1",
14 - "pug": "2.0.0-beta11" 15 + "nodemon": "^2.0.6",
16 + "pug": "2.0.0-beta11",
17 + "xmlhttprequest": "^1.8.0"
15 } 18 }
16 } 19 }
......
1 +const { urlencoded } = require('express');
1 var express = require('express'); 2 var express = require('express');
2 var router = express.Router(); 3 var router = express.Router();
4 +//import axios from 'axios';
3 5
4 /* GET home page. */ 6 /* GET home page. */
5 router.get('/', function(req, res, next) { 7 router.get('/', function(req, res, next) {
6 - res.render('index', { title: 'Express' }); 8 +
9 +
7 }); 10 });
8 11
12 +function BusStationCnt(){ //역세권-주변 버스정류장 현황
13 + var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
14 + var x= 37.25125448694078;
15 + var y= 127.07860104740388;
16 + var xhr = new XMLHttpRequest();
17 + var BusCnt=0;
18 + var apikey="1dmQfgdmhdVNnYsjXBxosTpLV8RdlRmk7h%2BtV6p7Qqs";
19 +
20 + var url="https://api.odsay.com/v1/api/pointSearch?lang=0&x=127.07860104740388&y=37.25125448694078&radius=500&stationClass=1"+"&apiKey="+apikey;
21 + xhr.open("GET", url, true);
22 + xhr.send();
23 + xhr.onreadystatechange = function() {
24 + if (xhr.readyState == 4 && xhr.status == 200) {
25 + result=JSON.parse(xhr.responseText);
26 + //console.log(result.result);
27 + console.log("버스정류장 개수:"+result.result.count);
28 + BusCnt=result.result.count;
29 + }
30 + }
31 + return BusCnt;
32 +
33 +}
34 +BusStationCnt();
35 +
36 +function SubwayStationCnt(){ //역세권-주변 지하철역 현황
37 + var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
38 + var x= 37.25125448694078;
39 + var y= 127.07860104740388;
40 + var xhr = new XMLHttpRequest();
41 + var SubwayCnt=0;
42 + var apikey="1dmQfgdmhdVNnYsjXBxosTpLV8RdlRmk7h%2BtV6p7Qqs";
43 + var url="https://api.odsay.com/v1/api/pointSearch?lang=0&x=127.07860104740388&y=37.25125448694078&radius=1000&stationClass=2"+"&apiKey="+apikey;
44 + xhr.open("GET", url, true);
45 + xhr.send();
46 + xhr.onreadystatechange = function() {
47 + if (xhr.readyState == 4 && xhr.status == 200) {
48 + result=JSON.parse(xhr.responseText);
49 + //console.log(result.result);
50 + console.log("지하철역 개수:"+result.result.count);
51 + SubwayCnt=result.result.count;
52 + }
53 + }
54 + return SubwayCnt;
55 +
56 +}
57 +SubwayStationCnt();
58 +
59 +TransportStationCnt= async function(){
60 + var buscnt=await BusStationCnt();
61 + var subwaycnt=await SubwayStationCnt();
62 +
63 + console.log("전체");
64 +}
65 +TransportStationCnt();
66 +
67 +function AcademyCnt(SGCD){//학세권-주변 학원 현황
68 +
69 + var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
70 + var xhr = new XMLHttpRequest();
71 + var academynum=0;
72 + var apikey="69c8644acb67449193803dab1972ff46";
73 + var url="https://openapi.gg.go.kr/TninsttInstutM?Type=json&SIGUN_CD="+SGCD+"&Key="+apikey;
74 + xhr.open("GET", url, true);
75 + xhr.send();
76 + xhr.onreadystatechange = function() {
77 + if (xhr.readyState == 4 && xhr.status == 200) {
78 + result=JSON.parse(xhr.responseText);
79 +
80 + if(result.TninsttInstutM[0].head[1].RESULT.CODE=='INFO-000'){
81 + academynum=result.TninsttInstutM[0].head[0].list_total_count;
82 + console.log(academynum+"개의 학원이 존재합니다.");
83 + }
84 + else{
85 +
86 + "학원이 존재하지 않습니다.";
87 + }
88 + }
89 + }
90 + return academynum;
91 +}
92 +AcademyCnt(41110);
93 +
94 +function LibraryCnt(SGCD){ //학세권-주변 도서관 현황
95 + var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
96 + var xhr = new XMLHttpRequest();
97 + var librarynum=0;
98 + var apikey="69c8644acb67449193803dab1972ff46";
99 + var url="https://openapi.gg.go.kr/Tbggibllbrm?Type=json&SIGUN_CD="+SGCD+"&Key="+apikey;
100 + xhr.open("GET", url, true);
101 + xhr.send();
102 + xhr.onreadystatechange = function() {
103 + if (xhr.readyState == 4 && xhr.status == 200) {
104 + result=JSON.parse(xhr.responseText);
105 + //console.log(result.Tbggibllbrm[0].head[0].list_total_count);
106 + result=result.Tbggibllbrm[0];
107 + if(result.head[1].RESULT.CODE=='INFO-000'){
108 + librarynum=result.head[0].list_total_count;
109 + console.log(librarynum+"개의 도서관이 존재합니다.");
110 + }
111 + else{
112 +
113 + "도서관이 존재하지 않습니다.";
114 + }
115 + }
116 + }
117 + return librarynum;
118 +}
119 +LibraryCnt(41110)
120 +
121 +function MallCount(SGCD){ //주변 쇼핑몰 현황
122 +
123 + var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
124 + var xhr = new XMLHttpRequest();
125 + var mallnum=0;
126 + var apikey="69c8644acb67449193803dab1972ff46";
127 + var url="https://openapi.gg.go.kr/MrktStoreM?Type=json&SIGUN_CD="+SGCD+"&Key="+apikey;
128 + xhr.open("GET", url, true);
129 + xhr.send();
130 + xhr.onreadystatechange = function() {
131 + if (xhr.readyState == 4 && xhr.status == 200) {
132 + result=JSON.parse(xhr.responseText);
133 + //console.log(result.MrktStoreM[0].head[1].RESULT.CODE);
134 + if(result.MrktStoreM[0].head[1].RESULT.CODE=='INFO-000'){
135 + mallnum=result.MrktStoreM[0].head[0].list_total_count;
136 + console.log(mallnum+"개의 쇼핑몰이 존재합니다.");
137 + }
138 + else{
139 +
140 + console.log("주변에 쇼핑몰이 없습니다.");
141 + }
142 + }
143 + }
144 + return mallnum;
145 +}
146 +MallCount(41110);
147 +
148 +function CityParkCount(SGCD){
149 +
150 + var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
151 + var xhr = new XMLHttpRequest();
152 + var cityparknum=0;
153 + var apikey="69c8644acb67449193803dab1972ff46";
154 + var url="https://openapi.gg.go.kr/CityPark?Type=json&SIGUN_CD="+SGCD+"&Key="+apikey;
155 + xhr.open("GET", url, true);
156 + xhr.send();
157 + xhr.onreadystatechange = function() {
158 + if (xhr.readyState == 4 && xhr.status == 200) {
159 + result=JSON.parse(xhr.responseText);
160 + // console.log(result.CityPark[0].head[0].list_total_count);
161 + if(result.CityPark[0].head[1].RESULT.CODE=='INFO-000'){
162 + cityparknum=result.CityPark[0].head[0].list_total_count;
163 + console.log(cityparknum+"개의 도시공원이 존재합니다.");
164 + }
165 + else{
166 +
167 + console.log("주변에 도시공원이 없습니다.");
168 + }
169 + }
170 + }
171 + return cityparknum;
172 +}
173 +CityParkCount(41110);
174 +
175 +
176 +function SafeBellCount(SGCD){ //안세권-안전 비상벨
177 + var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
178 + var xhr = new XMLHttpRequest();
179 + var safebellnum=0;
180 + var apikey="69c8644acb67449193803dab1972ff46";
181 + var url="https://openapi.gg.go.kr/Safeemrgncbell?Type=json&SIGUN_CD="+SGCD+"&Key="+apikey;
182 + xhr.open("GET", url, true);
183 + xhr.send();
184 + xhr.onreadystatechange = function() {
185 + if (xhr.readyState == 4 && xhr.status == 200) {
186 + result=JSON.parse(xhr.responseText);
187 +
188 + if(result.Safeemrgncbell[0].head[1].RESULT.CODE=='INFO-000'){
189 + safebellnum=result.Safeemrgncbell[0].head[0].list_total_count;
190 + console.log(safebellnum+"개의 안전 비상벨이 존재합니다.");
191 + }
192 + else{
193 +
194 + console.log("주변에 안전 비상벨이 없습니다.");
195 + }
196 + }
197 + }
198 + return safebellnum;
199 +}
200 +SafeBellCount(41110);
201 +
202 +function SecreLightCount(SGCD){
203 + var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
204 + var xhr = new XMLHttpRequest();
205 + var secretlightnum=0;
206 + var apikey="69c8644acb67449193803dab1972ff46";
207 + var url="https://openapi.gg.go.kr/SECRTLGT?Type=json&SIGUN_CD="+SGCD+"&Key="+apikey;
208 + xhr.open("GET", url, true);
209 + xhr.send();
210 + xhr.onreadystatechange = function() {
211 + if (xhr.readyState == 4 && xhr.status == 200) {
212 + result=JSON.parse(xhr.responseText);
213 +
214 +
215 + if(result.SECRTLGT[0].head[1].RESULT.CODE=='INFO-000'){
216 + secretlightnum=result.SECRTLGT[0].head[0].list_total_count;
217 + console.log(secretlightnum+"개의 보안등이 존재합니다.");
218 + }
219 + else{
220 +
221 + console.log("주변에 보안등이 없습니다.");
222 + }
223 + }
224 + }
225 + return secretlightnum;
226 +}
227 +SecreLightCount(41110);
228 +
229 +function CCTVCount(SGCD){
230 +
231 + var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
232 + var xhr = new XMLHttpRequest();
233 + var cctvnum=0;
234 + var apikey="69c8644acb67449193803dab1972ff46";
235 + var url="https://openapi.gg.go.kr/CCTV?Type=json&SIGUN_CD="+SGCD+"&Key="+apikey;
236 + xhr.open("GET", url, true);
237 + xhr.send();
238 + xhr.onreadystatechange = function() {
239 + if (xhr.readyState == 4 && xhr.status == 200) {
240 + result=JSON.parse(xhr.responseText);
241 + if(result.CCTV[0].head[1].RESULT.CODE=='INFO-000'){
242 + cctvnum=result.CCTV[0].head[0].list_total_count;
243 + console.log(cctvnum+"개의 CCTV가 존재합니다.");
244 + }
245 + else{
246 +
247 + console.log("주변에 CCTV가 없습니다.");
248 + }
249 + }
250 + }
251 + return cctvnum;
252 +}
253 +CCTVCount(41110);
254 +
255 +function GymCount(SGCD){ //근세권-주변 체육관 현황
256 +
257 + var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
258 + var xhr = new XMLHttpRequest();
259 + var gymnum=0;
260 + var apikey="69c8644acb67449193803dab1972ff46";
261 + var url="https://openapi.gg.go.kr/PhysicaFitnessTrainingPlace?Type=json&SIGUN_CD="+SGCD+"&Key="+apikey;
262 + xhr.open("GET", url, true);
263 + xhr.send();
264 + xhr.onreadystatechange = function() {
265 + if (xhr.readyState == 4 && xhr.status == 200) {
266 + result=JSON.parse(xhr.responseText);
267 + //console.log(result);
268 + if(result.PhysicaFitnessTrainingPlace[0].head[1].RESULT.CODE=='INFO-000'){
269 +
270 + gymnum=result.PhysicaFitnessTrainingPlace[0].head[0].list_total_count;
271 + console.log(gymnum+"개의 체육관이 존재합니다.");
272 + }
273 + else{
274 +
275 + console.log("주변에 체육관이 없습니다.");
276 + }
277 + }
278 + }
279 + return gymnum;
280 +
281 +}
282 +GymCount(41110);
283 +
9 module.exports = router; 284 module.exports = router;
285 +
......