홍용민

predict 함수 사용방법 수정

Showing 1 changed file with 16 additions and 23 deletions
......@@ -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
......