Toggle navigation
Toggle navigation
This project
Loading...
Sign in
teamPARK
/
holiday-counter-recommend-activity
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
박지환
2022-05-09 11:00:21 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e794b3b9cfcaf70d49c3fe47045a6ca24e079c56
e794b3b9
1 parent
28a26263
Add comments
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
9 deletions
server.js
server.js
View file @
e794b3b
...
...
@@ -5,20 +5,24 @@ const convert = require("xml-js");
const
fs
=
require
(
"fs"
);
const
xml2js
=
require
(
"xml2js"
);
// http://apis.data.go.kr/B090041/openapi/service/SpcdeInfoService/getHoliDeInfo?solYear=2019&solMonth=03&ServiceKey=서비스키
// Modify the values as needed
var
year
=
"2022"
;
var
month
=
"09"
;
var
operation
=
"getHoliDeInfo"
;
// Do not modify the values
var
SERVEICE_KEY
=
"qBtJy2Prw8CCnAiijUM7VkuaA9MZozHuiQI4FbEGYdUDPz4%2FM%2FuxegGjNBWK0aWQHvSslVHwIZQwNWh57WgRTA%3D%3D"
;
var
operation
=
"getHoliDeInfo"
;
var
url
=
"http://apis.data.go.kr/B090041/openapi/service/SpcdeInfoService/"
+
operation
;
var
queryParams
=
"?"
+
"solYear"
+
"="
+
"2022"
;
queryParams
+=
"&"
+
"solMonth"
+
"="
+
"09"
;
var
queryParams
=
"?"
+
"solYear"
+
"="
+
year
;
queryParams
+=
"&"
+
"solMonth"
+
"="
+
month
;
queryParams
+=
"&"
+
"ServiceKey"
+
"="
+
SERVEICE_KEY
;
let
requestUrl
=
url
+
queryParams
;
// Empty variables
var
text
=
""
;
var
text2
=
""
;
var
dateName
=
[];
var
locdate
=
[];
var
tempArr
=
[];
...
...
@@ -33,17 +37,19 @@ app.get("/", function (req, res) {
console
.
log
(
"err => "
+
err
);
}
else
{
if
(
res
.
statusCode
==
200
)
{
// Read url success
var
result
=
body
;
var
xmlToJson
=
convert
.
xml2json
(
result
,
{
compact
:
true
,
spaces
:
4
});
console
.
log
(
result
);
console
.
log
(
xmlToJson
);
fs
.
writeFileSync
(
"holi.
json"
,
xmlToJson
);
fs
.
writeFileSync
(
"holi.
xml"
,
result
);
fs
.
writeFileSync
(
"holi.
xml"
,
result
);
// Create/Modify holi.xml
fs
.
writeFileSync
(
"holi.
json"
,
xmlToJson
);
// Create/Modify holi.json
var
parser
=
new
xml2js
.
Parser
();
parser
.
parseString
(
result
,
function
(
err
,
res
)
{
console
.
log
(
res
);
text
=
JSON
.
stringify
(
res
);
console
.
log
(
text
);
// Get dataName method
dateName
=
[];
var
idx
=
text
.
indexOf
(
"dateName"
,
0
);
while
(
idx
!=
-
1
)
{
...
...
@@ -56,6 +62,7 @@ app.get("/", function (req, res) {
idx
=
text
.
indexOf
(
"dateName"
,
idx
+
1
);
}
console
.
log
(
dateName
);
// Get locdate method
locdate
=
[];
idx
=
text
.
indexOf
(
"locdate"
,
0
);
while
(
idx
!=
-
1
)
{
...
...
@@ -68,7 +75,7 @@ app.get("/", function (req, res) {
idx
=
text
.
indexOf
(
"locdate"
,
idx
+
1
);
}
console
.
log
(
locdate
);
text2
=
dateName
.
toString
()
+
"&"
+
locdate
.
toString
();
// Create tempArr to save dateName and locdate at once
tempArr
=
[];
tempArr
.
push
(
dateName
);
tempArr
.
push
(
locdate
);
...
...
@@ -77,12 +84,14 @@ app.get("/", function (req, res) {
}
}
});
// Send data from nodejs to ejs
res
.
render
(
"data.ejs"
,
{
data
:
tempArr
},
function
(
err
,
html
)
{
if
(
err
)
{
console
.
log
(
err
);
}
res
.
end
(
html
);
//
응답 종료
res
.
end
(
html
);
//
End response
});
// send data.ejs
res
.
sendFile
(
__dirname
+
"/views/data.ejs"
);
});
...
...
Please
register
or
login
to post a comment