안지영

Add API code

......@@ -3,14 +3,17 @@
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
"start": "nodemon ./bin/www"
},
"dependencies": {
"axios": "^0.21.0",
"cookie-parser": "~1.4.4",
"debug": "~2.6.9",
"express": "~4.16.1",
"http-errors": "~1.6.3",
"morgan": "~1.9.1",
"pug": "2.0.0-beta11"
"nodemon": "^2.0.6",
"pug": "2.0.0-beta11",
"xmlhttprequest": "^1.8.0"
}
}
......
const { urlencoded } = require('express');
var express = require('express');
var router = express.Router();
//import axios from 'axios';
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
function BusStationCnt(){ //역세권-주변 버스정류장 현황
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var x= 37.25125448694078;
var y= 127.07860104740388;
var xhr = new XMLHttpRequest();
var BusCnt=0;
var apikey="1dmQfgdmhdVNnYsjXBxosTpLV8RdlRmk7h%2BtV6p7Qqs";
var url="https://api.odsay.com/v1/api/pointSearch?lang=0&x=127.07860104740388&y=37.25125448694078&radius=500&stationClass=1"+"&apiKey="+apikey;
xhr.open("GET", url, true);
xhr.send();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
result=JSON.parse(xhr.responseText);
//console.log(result.result);
console.log("버스정류장 개수:"+result.result.count);
BusCnt=result.result.count;
}
}
return BusCnt;
}
BusStationCnt();
function SubwayStationCnt(){ //역세권-주변 지하철역 현황
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var x= 37.25125448694078;
var y= 127.07860104740388;
var xhr = new XMLHttpRequest();
var SubwayCnt=0;
var apikey="1dmQfgdmhdVNnYsjXBxosTpLV8RdlRmk7h%2BtV6p7Qqs";
var url="https://api.odsay.com/v1/api/pointSearch?lang=0&x=127.07860104740388&y=37.25125448694078&radius=1000&stationClass=2"+"&apiKey="+apikey;
xhr.open("GET", url, true);
xhr.send();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
result=JSON.parse(xhr.responseText);
//console.log(result.result);
console.log("지하철역 개수:"+result.result.count);
SubwayCnt=result.result.count;
}
}
return SubwayCnt;
}
SubwayStationCnt();
TransportStationCnt= async function(){
var buscnt=await BusStationCnt();
var subwaycnt=await SubwayStationCnt();
console.log("전체");
}
TransportStationCnt();
function AcademyCnt(SGCD){//학세권-주변 학원 현황
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var xhr = new XMLHttpRequest();
var academynum=0;
var apikey="69c8644acb67449193803dab1972ff46";
var url="https://openapi.gg.go.kr/TninsttInstutM?Type=json&SIGUN_CD="+SGCD+"&Key="+apikey;
xhr.open("GET", url, true);
xhr.send();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
result=JSON.parse(xhr.responseText);
if(result.TninsttInstutM[0].head[1].RESULT.CODE=='INFO-000'){
academynum=result.TninsttInstutM[0].head[0].list_total_count;
console.log(academynum+"개의 학원이 존재합니다.");
}
else{
"학원이 존재하지 않습니다.";
}
}
}
return academynum;
}
AcademyCnt(41110);
function LibraryCnt(SGCD){ //학세권-주변 도서관 현황
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var xhr = new XMLHttpRequest();
var librarynum=0;
var apikey="69c8644acb67449193803dab1972ff46";
var url="https://openapi.gg.go.kr/Tbggibllbrm?Type=json&SIGUN_CD="+SGCD+"&Key="+apikey;
xhr.open("GET", url, true);
xhr.send();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
result=JSON.parse(xhr.responseText);
//console.log(result.Tbggibllbrm[0].head[0].list_total_count);
result=result.Tbggibllbrm[0];
if(result.head[1].RESULT.CODE=='INFO-000'){
librarynum=result.head[0].list_total_count;
console.log(librarynum+"개의 도서관이 존재합니다.");
}
else{
"도서관이 존재하지 않습니다.";
}
}
}
return librarynum;
}
LibraryCnt(41110)
function MallCount(SGCD){ //주변 쇼핑몰 현황
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var xhr = new XMLHttpRequest();
var mallnum=0;
var apikey="69c8644acb67449193803dab1972ff46";
var url="https://openapi.gg.go.kr/MrktStoreM?Type=json&SIGUN_CD="+SGCD+"&Key="+apikey;
xhr.open("GET", url, true);
xhr.send();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
result=JSON.parse(xhr.responseText);
//console.log(result.MrktStoreM[0].head[1].RESULT.CODE);
if(result.MrktStoreM[0].head[1].RESULT.CODE=='INFO-000'){
mallnum=result.MrktStoreM[0].head[0].list_total_count;
console.log(mallnum+"개의 쇼핑몰이 존재합니다.");
}
else{
console.log("주변에 쇼핑몰이 없습니다.");
}
}
}
return mallnum;
}
MallCount(41110);
function CityParkCount(SGCD){
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var xhr = new XMLHttpRequest();
var cityparknum=0;
var apikey="69c8644acb67449193803dab1972ff46";
var url="https://openapi.gg.go.kr/CityPark?Type=json&SIGUN_CD="+SGCD+"&Key="+apikey;
xhr.open("GET", url, true);
xhr.send();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
result=JSON.parse(xhr.responseText);
// console.log(result.CityPark[0].head[0].list_total_count);
if(result.CityPark[0].head[1].RESULT.CODE=='INFO-000'){
cityparknum=result.CityPark[0].head[0].list_total_count;
console.log(cityparknum+"개의 도시공원이 존재합니다.");
}
else{
console.log("주변에 도시공원이 없습니다.");
}
}
}
return cityparknum;
}
CityParkCount(41110);
function SafeBellCount(SGCD){ //안세권-안전 비상벨
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var xhr = new XMLHttpRequest();
var safebellnum=0;
var apikey="69c8644acb67449193803dab1972ff46";
var url="https://openapi.gg.go.kr/Safeemrgncbell?Type=json&SIGUN_CD="+SGCD+"&Key="+apikey;
xhr.open("GET", url, true);
xhr.send();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
result=JSON.parse(xhr.responseText);
if(result.Safeemrgncbell[0].head[1].RESULT.CODE=='INFO-000'){
safebellnum=result.Safeemrgncbell[0].head[0].list_total_count;
console.log(safebellnum+"개의 안전 비상벨이 존재합니다.");
}
else{
console.log("주변에 안전 비상벨이 없습니다.");
}
}
}
return safebellnum;
}
SafeBellCount(41110);
function SecreLightCount(SGCD){
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var xhr = new XMLHttpRequest();
var secretlightnum=0;
var apikey="69c8644acb67449193803dab1972ff46";
var url="https://openapi.gg.go.kr/SECRTLGT?Type=json&SIGUN_CD="+SGCD+"&Key="+apikey;
xhr.open("GET", url, true);
xhr.send();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
result=JSON.parse(xhr.responseText);
if(result.SECRTLGT[0].head[1].RESULT.CODE=='INFO-000'){
secretlightnum=result.SECRTLGT[0].head[0].list_total_count;
console.log(secretlightnum+"개의 보안등이 존재합니다.");
}
else{
console.log("주변에 보안등이 없습니다.");
}
}
}
return secretlightnum;
}
SecreLightCount(41110);
function CCTVCount(SGCD){
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var xhr = new XMLHttpRequest();
var cctvnum=0;
var apikey="69c8644acb67449193803dab1972ff46";
var url="https://openapi.gg.go.kr/CCTV?Type=json&SIGUN_CD="+SGCD+"&Key="+apikey;
xhr.open("GET", url, true);
xhr.send();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
result=JSON.parse(xhr.responseText);
if(result.CCTV[0].head[1].RESULT.CODE=='INFO-000'){
cctvnum=result.CCTV[0].head[0].list_total_count;
console.log(cctvnum+"개의 CCTV가 존재합니다.");
}
else{
console.log("주변에 CCTV가 없습니다.");
}
}
}
return cctvnum;
}
CCTVCount(41110);
function GymCount(SGCD){ //근세권-주변 체육관 현황
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var xhr = new XMLHttpRequest();
var gymnum=0;
var apikey="69c8644acb67449193803dab1972ff46";
var url="https://openapi.gg.go.kr/PhysicaFitnessTrainingPlace?Type=json&SIGUN_CD="+SGCD+"&Key="+apikey;
xhr.open("GET", url, true);
xhr.send();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
result=JSON.parse(xhr.responseText);
//console.log(result);
if(result.PhysicaFitnessTrainingPlace[0].head[1].RESULT.CODE=='INFO-000'){
gymnum=result.PhysicaFitnessTrainingPlace[0].head[0].list_total_count;
console.log(gymnum+"개의 체육관이 존재합니다.");
}
else{
console.log("주변에 체육관이 없습니다.");
}
}
}
return gymnum;
}
GymCount(41110);
module.exports = router;
......