forked from 1core2life/smart-mirror-A-team
-
Notifications
You must be signed in to change notification settings - Fork 0
/
busntrail.js
44 lines (36 loc) · 1.96 KB
/
busntrail.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
exports.searchBus = function(res,stationName,busDes) {
var request = require('request');
var cheerio = require('cheerio');
var urlencode = require('urlencode');
var EncodedName = urlencode(stationName);
var SearchStationNum = "http://m.gbis.go.kr/search/getStationPageList.do?tabMode=&serviceKey=1234567890&pageSize=15&pageNo=1&keyword="+EncodedName+"&routeType=41%2C42%2C43%2C51%2C52%2C53&searchData="+EncodedName+"&osInfoType=M";
request({
url: SearchStationNum,
method: 'GET'
}, function(err, response, body) {
var totalInfo = JSON.parse(body);
var array = {"station": [], "stationId": []};
for( var i in totalInfo["result"]["stationList"]){
array["station"][i] = totalInfo["result"]["stationList"][i]["stationName"];
array["stationId"][i] = totalInfo["result"]["stationList"][i]["stationId"];
}
// here, 0~ n th check from user , then input num
// untill input system made, use 0 input
SearchStationNum = "http://m.gbis.go.kr/search/getBusStationArrival.do?stationId="+array["stationId"][busDes]+"&osInfoType=M";
request({
url: SearchStationNum,
method: 'GET'
}, function(err, response, body) {
var totalInfo2 = JSON.parse(body);
var array2 = {"busNum": [], "predictTime": [], "routeDestName": []};
for( var i in totalInfo2["busStationArrivalInfo"]["arrivalList"]){
array2["routeDestName"][i] = totalInfo2["busStationArrivalInfo"]["arrivalList"][i]["routeDestName"];
array2["busNum"][i] = totalInfo2["busStationArrivalInfo"]["arrivalList"][i]["routeName"];
array2["predictTime"][i] = totalInfo2["busStationArrivalInfo"]["arrivalList"][i]["predictTime1"];
}
var renderingJson = JSON.stringify(array2);
res.writeHead(200 , {'Content-Type': 'text/html'});
res.end(renderingJson);
});
});
}