Toggle navigation
Toggle navigation
This project
Loading...
Sign in
임채언
/
OSS-chatbot-11
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
EC2 Default User
2022-11-26 22:11:14 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
85786f7a3f3018634fd943dd1d374ba69fac7afc
85786f7a
1 parent
33d5a3cc
feat: Implement bus arrival information output
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
15 deletions
app.js
src/bus/request.js
src/bus/routeidmap.js
app.js
View file @
85786f7
var
express
=
require
(
'express'
);
require
(
"dotenv"
).
config
();
var
url
=
'http://apis.data.go.kr/6410000/busarrivalservice/getBusArrivalList'
;
var
queryParams
=
'?'
+
encodeURIComponent
(
'serviceKey'
)
+
'Y6FZX1ZGniy+sKjl3AYf+bnh719O0mTDXOdJEODTJ4x1hgFVU60TCHS8Cj//pUtXTkEBp6k2RQ7GGuTqNeAiyA=='
;
/* Service Key*/
queryParams
+=
'&'
+
encodeURIComponent
(
'stationId'
)
+
'='
+
encodeURIComponent
(
'200000078'
);
/* */
const
fs
=
require
(
'fs'
);
const
path
=
require
(
'path'
);
...
...
src/bus/request.js
View file @
85786f7
var
request
=
require
(
'request'
);
const
convert
=
require
(
"xml-js"
)
const
convert
=
require
(
"xml-js"
);
const
{
routeIdToBusNum
}
=
require
(
"./routeidmap"
);
var
url
=
'http://apis.data.go.kr/6410000/busarrivalservice/getBusArrivalList'
;
var
queryParams
=
'?'
+
encodeURIComponent
(
'serviceKey'
)
+
process
.
env
.
SERVICE_KEY
;
/* Service Key*/
...
...
@@ -11,11 +12,27 @@ function callRequest() {
url
:
url
+
queryParams
,
method
:
'GET'
},
function
(
error
,
response
,
body
)
{
const
data
=
convert
.
xml2js
(
body
,
{
compact
:
true
}).
response
.
msgBody
if
(
data
)
resolve
(
JSON
.
stringify
(
data
.
busArrivalList
[
1
]));
else
resolve
(
"운행 중인 버스가 없습니다."
);
const
data
=
convert
.
xml2js
(
body
,
{
compact
:
true
}).
response
.
msgBody
.
busArrivalList
if
(
!
data
)
resolve
(
"운행 중인 버스가 없습니다."
);
let
result
=
""
;
for
(
let
i
in
data
)
{
result
+=
`
${
routeIdToBusNum
[
data
[
i
].
routeId
.
_text
]}
번 버스 도착 정보입니다\n`
;
result
+=
`첫 번째 도착:
${
data
[
i
].
predictTime1
.
_text
}
\n두 번째 도착:
${
data
[
i
].
predictTime2
.
_text
}
\n\n`
;
}
resolve
(
result
.
substring
(
0
,
result
.
length
-
2
));
// const data1 = convert.xml2js(body, { compact: true }).response.msgBody.busArrivalList[0].predictTime1._text
// const data2 = convert.xml2js(body, { compact: true }).response.msgBody.busArrivalList[0].predictTime2._text
// if (data1)
// {
// //resolve(JSON.stringify(data.busArrivalList[0]));
// console.log("첫 번째: " + data1)
// resolve("첫 번째: " + data1 + "\n두 번째: "+data2);
// //resolve(JSON.stringify(data));
// }
// else
// resolve("운행 중인 버스가 없습니다.");
});
})
}
...
...
src/bus/routeidmap.js
View file @
85786f7
module
.
exports
=
{
200000115
:
"5100"
,
200000103
:
"9"
,
234000016
:
"1112"
,
234000001
:
"5500_1"
,
200000112
:
"7000"
,
234001243
:
"5107"
,
routeIdToBusNum
:
{
200000115
:
"5100"
,
200000103
:
"9"
,
234000016
:
"1112"
,
200000112
:
"7000"
,
234000001
:
"5500_1"
,
234001243
:
"5107"
,
},
busNumToRouteId
:
{
"5100"
:
200000115
,
"9"
:
200000103
,
"1112"
:
234000016
,
"7000"
:
200000112
,
"5500_1"
:
234000001
,
"5107"
:
234001243
,
}
}
\ No newline at end of file
...
...
Please
register
or
login
to post a comment