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-21 23:02:55 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
9fe7d2eebc1af08ce2f06682b4ae7934eceec3f6
9fe7d2ee
1 parent
13da6d07
코드 폴더
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
206 additions
and
0 deletions
router/main.js
router/main.js
0 → 100644
View file @
9fe7d2e
// api에서 데이터 불러오기
var
xml2js
=
require
(
'xml-js'
);
var
urlencode
=
require
(
'urlencode'
);
var
xmlToJson
;
//var Dust_Month=0;
var
Feb_Dust_2018
=
0
;
var
Mar_Dust_2018
=
0
;
var
April_Dust_2018
=
0
;
var
May_Dust_2018
=
0
;
var
June_Dust_2018
=
0
;
var
Feb_Dust_2019
=
0
;
var
Mar_Dust_2019
=
0
;
var
April_Dust_2019
=
0
;
var
May_Dust_2019
=
0
;
var
June_Dust_2019
=
0
;
var
Feb_Dust_2020
=
0
;
var
Mar_Dust_2020
=
0
;
var
April_Dust_2020
=
0
;
var
May_Dust_2020
=
0
;
var
June_Dust_2020
=
0
;
const
request
=
require
(
'request'
);
var
url
;
const
Dust_URL
=
"http://openAPI.seoul.go.kr:8088/"
//미세먼지 api주소_1
const
Dust_URL2
=
"/xml/MonthlyAverageAirQuality/1/5/"
//미세먼지 api주소_2
const
Dust_ServiceKey
=
"73754a53586a696d38345951716b6b"
//Dust url의 key값
const
Dust_Place
=
'/'
+
urlencode
(
"강남구"
)
//측정한 장소
//2020년 2월~6월 미세먼지 평균
function
DelayNode_2020
(
item
)
{
return
new
Promise
(
function
(
resolve
,
reject
){
setTimeout
(
function
(){
url
=
Dust_URL
+
Dust_ServiceKey
+
Dust_URL2
+
item
+
Dust_Place
;
request
(
url
,
function
(
error
,
res
,
body
)
{
if
(
error
){
console
.
log
(
'error=>${error}'
);
}
else
{
if
(
res
.
statusCode
==
200
)
{
var
result
=
body
;
xmlToJson
=
xml2js
.
xml2json
(
result
,
{
compact
:
true
,
spaces
:
4
});
xmlToJson2
=
JSON
.
parse
(
xmlToJson
);
if
(
item
==
202002
){
console
.
log
(
"2미세먼지 농도:"
,
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
]);
Feb_Dust_2020
=
parseInt
(
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
])
}
else
if
(
item
==
202003
){
console
.
log
(
"3미세먼지 농도:"
,
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
]);
Mar_Dust_2020
=
parseInt
(
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
])
}
else
if
(
item
==
202004
){
console
.
log
(
"4미세먼지 농도:"
,
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
]);
April_Dust_2020
=
parseInt
(
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
])
}
else
if
(
item
==
202005
){
console
.
log
(
"5미세먼지 농도:"
,
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
]);
May_Dust_2020
=
parseInt
(
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
])
}
else
if
(
item
==
202006
){
console
.
log
(
"6미세먼지 농도:"
,
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
]);
June_Dust_2020
=
parseInt
(
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
])
}
}
}
});
resolve
();
},
500
)
})
}
async
function
Dust_Month_2020
(
Dust_Month_2020
){
for
(
let
i
=
0
;
i
<
Dust_Month_2020
.
length
;
i
++
)
{
await
DelayNode_2020
(
Dust_Month_2020
[
i
]);
}
}
Dust_Month_2020
([
202002
,
202003
,
202004
,
202005
,
202006
]);
//2019년 2월~6월 미세먼지 평균
function
DelayNode_2019
(
item
)
{
return
new
Promise
(
function
(
resolve
,
reject
){
setTimeout
(
function
(){
url
=
Dust_URL
+
Dust_ServiceKey
+
Dust_URL2
+
item
+
Dust_Place
;
request
(
url
,
function
(
error
,
res
,
body
)
{
if
(
error
){
console
.
log
(
'error=>${error}'
);
}
else
{
if
(
res
.
statusCode
==
200
)
{
var
result
=
body
;
xmlToJson
=
xml2js
.
xml2json
(
result
,
{
compact
:
true
,
spaces
:
4
});
xmlToJson2
=
JSON
.
parse
(
xmlToJson
);
if
(
item
==
201902
){
console
.
log
(
"2미세먼지 농도:"
,
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
]);
Feb_Dust_2019
=
parseInt
(
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
])
}
else
if
(
item
==
201903
){
console
.
log
(
"3미세먼지 농도:"
,
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
]);
Mar_Dust_2019
=
parseInt
(
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
])
}
else
if
(
item
==
201904
){
console
.
log
(
"4미세먼지 농도:"
,
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
]);
April_Dust_2019
=
parseInt
(
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
])
}
else
if
(
item
==
201905
){
console
.
log
(
"5미세먼지 농도:"
,
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
]);
May_Dust_2019
=
parseInt
(
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
])
}
else
if
(
item
==
201906
){
console
.
log
(
"6미세먼지 농도:"
,
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
]);
June_Dust_2019
=
parseInt
(
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
])
}
}
}
});
resolve
();
},
500
)
})
}
async
function
Dust_Month_2019
(
Dust_Month_2019
){
for
(
let
i
=
0
;
i
<
Dust_Month_2019
.
length
;
i
++
)
{
await
DelayNode_2019
(
Dust_Month_2019
[
i
]);
}
}
Dust_Month_2019
([
201902
,
201903
,
201904
,
201905
,
201906
]);
//2018년 2월~6월 미세먼지 평균
function
DelayNode_2018
(
item
)
{
return
new
Promise
(
function
(
resolve
,
reject
){
setTimeout
(
function
(){
url
=
Dust_URL
+
Dust_ServiceKey
+
Dust_URL2
+
item
+
Dust_Place
;
request
(
url
,
function
(
error
,
res
,
body
)
{
if
(
error
){
console
.
log
(
'error=>${error}'
);
}
else
{
if
(
res
.
statusCode
==
200
)
{
var
result
=
body
;
xmlToJson
=
xml2js
.
xml2json
(
result
,
{
compact
:
true
,
spaces
:
4
});
xmlToJson2
=
JSON
.
parse
(
xmlToJson
);
if
(
item
==
201802
){
console
.
log
(
"2미세먼지 농도:"
,
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
]);
Feb_Dust_2018
=
parseInt
(
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
])
}
else
if
(
item
==
201803
){
console
.
log
(
"3미세먼지 농도:"
,
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
]);
Mar_Dust_2018
=
parseInt
(
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
])
}
else
if
(
item
==
201804
){
console
.
log
(
"4미세먼지 농도:"
,
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
]);
April_Dust_2018
=
parseInt
(
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
])
}
else
if
(
item
==
201805
){
console
.
log
(
"5미세먼지 농도:"
,
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
]);
May_Dust_2018
=
parseInt
(
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
])
}
else
if
(
item
==
201806
){
console
.
log
(
"6미세먼지 농도:"
,
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
]);
June_Dust_2018
=
parseInt
(
xmlToJson2
[
"MonthlyAverageAirQuality"
][
"row"
][
"PM10"
][
"_text"
])
}
}
}
});
resolve
();
},
500
)
})
}
async
function
Dust_Month_2018
(
Dust_Month_2018
){
for
(
let
i
=
0
;
i
<
Dust_Month_2018
.
length
;
i
++
)
{
await
DelayNode_2018
(
Dust_Month_2018
[
i
]);
}
}
Dust_Month_2018
([
201802
,
201803
,
201804
,
201805
,
201806
]);
module
.
exports
=
function
(
app
)
{
app
.
get
(
'/'
,
function
(
req
,
res
){
res
.
render
(
'index'
,{
Feb_Dust_2018
,
Mar_Dust_2018
,
April_Dust_2018
,
May_Dust_2018
,
June_Dust_2018
,
Feb_Dust_2019
,
Mar_Dust_2019
,
April_Dust_2019
,
May_Dust_2019
,
June_Dust_2019
,
Feb_Dust_2020
,
Mar_Dust_2020
,
April_Dust_2020
,
May_Dust_2020
,
June_Dust_2020
})
});
app
.
get
(
'/about'
,
function
(
req
,
res
){
res
.
render
(
'about.ejs'
);
});
}
\ No newline at end of file
Please
register
or
login
to post a comment