hk-bus-eta 1.5.0 → 1.6.0
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/Gmb.js +2 -5
- package/LightRail.js +31 -0
- package/index.d.ts +1 -1
- package/index.js +5 -2
- package/package.json +1 -1
package/Gmb.js
CHANGED
|
@@ -2,13 +2,14 @@ const utils = require('./utils');
|
|
|
2
2
|
|
|
3
3
|
module.exports = {
|
|
4
4
|
co: 'gmb',
|
|
5
|
-
fetchEtas: ({gtfsId, stopId, bound}) => (
|
|
5
|
+
fetchEtas: ({gtfsId, stopId, bound,seq}) => (
|
|
6
6
|
fetch(`https://data.etagmb.gov.hk/eta/route-stop/${gtfsId}/${stopId}`, {
|
|
7
7
|
cache: utils.isSafari ? 'default' : 'no-store'
|
|
8
8
|
}).then( response => response.json() )
|
|
9
9
|
.then(({data}) => (
|
|
10
10
|
data
|
|
11
11
|
.filter(({route_seq}) => ( bound === 'O' && route_seq === 1 ) || ( bound === 'I' && route_seq === 2 ) )
|
|
12
|
+
.filter(({stop_seq}) => stop_seq === seq + 1)
|
|
12
13
|
.reduce( (acc, {eta}) => [
|
|
13
14
|
...acc,
|
|
14
15
|
...eta.map( data => ({
|
|
@@ -21,10 +22,6 @@ module.exports = {
|
|
|
21
22
|
}))
|
|
22
23
|
], [] )
|
|
23
24
|
))
|
|
24
|
-
.then(ret => {
|
|
25
|
-
console.log(ret)
|
|
26
|
-
return ret
|
|
27
|
-
})
|
|
28
25
|
),
|
|
29
26
|
fetchStopEtas: ( stopId ) => []
|
|
30
27
|
}
|
package/LightRail.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const utils = require('./utils');
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
co: 'lightRail',
|
|
5
|
+
fetchEtas: ({stopId, route, dest }) => (
|
|
6
|
+
fetch(`https://rt.data.gov.hk/v1/transport/mtr/lrt/getSchedule?station_id=${stopId.slice(2)}`, {
|
|
7
|
+
cache: utils.isSafari ? 'default' : 'no-store',
|
|
8
|
+
|
|
9
|
+
}).then( response => response.json() )
|
|
10
|
+
.then(({platform_list}) => (
|
|
11
|
+
platform_list
|
|
12
|
+
.reduce((acc, {route_list, platform_id}) => [
|
|
13
|
+
...acc,
|
|
14
|
+
...route_list
|
|
15
|
+
.filter(({route_no, dest_ch, stop}) => route === route_no && dest_ch === dest.zh && stop === 0)
|
|
16
|
+
.map( ({time_en}) => {
|
|
17
|
+
const etaDate = new Date(Date.now() + parseInt(time_en, 10) * 60 * 1000).toISOString();
|
|
18
|
+
return {
|
|
19
|
+
eta: etaDate,
|
|
20
|
+
remark: {
|
|
21
|
+
zh: `${platform_id}號平台`,
|
|
22
|
+
en: `Platform ${platform_id}`
|
|
23
|
+
},
|
|
24
|
+
co: 'lightRail'
|
|
25
|
+
}
|
|
26
|
+
}, [])
|
|
27
|
+
], [])
|
|
28
|
+
))
|
|
29
|
+
),
|
|
30
|
+
fetchStopEtas: ( stopId ) => []
|
|
31
|
+
}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -4,10 +4,11 @@ const CtbApi = require('./Ctb')
|
|
|
4
4
|
const NlbApi = require('./Nlb')
|
|
5
5
|
const LrtfeederApi = require('./Lrtfeeder')
|
|
6
6
|
const GmbApi = require('./Gmb')
|
|
7
|
+
const LightRailApi = require('./LightRail')
|
|
7
8
|
|
|
8
9
|
module.exports = {
|
|
9
10
|
// seq is 0-based here
|
|
10
|
-
fetchEtas: async ( {route, stops, bound, seq, serviceType, co, nlbId, gtfsId, language }) => {
|
|
11
|
+
fetchEtas: async ( {route, stops, bound, dest, seq, serviceType, co, nlbId, gtfsId, language }) => {
|
|
11
12
|
let _etas = []
|
|
12
13
|
for ( const company_id of co ) {
|
|
13
14
|
if (company_id === 'kmb' && stops.kmb ){
|
|
@@ -26,7 +27,9 @@ module.exports = {
|
|
|
26
27
|
} else if ( company_id === 'lrtfeeder' && stops.lrtfeeder ) {
|
|
27
28
|
_etas = _etas.concat( await LrtfeederApi.fetchEtas({stopId: stops.lrtfeeder[seq], route, language}))
|
|
28
29
|
} else if ( company_id === 'gmb' && stops.gmb ) {
|
|
29
|
-
_etas = _etas.concat( await GmbApi.fetchEtas({stopId: stops.gmb[seq], gtfsId, bound: bound[company_id]}) )
|
|
30
|
+
_etas = _etas.concat( await GmbApi.fetchEtas({stopId: stops.gmb[seq], gtfsId, seq, bound: bound[company_id]}) )
|
|
31
|
+
} else if ( company_id === 'lightRail' && stops.lightRail ) {
|
|
32
|
+
_etas = _etas.concat( await LightRailApi.fetchEtas({ stopId: stops.lightRail[seq], route, dest }) )
|
|
30
33
|
}
|
|
31
34
|
}
|
|
32
35
|
|