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-06-07 00:12:43 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
0ecf406fa8da0f0d8356d524b781de1482e0c002
0ecf406f
1 parent
cd01f210
predict 함수 사용방법 수정
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
23 deletions
BusInfo.js
BusInfo.js
View file @
0ecf406
...
...
@@ -2,25 +2,25 @@ let request = require('request');
let
cheerio
=
require
(
'cheerio'
);
const
bus_url
=
'http://apis.data.go.kr/6410000/busarrivalservice/getBusArrivalList'
;
const
stationID
=
'228000708'
;
// 사색의광장 들어오는 방향
//
const stationID = '228000708'; // 사색의광장 들어오는 방향
const
gateStationID
=
'203000125'
require
(
'dotenv'
).
config
();
const
BusArrivalUrl
=
bus_url
+
'?servicekey='
+
process
.
env
.
key
+
'&stationId='
+
stationID
;
// 사색의광장 정류장 버스 도착 정보 조회용
//
const BusArrivalUrl = bus_url + '?servicekey=' + process.env.key + '&stationId=' + stationID;// 사색의광장 정류장 버스 도착 정보 조회용
//console.log(BusArrivalUrl);
var
routeID
=
[];
var
routeID
=
[
'200000112'
,
'200000115'
,
'234000016'
,
'200000103'
];
var
Bus
=
[];
request
(
BusArrivalUrl
,
(
err
,
res
,
body
)
=>
{
var
$
=
cheerio
.
load
(
body
,
{
decodeEntities
:
false
});
//
request(BusArrivalUrl, (err, res, body) => {
//
var $ = cheerio.load(body, {decodeEntities: false});
$
(
'busArrivalList'
).
each
(
function
(
idx
){
let
route
=
$
(
this
).
find
(
'routeId'
).
text
();
routeID
.
push
(
route
);
})
//console.log(routeID);
})
//
$('busArrivalList').each(function(idx){
//
let route = $(this).find('routeId').text();
//
routeID.push(route);
//
})
//
//console.log(routeID);
//
})
const
route_url
=
'http://apis.data.go.kr/6410000/busrouteservice/getBusRouteInfoItem'
;
var
index
=
0
;
...
...
@@ -57,19 +57,15 @@ function getBusNum(){
})
}
function
useFor
(){
for
(
var
i
=
0
;
i
<
routeID
.
length
;
i
++
){
setTimeout
(
getBusNum
,
500
);
}
for
(
var
i
=
0
;
i
<
routeID
.
length
;
i
++
){
getBusNum
();
}
setTimeout
(
useFor
,
500
);
const
GateBusUrl
=
bus_url
+
'?servicekey='
+
process
.
env
.
key
+
'&stationId='
+
gateStationID
;
//국제캠 정문 정류장
let
date
=
new
Date
();
let
curHour
=
date
.
getHours
();
// 현재 시간
let
curMinute
=
date
.
getMinutes
();
//현재 분
function
predict
(){
console
.
log
(
GateBusUrl
);
request
(
GateBusUrl
,
(
err
,
res
,
body
)
=>
{
var
$
=
cheerio
.
load
(
body
,
{
decodeEntities
:
false
});
...
...
@@ -98,14 +94,11 @@ function predict(){
Bus
[
index
][
"MaxPredictTime"
]
=
predictHour2
+
":"
+
predictMinute2
;
}
})
console
.
log
(
Bus
);
})
}
function
useWhile
(){
while
(
true
){
setTimeout
(
predict
,
6000
);
}
setInterval
(
predict
,
60000
);
}
setTimeout
(
useWhile
,
1000
);
\ No newline at end of file
setTimeout
(
useWhile
,
20000
);
\ No newline at end of file
...
...
Please
register
or
login
to post a comment