Showing
1 changed file
with
0 additions
and
33 deletions
app.js
deleted
100644 → 0
1 | -var express = require('express'); | ||
2 | -var xml2js = require('xml-js'); | ||
3 | -var urlencode = require('urlencode'); | ||
4 | -const request = require('request'); | ||
5 | -const Dust_URL = "http://openapi.seoul.go.kr:8088/" //미세먼지 api주소 | ||
6 | -const Dust_URL2 = "/xml/DailyAverageAirQuality/" //미세먼지 api주소2 | ||
7 | -const Dust_ServiceKey = "6b665775706a696d38396245624461" //Dust url의 key값 | ||
8 | -const Dust_Days = "1/5/20190520/" //미세먼지 날짜 | ||
9 | -const Dust_Place =urlencode("강남구") //측정한 장소 | ||
10 | -const app = express(); | ||
11 | -const port = 23023; | ||
12 | - | ||
13 | - | ||
14 | -const url = Dust_URL+Dust_ServiceKey+Dust_URL2+Dust_Days+Dust_Place; | ||
15 | - | ||
16 | -request(url,function(error,res,body) { | ||
17 | - if(error){ | ||
18 | - console.log('error=>${error}'); | ||
19 | - } | ||
20 | - else{ | ||
21 | - if(res.statusCode == 200) { | ||
22 | - var result = body; | ||
23 | - //console.log(`body data => ${result}`); | ||
24 | - var xmlToJson = xml2js.xml2json(result, {compact: true, spaces: 4}); | ||
25 | - //console.log(`xml to json => ${xmlToJson}`); | ||
26 | - //console.log(typeof(JSON.parse(xmlToJson))); | ||
27 | - xmlToJson2 = JSON.parse(xmlToJson); | ||
28 | - console.log("측정 날짜:",xmlToJson2["DailyAverageAirQuality"]["row"]["MSRDT_DE"]["_text"]); | ||
29 | - console.log("측정 장소:",xmlToJson2["DailyAverageAirQuality"]["row"]["MSRSTE_NM"]["_text"]); | ||
30 | - console.log("미세먼지 농도:", xmlToJson2["DailyAverageAirQuality"]["row"]["PM10"]["_text"]); | ||
31 | - } | ||
32 | - } | ||
33 | -}); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment