hk-bus-eta 1.6.0 → 1.7.2
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/LightRail.js +19 -3
- package/Mtr.js +27 -0
- package/index.d.ts +1 -1
- package/index.js +3 -0
- package/package.json +1 -1
package/LightRail.js
CHANGED
|
@@ -14,11 +14,23 @@ module.exports = {
|
|
|
14
14
|
...route_list
|
|
15
15
|
.filter(({route_no, dest_ch, stop}) => route === route_no && dest_ch === dest.zh && stop === 0)
|
|
16
16
|
.map( ({time_en}) => {
|
|
17
|
-
|
|
17
|
+
let waitTime = 0
|
|
18
|
+
switch ( time_en.toLowerCase() ) {
|
|
19
|
+
case 'arriving':
|
|
20
|
+
case 'departing':
|
|
21
|
+
case '-':
|
|
22
|
+
waitTime = 0;
|
|
23
|
+
break;
|
|
24
|
+
default:
|
|
25
|
+
waitTime = parseInt(time_en, 10)
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
const etaDate = new Date(Date.now() + waitTime * 60 * 1000 + 8 * 3600000);
|
|
18
29
|
return {
|
|
19
|
-
eta: etaDate
|
|
30
|
+
eta: `${etaDate.getUTCFullYear()}-${`0${etaDate.getUTCMonth() + 1}`.slice(-2)}-${`0${etaDate.getUTCDate()}`.slice(-2)}`
|
|
31
|
+
+`T${`0${etaDate.getUTCHours()}`.slice(-2)}:${`0${etaDate.getMinutes()}`.slice(-2)}:${`0${etaDate.getSeconds()}`.slice(-2)}+08:00`,
|
|
20
32
|
remark: {
|
|
21
|
-
zh: `${platform_id}
|
|
33
|
+
zh: `${platform_id}號月台`,
|
|
22
34
|
en: `Platform ${platform_id}`
|
|
23
35
|
},
|
|
24
36
|
co: 'lightRail'
|
|
@@ -26,6 +38,10 @@ module.exports = {
|
|
|
26
38
|
}, [])
|
|
27
39
|
], [])
|
|
28
40
|
))
|
|
41
|
+
.catch(e => {
|
|
42
|
+
console.error(e);
|
|
43
|
+
return [];
|
|
44
|
+
})
|
|
29
45
|
),
|
|
30
46
|
fetchStopEtas: ( stopId ) => []
|
|
31
47
|
}
|
package/Mtr.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const utils = require('./utils');
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
co: 'mtr',
|
|
5
|
+
fetchEtas: ({stopId, route, bound }) => (
|
|
6
|
+
fetch(`https://rt.data.gov.hk/v1/transport/mtr/getSchedule.php?line=${route}&sta=${stopId}`, {
|
|
7
|
+
cache: utils.isSafari ? 'default' : 'no-store',
|
|
8
|
+
}).then( response => response.json() )
|
|
9
|
+
.then(({data, status}) => (
|
|
10
|
+
status === 0
|
|
11
|
+
? []
|
|
12
|
+
: data[`${route}-${stopId}`][bound.slice(-2,1) === 'U' ? 'UP' : 'DOWN']
|
|
13
|
+
.reduce((acc, {time, plat, dest}) => [
|
|
14
|
+
...acc,
|
|
15
|
+
{
|
|
16
|
+
eta: time.replace(' ', 'T')+'+08:00',
|
|
17
|
+
remark: {
|
|
18
|
+
zh: `${plat}號月台`,
|
|
19
|
+
en: `Platform ${plat}`
|
|
20
|
+
},
|
|
21
|
+
co: 'mtr'
|
|
22
|
+
}
|
|
23
|
+
], [])
|
|
24
|
+
))
|
|
25
|
+
),
|
|
26
|
+
fetchStopEtas: ( stopId ) => []
|
|
27
|
+
}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -5,6 +5,7 @@ const NlbApi = require('./Nlb')
|
|
|
5
5
|
const LrtfeederApi = require('./Lrtfeeder')
|
|
6
6
|
const GmbApi = require('./Gmb')
|
|
7
7
|
const LightRailApi = require('./LightRail')
|
|
8
|
+
const MtrApi = require('./Mtr')
|
|
8
9
|
|
|
9
10
|
module.exports = {
|
|
10
11
|
// seq is 0-based here
|
|
@@ -30,6 +31,8 @@ module.exports = {
|
|
|
30
31
|
_etas = _etas.concat( await GmbApi.fetchEtas({stopId: stops.gmb[seq], gtfsId, seq, bound: bound[company_id]}) )
|
|
31
32
|
} else if ( company_id === 'lightRail' && stops.lightRail ) {
|
|
32
33
|
_etas = _etas.concat( await LightRailApi.fetchEtas({ stopId: stops.lightRail[seq], route, dest }) )
|
|
34
|
+
} else if ( company_id === 'mtr' && stops.mtr ) {
|
|
35
|
+
_etas = _etas.concat( await MtrApi.fetchEtas({ stopId: stops.mtr[seq], route, bound: bound.mtr }) )
|
|
33
36
|
}
|
|
34
37
|
}
|
|
35
38
|
|