hk-bus-eta 1.2.2 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Ctb.js +3 -5
- package/Kmb.js +3 -5
- package/Lrtfeeder.js +34 -0
- package/Nlb.js +1 -3
- package/Nwfb.js +3 -5
- package/index.d.ts +3 -2
- package/index.js +18 -18
- package/package.json +1 -1
- package/utils.js +0 -3
package/Ctb.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
const utils = require('./utils')
|
|
2
|
-
|
|
3
1
|
module.exports = {
|
|
4
2
|
co: 'ctb',
|
|
5
3
|
fetchEtas: ({stopId, route, bound }) => (
|
|
6
4
|
fetch(`https://rt.data.gov.hk//v1/transport/citybus-nwfb/eta/CTB/${stopId}/${route}`, {
|
|
7
|
-
cache:
|
|
5
|
+
cache: "reload"
|
|
8
6
|
}).then(
|
|
9
7
|
response => response.json()
|
|
10
8
|
).then(({data}) => data.filter(eta => eta.eta && eta.dir === bound).map(e => ({
|
|
@@ -19,7 +17,7 @@ module.exports = {
|
|
|
19
17
|
),
|
|
20
18
|
fetchStopEtas: ( stopId ) => (
|
|
21
19
|
fetch(`https://rt.data.gov.hk/v1/transport/batch/stop-eta/CTB/${stopId}`, {
|
|
22
|
-
cache:
|
|
20
|
+
cache: "reload"
|
|
23
21
|
}).then(
|
|
24
22
|
response => response.json()
|
|
25
23
|
).then(({data}) => data.map( e => ({
|
|
@@ -37,4 +35,4 @@ module.exports = {
|
|
|
37
35
|
co: 'ctb'
|
|
38
36
|
})))
|
|
39
37
|
)
|
|
40
|
-
}
|
|
38
|
+
}
|
package/Kmb.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
const utils = require('./utils')
|
|
2
|
-
|
|
3
1
|
module.exports = {
|
|
4
2
|
co: 'kmb',
|
|
5
3
|
fetchEtas: ({stopId, route, seq, serviceType, bound}) => (
|
|
6
4
|
fetch(
|
|
7
5
|
`https://data.etabus.gov.hk/v1/transport/kmb/eta/${stopId}/${route}/${serviceType}`,
|
|
8
|
-
{ cache:
|
|
6
|
+
{ cache: "reload" }
|
|
9
7
|
).then( response => response.json() )
|
|
10
8
|
.then(({data}) => data.filter(e =>
|
|
11
9
|
e.dir === bound
|
|
@@ -22,7 +20,7 @@ module.exports = {
|
|
|
22
20
|
),
|
|
23
21
|
fetchStopEtas: ( stopId ) => (
|
|
24
22
|
fetch(`https://data.etabus.gov.hk/v1/transport/kmb/stop-eta/${stopId}`, {
|
|
25
|
-
cache:
|
|
23
|
+
cache: "reload"
|
|
26
24
|
})
|
|
27
25
|
.then(response => response.json())
|
|
28
26
|
.then(({data}) => data.map( e => ({
|
|
@@ -42,4 +40,4 @@ module.exports = {
|
|
|
42
40
|
co: 'kmb'
|
|
43
41
|
})))
|
|
44
42
|
)
|
|
45
|
-
}
|
|
43
|
+
}
|
package/Lrtfeeder.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
co: 'lrtfeeder',
|
|
3
|
+
fetchEtas: ({stopId, route, language}) => (
|
|
4
|
+
fetch(`https://rt.data.gov.hk/v1/transport/mtr/bus/getSchedule`, {
|
|
5
|
+
method: "POST",
|
|
6
|
+
cache: "reload",
|
|
7
|
+
headers: {
|
|
8
|
+
'Content-Type': 'application/json'
|
|
9
|
+
},
|
|
10
|
+
body: JSON.stringify({
|
|
11
|
+
'language': language,
|
|
12
|
+
'routeName': route
|
|
13
|
+
})
|
|
14
|
+
}).then( response => response.json() )
|
|
15
|
+
.then(({busStop}) =>
|
|
16
|
+
busStop.filter(({busStopId}) => busStopId === stopId)
|
|
17
|
+
.reduce((ret, {bus: buses}) => ([...ret, ...buses.reduce( (etas, bus) => {
|
|
18
|
+
const etaDate = new Date(Date.now() + parseInt(bus.arrivalTimeInSecond, 10) * 1000)
|
|
19
|
+
if ( bus.arrivalTimeInSecond === "108000" ) return [...etas];
|
|
20
|
+
return [
|
|
21
|
+
...etas,
|
|
22
|
+
{
|
|
23
|
+
eta: etaDate.toISOString(),
|
|
24
|
+
remark: {
|
|
25
|
+
[language]: bus.busRemark
|
|
26
|
+
},
|
|
27
|
+
co: 'lrtfeeder'
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}, [])]), [])
|
|
31
|
+
)
|
|
32
|
+
),
|
|
33
|
+
fetchStopEtas: ( stopId ) => []
|
|
34
|
+
}
|
package/Nlb.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
const utils = require('./utils')
|
|
2
|
-
|
|
3
1
|
module.exports = {
|
|
4
2
|
co: 'nlb',
|
|
5
3
|
fetchEtas: ({stopId, nlbId }) => (
|
|
@@ -30,7 +28,7 @@ module.exports = {
|
|
|
30
28
|
),
|
|
31
29
|
fetchStopEtas: ( stopId ) => (
|
|
32
30
|
fetch(`https://rt.data.gov.hk/v1/transport/batch/stop-eta/NLB/${stopId}`, {
|
|
33
|
-
cache:
|
|
31
|
+
cache: "reload"
|
|
34
32
|
}).then( response => {
|
|
35
33
|
if (response.ok)
|
|
36
34
|
return response.json()
|
package/Nwfb.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
const utils = require('./utils')
|
|
2
|
-
|
|
3
1
|
module.exports = {
|
|
4
2
|
co: 'nwfb',
|
|
5
3
|
fetchEtas: ({stopId, route, bound }) => (
|
|
6
4
|
fetch(`https://rt.data.gov.hk//v1/transport/citybus-nwfb/eta/NWFB/${stopId}/${route}`, {
|
|
7
|
-
cache:
|
|
5
|
+
cache: "reload"
|
|
8
6
|
}).then(
|
|
9
7
|
response => response.json()
|
|
10
8
|
).then(({data}) => data.filter(eta => eta.eta && eta.dir === bound).map(e => ({
|
|
@@ -19,7 +17,7 @@ module.exports = {
|
|
|
19
17
|
),
|
|
20
18
|
fetchStopEtas: ( stopId ) => (
|
|
21
19
|
fetch(`https://rt.data.gov.hk/v1/transport/batch/stop-eta/NWFB/${stopId}`, {
|
|
22
|
-
cache:
|
|
20
|
+
cache: "reload"
|
|
23
21
|
}).then(
|
|
24
22
|
response => response.json()
|
|
25
23
|
).then(({data}) => data.map( e => ({
|
|
@@ -37,4 +35,4 @@ module.exports = {
|
|
|
37
35
|
co: 'nwfb'
|
|
38
36
|
})))
|
|
39
37
|
)
|
|
40
|
-
}
|
|
38
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type Company = "kmb" | "nlb" | "ctb" | "nwfb"
|
|
1
|
+
export type Company = "kmb" | "nlb" | "ctb" | "nwfb" | 'lrtfeeder'
|
|
2
2
|
|
|
3
3
|
export type Terminal = {
|
|
4
4
|
en: string,
|
|
@@ -21,6 +21,7 @@ export type RouteListEntry = {
|
|
|
21
21
|
readonly fares: string[] | null,
|
|
22
22
|
readonly faresHoliday: string[] | null,
|
|
23
23
|
readonly freq: Freq | null,
|
|
24
|
+
readonly jt: string | null,
|
|
24
25
|
readonly seq: number,
|
|
25
26
|
readonly serviceType: string,
|
|
26
27
|
readonly stops: {
|
|
@@ -69,7 +70,7 @@ export type Eta = {
|
|
|
69
70
|
co: Company
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
export declare function fetchEtas(route:
|
|
73
|
+
export declare function fetchEtas(route: any): Promise<Eta[]>
|
|
73
74
|
|
|
74
75
|
export declare function fetchEtaObj(): Promise<BusDb>
|
|
75
76
|
|
package/index.js
CHANGED
|
@@ -2,29 +2,29 @@ const KmbApi = require('./Kmb')
|
|
|
2
2
|
const NwfbApi = require('./Nwfb')
|
|
3
3
|
const CtbApi = require('./Ctb')
|
|
4
4
|
const NlbApi = require('./Nlb')
|
|
5
|
+
const LrtfeederApi = require('./Lrtfeeder')
|
|
5
6
|
|
|
6
7
|
module.exports = {
|
|
7
8
|
// seq is 0-based here
|
|
8
|
-
fetchEtas: async ( {route, stops, bound, seq, serviceType, co, nlbId }) => {
|
|
9
|
+
fetchEtas: async ( {route, stops, bound, seq, serviceType, co, nlbId, language }) => {
|
|
9
10
|
let _etas = []
|
|
10
11
|
for ( const company_id of co ) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
12
|
+
if (company_id === 'kmb' && stops.kmb ){
|
|
13
|
+
_etas = _etas.concat( await KmbApi.fetchEtas({
|
|
14
|
+
route,
|
|
15
|
+
stopId: stops.kmb[seq],
|
|
16
|
+
seq,
|
|
17
|
+
serviceType, bound: bound[company_id]})
|
|
18
|
+
)
|
|
19
|
+
} else if ( company_id === 'ctb' && stops.ctb ) {
|
|
20
|
+
_etas = _etas.concat( await CtbApi.fetchEtas({stopId: stops.ctb[seq], route, bound: bound[company_id] }))
|
|
21
|
+
} else if ( company_id === 'nwfb' && stops.nwfb ) {
|
|
22
|
+
_etas = _etas.concat( await NwfbApi.fetchEtas({stopId: stops.nwfb[seq], route, bound: bound[company_id] }))
|
|
23
|
+
} else if ( company_id === 'nlb' && stops.nlb ) {
|
|
24
|
+
_etas = _etas.concat( await NlbApi.fetchEtas({stopId: stops.nlb[seq], nlbId}) )
|
|
25
|
+
} else if ( company_id === 'lrtfeeder' && stops.lrtfeeder ) {
|
|
26
|
+
_etas = _etas.concat( await LrtfeederApi.fetchEtas({stopId: stops.lrtfeeder[seq], route, language}))
|
|
27
|
+
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
return _etas.sort((a,b) => {
|
package/package.json
CHANGED
package/utils.js
DELETED