홍용민

버스 도착 여부 확인

test.js
BusInfo.txt
\ No newline at end of file
......@@ -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
......