Toggle navigation
Toggle navigation
This project
Loading...
Sign in
황지민
/
Corona_Dust
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
jimin
2020-06-03 20:21:45 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
55e1d3a8ce6459ca6a135c36633b668ada6da3ea
55e1d3a8
0 parents
app.js upload
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
0 deletions
app.js
app.js
0 → 100644
View file @
55e1d3a
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
Please
register
or
login
to post a comment