jimin

app.js upload

Showing 1 changed file with 33 additions and 0 deletions
var express = require('express');
var xml2js = require('xml-js');
var urlencode = require('urlencode');
const request = require('request');
const Dust_URL = "http://openapi.seoul.go.kr:8088/" //미세먼지 api주소
const Dust_URL2 = "/xml/DailyAverageAirQuality/" //미세먼지 api주소2
const Dust_ServiceKey = "6b665775706a696d38396245624461" //Dust url의 key값
const Dust_Days = "1/5/20190520/" //미세먼지 날짜
const Dust_Place =urlencode("강남구") //측정한 장소
const app = express();
const port = 23023;
const url = Dust_URL+Dust_ServiceKey+Dust_URL2+Dust_Days+Dust_Place;
request(url,function(error,res,body) {
if(error){
console.log('error=>${error}');
}
else{
if(res.statusCode == 200) {
var result = body;
//console.log(`body data => ${result}`);
var xmlToJson = xml2js.xml2json(result, {compact: true, spaces: 4});
//console.log(`xml to json => ${xmlToJson}`);
//console.log(typeof(JSON.parse(xmlToJson)));
xmlToJson2 = JSON.parse(xmlToJson);
console.log("측정 날짜:",xmlToJson2["DailyAverageAirQuality"]["row"]["MSRDT_DE"]["_text"]);
console.log("측정 장소:",xmlToJson2["DailyAverageAirQuality"]["row"]["MSRSTE_NM"]["_text"]);
console.log("미세먼지 농도:", xmlToJson2["DailyAverageAirQuality"]["row"]["PM10"]["_text"]);
}
}
});
\ No newline at end of file