Toggle navigation
Toggle navigation
This project
Loading...
Sign in
홍용민
/
BusTime
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
홍용민
2021-05-28 22:06:29 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
715215a9cb7c3f4885d03dee3327c19ed9857467
715215a9
1 parent
81ffeed8
필요 정보 저장 형태 json으로 변환
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
37 deletions
BusInfo.js
BusInfo.js
View file @
715215a
...
...
@@ -7,7 +7,7 @@ const stationID = '228000708'; // 사색의광장 들어오는 방향
const
gateStationID
=
'203000125'
const
BusArrivalUrl
=
bus_url
+
'?servicekey='
+
bus_key
+
'&stationId='
+
stationID
;
// 사색의광장 정류장 버스 도착 정보 조회용
console
.
log
(
BusArrivalUrl
);
//
console.log(BusArrivalUrl);
var
routeID
=
[];
var
Bus
=
[];
// 버스 차 번호( ex) 경기 70바 3713 ) / 도착 여부 확인용
...
...
@@ -19,61 +19,78 @@ request(BusArrivalUrl, (err, res, body) => {
let
route
=
$
(
this
).
find
(
'routeId'
).
text
();
routeID
.
push
(
route
);
})
console
.
log
(
routeID
);
//
console.log(routeID);
})
const
route_url
=
'http://apis.data.go.kr/6410000/busrouteservice/getBusRouteInfoItem'
;
const
route_key
=
'RwxSWXH88b2bKOAT6Ot3FHorPZQW9omma0xYIjtJe0JIKe4DC7TjX7Uj6E1ArzYi2AvVETmPrAIYyY8FlL%2BfAA%3D%3D'
;
var
j
=
0
;
var
index
=
0
;
function
getBusNum
(){
let
BusRouteUrl
=
route_url
+
'?servicekey='
+
route_key
+
'&routeId='
;
// 각 버스 정보 조회용
BusRouteUrl
+=
routeID
[
j
++
];
var
BusRouteUrl
=
route_url
+
'?servicekey='
+
route_key
+
'&routeId='
;
// 각 버스 정보 조회용
BusRouteUrl
+=
routeID
[
index
++
];
//console.log(BusRouteUrl);
request
(
BusRouteUrl
,
(
err
,
res
,
body
)
=>
{
var
$
=
cheerio
.
load
(
body
,
{
decodeEntities
:
false
});
$
(
'busRouteInfoItem'
).
each
(
function
(
idx
){
let
num
=
$
(
this
).
find
(
'routeName'
).
text
();
BusNum
.
push
(
num
);
console
.
log
(
num
);
var
id
=
$
(
this
).
find
(
'routeId'
).
text
();
//버스 노선 id
var
num
=
$
(
this
).
find
(
'routeName'
).
text
();
//버스 번호
var
firsttime
=
$
(
this
).
find
(
'upFirstTime'
).
text
();
//평일 기점 첫차시간
var
lasttime
=
$
(
this
).
find
(
'upLastTime'
).
text
();
//평일 기점 막차 시간
var
mintime
=
$
(
this
).
find
(
'peekAlloc'
).
text
();
//평일 최소 배차시간
var
maxtime
=
$
(
this
).
find
(
'nPeekAlloc'
).
text
();
//평일 최대 배차시간
//var idx = Bus.findIndex((item, idx) => { return item.routeId = id})
var
newBus
=
new
Object
();
newBus
.
routeId
=
id
;
newBus
.
BusNum
=
num
;
newBus
.
FirstTime
=
firsttime
;
newBus
.
LastTime
=
lasttime
;
newBus
.
MinTime
=
mintime
;
newBus
.
MaxTime
=
maxtime
;
console
.
log
(
newBus
);
Bus
.
push
(
newBus
);
})
})
}
function
useFor
(){
for
(
var
i
=
0
;
i
<
routeID
.
length
;
i
++
){
setTimeout
(
getBusNum
,
10
00
);
setTimeout
(
getBusNum
,
5
00
);
}
}
setTimeout
(
useFor
,
500
);
const
GateBusUrl
=
bus_url
+
'?servicekey='
+
bus_key
+
'&stationId='
+
gateStationID
;
//
const GateBusUrl = bus_url + '?servicekey=' + bus_key + '&stationId=' + gateStationID;
request
(
GateBusUrl
,
(
err
,
res
,
body
)
=>
{
var
$
=
cheerio
.
load
(
body
,
{
decodeEntities
:
false
});
//
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
// $('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
...
...
Please
register
or
login
to post a comment