홍용민

버스 도착 여부 확인

1 +test.js
2 +BusInfo.txt
...\ No newline at end of file ...\ No newline at end of file
...@@ -3,14 +3,15 @@ let cheerio = require('cheerio'); ...@@ -3,14 +3,15 @@ let cheerio = require('cheerio');
3 3
4 const bus_url = 'http://apis.data.go.kr/6410000/busarrivalservice/getBusArrivalList'; 4 const bus_url = 'http://apis.data.go.kr/6410000/busarrivalservice/getBusArrivalList';
5 const bus_key = 'RwxSWXH88b2bKOAT6Ot3FHorPZQW9omma0xYIjtJe0JIKe4DC7TjX7Uj6E1ArzYi2AvVETmPrAIYyY8FlL%2BfAA%3D%3D'; 5 const bus_key = 'RwxSWXH88b2bKOAT6Ot3FHorPZQW9omma0xYIjtJe0JIKe4DC7TjX7Uj6E1ArzYi2AvVETmPrAIYyY8FlL%2BfAA%3D%3D';
6 -const stationID = '228000708'; 6 +const stationID = '228000708'; // 사색의광장 들어오는 방향
7 +const gateStationID = '203000125'
7 8
8 const BusArrivalUrl = bus_url + '?servicekey=' + bus_key + '&stationId=' + stationID;// 사색의광장 정류장 버스 도착 정보 조회용 9 const BusArrivalUrl = bus_url + '?servicekey=' + bus_key + '&stationId=' + stationID;// 사색의광장 정류장 버스 도착 정보 조회용
9 console.log(BusArrivalUrl); 10 console.log(BusArrivalUrl);
10 11
11 -const _sleep = (delay) => new Promise((resolve) => setTimeout(resolve, delay));
12 var routeID = []; 12 var routeID = [];
13 -var BusNum = []; 13 +var Bus = []; // 버스 차 번호( ex) 경기 70바 3713 ) / 도착 여부 확인용
14 +var BusNum = []; // 버스 번호 ( ex) 9)
14 request(BusArrivalUrl, (err, res, body) => { 15 request(BusArrivalUrl, (err, res, body) => {
15 var $ = cheerio.load(body, {decodeEntities: false}); 16 var $ = cheerio.load(body, {decodeEntities: false});
16 17
...@@ -26,9 +27,9 @@ const route_key = 'RwxSWXH88b2bKOAT6Ot3FHorPZQW9omma0xYIjtJe0JIKe4DC7TjX7Uj6E1Ar ...@@ -26,9 +27,9 @@ const route_key = 'RwxSWXH88b2bKOAT6Ot3FHorPZQW9omma0xYIjtJe0JIKe4DC7TjX7Uj6E1Ar
26 27
27 var j = 0; 28 var j = 0;
28 function getBusNum(){ 29 function getBusNum(){
29 - let BusRouteUrl = route_url + '?servicekey=' + route_key + '&routeId='; 30 + let BusRouteUrl = route_url + '?servicekey=' + route_key + '&routeId='; // 각 버스 정보 조회용
30 BusRouteUrl += routeID[j++]; 31 BusRouteUrl += routeID[j++];
31 - console.log(BusRouteUrl); 32 + //console.log(BusRouteUrl);
32 33
33 request(BusRouteUrl, (err, res, body) => { 34 request(BusRouteUrl, (err, res, body) => {
34 var $ = cheerio.load(body, {decodeEntities: false}); 35 var $ = cheerio.load(body, {decodeEntities: false});
...@@ -46,3 +47,33 @@ function useFor(){ ...@@ -46,3 +47,33 @@ function useFor(){
46 } 47 }
47 } 48 }
48 setTimeout(useFor, 500); 49 setTimeout(useFor, 500);
50 +
51 +const GateBusUrl = bus_url + '?servicekey=' + bus_key + '&stationId=' + gateStationID;
52 +
53 +request(GateBusUrl, (err, res, body) => {
54 + var $ = cheerio.load(body, {decodeEntities: false});
55 +
56 + $('busArrivalList').each(function(idx){
57 + let route = $(this).find('routeId').text();
58 + let num = $(this).find('plateNo1').text();
59 +
60 + var index = routeID.indexOf(route);
61 + if(index > -1){
62 + for(var i=0; i<Bus.length; i++){
63 + if(Bus[i]['route'] == route){
64 + if(Bus[i]['num'] != num){
65 + Bus[i]['pass'] = true;
66 + Bus[i]['num'] == num;
67 + }
68 + }
69 + }
70 + var info = new Object();
71 + info.route = route;
72 + info.num = num;
73 + info.pass = false; // json 형태로 저장
74 + Bus.push(info);
75 + }
76 + })
77 + console.log(routeID);
78 + console.log(Bus);
79 +})
...\ No newline at end of file ...\ No newline at end of file
......