홍용민

predict 함수 사용방법 수정

Showing 1 changed file with 16 additions and 23 deletions
...@@ -2,25 +2,25 @@ let request = require('request'); ...@@ -2,25 +2,25 @@ let request = require('request');
2 let cheerio = require('cheerio'); 2 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 stationID = '228000708'; // 사색의광장 들어오는 방향 5 +//const stationID = '228000708'; // 사색의광장 들어오는 방향
6 const gateStationID = '203000125' 6 const gateStationID = '203000125'
7 7
8 require('dotenv').config(); 8 require('dotenv').config();
9 9
10 -const BusArrivalUrl = bus_url + '?servicekey=' + process.env.key + '&stationId=' + stationID;// 사색의광장 정류장 버스 도착 정보 조회용 10 +//const BusArrivalUrl = bus_url + '?servicekey=' + process.env.key + '&stationId=' + stationID;// 사색의광장 정류장 버스 도착 정보 조회용
11 //console.log(BusArrivalUrl); 11 //console.log(BusArrivalUrl);
12 12
13 -var routeID = []; 13 +var routeID = ['200000112', '200000115', '234000016', '200000103'];
14 var Bus = []; 14 var Bus = [];
15 -request(BusArrivalUrl, (err, res, body) => { 15 +// request(BusArrivalUrl, (err, res, body) => {
16 - var $ = cheerio.load(body, {decodeEntities: false}); 16 +// var $ = cheerio.load(body, {decodeEntities: false});
17 17
18 - $('busArrivalList').each(function(idx){ 18 +// $('busArrivalList').each(function(idx){
19 - let route = $(this).find('routeId').text(); 19 +// let route = $(this).find('routeId').text();
20 - routeID.push(route); 20 +// routeID.push(route);
21 - }) 21 +// })
22 - //console.log(routeID); 22 +// //console.log(routeID);
23 -}) 23 +// })
24 24
25 const route_url = 'http://apis.data.go.kr/6410000/busrouteservice/getBusRouteInfoItem'; 25 const route_url = 'http://apis.data.go.kr/6410000/busrouteservice/getBusRouteInfoItem';
26 var index = 0; 26 var index = 0;
...@@ -57,19 +57,15 @@ function getBusNum(){ ...@@ -57,19 +57,15 @@ function getBusNum(){
57 }) 57 })
58 } 58 }
59 59
60 -function useFor(){ 60 +for(var i=0; i<routeID.length; i++){
61 - for(var i=0; i<routeID.length; i++){ 61 + getBusNum();
62 - setTimeout(getBusNum, 500);
63 - }
64 } 62 }
65 -setTimeout(useFor, 500);
66 63
67 const GateBusUrl = bus_url + '?servicekey=' + process.env.key + '&stationId=' + gateStationID; //국제캠 정문 정류장 64 const GateBusUrl = bus_url + '?servicekey=' + process.env.key + '&stationId=' + gateStationID; //국제캠 정문 정류장
68 let date = new Date(); 65 let date = new Date();
69 -let curHour = date.getHours(); // 현재 시간
70 -let curMinute = date.getMinutes(); //현재 분
71 66
72 function predict(){ 67 function predict(){
68 + console.log(GateBusUrl);
73 request(GateBusUrl, (err, res, body) => { 69 request(GateBusUrl, (err, res, body) => {
74 var $ = cheerio.load(body, {decodeEntities: false}); 70 var $ = cheerio.load(body, {decodeEntities: false});
75 71
...@@ -98,14 +94,11 @@ function predict(){ ...@@ -98,14 +94,11 @@ function predict(){
98 Bus[index]["MaxPredictTime"] = predictHour2 + ":" + predictMinute2; 94 Bus[index]["MaxPredictTime"] = predictHour2 + ":" + predictMinute2;
99 } 95 }
100 }) 96 })
101 - console.log(Bus);
102 }) 97 })
103 } 98 }
104 99
105 function useWhile(){ 100 function useWhile(){
106 - while(true){ 101 + setInterval(predict, 60000);
107 - setTimeout(predict, 6000);
108 - }
109 } 102 }
110 103
111 -setTimeout(useWhile, 1000);
...\ No newline at end of file ...\ No newline at end of file
104 +setTimeout(useWhile, 20000);
...\ No newline at end of file ...\ No newline at end of file
......