Toggle navigation
Toggle navigation
This project
Loading...
Sign in
홍용민
/
BusTime
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
홍용민
2021-05-27 01:37:59 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
81ffeed86e93e1be5fede1e748b4ea0124db0e44
81ffeed8
1 parent
010d585a
버스 도착 여부 확인
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
5 deletions
.gitignore
BusInfo.js
.gitignore
0 → 100644
View file @
81ffeed
test.js
BusInfo.txt
\ No newline at end of file
BusInfo.js
View file @
81ffeed
...
...
@@ -3,14 +3,15 @@ let cheerio = require('cheerio');
const
bus_url
=
'http://apis.data.go.kr/6410000/busarrivalservice/getBusArrivalList'
;
const
bus_key
=
'RwxSWXH88b2bKOAT6Ot3FHorPZQW9omma0xYIjtJe0JIKe4DC7TjX7Uj6E1ArzYi2AvVETmPrAIYyY8FlL%2BfAA%3D%3D'
;
const
stationID
=
'228000708'
;
const
stationID
=
'228000708'
;
// 사색의광장 들어오는 방향
const
gateStationID
=
'203000125'
const
BusArrivalUrl
=
bus_url
+
'?servicekey='
+
bus_key
+
'&stationId='
+
stationID
;
// 사색의광장 정류장 버스 도착 정보 조회용
console
.
log
(
BusArrivalUrl
);
const
_sleep
=
(
delay
)
=>
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
delay
));
var
routeID
=
[];
var
BusNum
=
[];
var
Bus
=
[];
// 버스 차 번호( ex) 경기 70바 3713 ) / 도착 여부 확인용
var
BusNum
=
[];
// 버스 번호 ( ex) 9)
request
(
BusArrivalUrl
,
(
err
,
res
,
body
)
=>
{
var
$
=
cheerio
.
load
(
body
,
{
decodeEntities
:
false
});
...
...
@@ -26,9 +27,9 @@ const route_key = 'RwxSWXH88b2bKOAT6Ot3FHorPZQW9omma0xYIjtJe0JIKe4DC7TjX7Uj6E1Ar
var
j
=
0
;
function
getBusNum
(){
let
BusRouteUrl
=
route_url
+
'?servicekey='
+
route_key
+
'&routeId='
;
let
BusRouteUrl
=
route_url
+
'?servicekey='
+
route_key
+
'&routeId='
;
// 각 버스 정보 조회용
BusRouteUrl
+=
routeID
[
j
++
];
console
.
log
(
BusRouteUrl
);
//
console.log(BusRouteUrl);
request
(
BusRouteUrl
,
(
err
,
res
,
body
)
=>
{
var
$
=
cheerio
.
load
(
body
,
{
decodeEntities
:
false
});
...
...
@@ -46,3 +47,33 @@ function useFor(){
}
}
setTimeout
(
useFor
,
500
);
const
GateBusUrl
=
bus_url
+
'?servicekey='
+
bus_key
+
'&stationId='
+
gateStationID
;
request
(
GateBusUrl
,
(
err
,
res
,
body
)
=>
{
var
$
=
cheerio
.
load
(
body
,
{
decodeEntities
:
false
});
$
(
'busArrivalList'
).
each
(
function
(
idx
){
let
route
=
$
(
this
).
find
(
'routeId'
).
text
();
let
num
=
$
(
this
).
find
(
'plateNo1'
).
text
();
var
index
=
routeID
.
indexOf
(
route
);
if
(
index
>
-
1
){
for
(
var
i
=
0
;
i
<
Bus
.
length
;
i
++
){
if
(
Bus
[
i
][
'route'
]
==
route
){
if
(
Bus
[
i
][
'num'
]
!=
num
){
Bus
[
i
][
'pass'
]
=
true
;
Bus
[
i
][
'num'
]
==
num
;
}
}
}
var
info
=
new
Object
();
info
.
route
=
route
;
info
.
num
=
num
;
info
.
pass
=
false
;
// json 형태로 저장
Bus
.
push
(
info
);
}
})
console
.
log
(
routeID
);
console
.
log
(
Bus
);
})
\ No newline at end of file
...
...
Please
register
or
login
to post a comment