Skip to content

Commit a83078c

Browse files
committed
website: Revive ISB bus timings
Straightforward changes necessary to bring back bus timings in Venues. Most of the work was done by @kagiura in PR #3172. I'm mainly bringing in the bus stop data and API changes and gluing it together to make it work with the original bus timing feature.
1 parent 6b925d2 commit a83078c

File tree

7 files changed

+1011
-443
lines changed

7 files changed

+1011
-443
lines changed

website/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"@types/enzyme": "3.10.18",
4747
"@types/jest": "29.5.14",
4848
"@types/json2mq": "0.2.2",
49-
"@types/leaflet": "1.9.12",
49+
"@types/leaflet": "1.9.14",
5050
"@types/lodash": "4.14.197",
5151
"@types/mousetrap": "1.6.15",
5252
"@types/no-scroll": "2.1.2",

website/scripts/download-bus-stops.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// TODO: This script is outdated and needs work to make it work with the new API.
2+
13
const path = require('path');
24
const axios = require('axios');
35
const fs = require('fs-extra');

website/src/apis/nextbus.ts

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import axios from 'axios';
22

33
import { NextBus, NextBusTime, NextBusTimings } from 'types/venues';
44

5-
const baseUrl = 'https://nextbus.nusmods.com';
5+
const baseUrl = 'https://nnextbus.nusmods.com';
66

77
interface ShuttleServiceResult {
88
caption: string;
@@ -25,24 +25,18 @@ function convertArrivalTime(arrivalTime: string): NextBusTime {
2525
throw new Error(`Unknown arrival time ${arrivalTime}`);
2626
}
2727

28-
export function nextBus(code: string): Promise<NextBusTimings> {
29-
const url = `${baseUrl}/arrival`;
30-
return axios
31-
.get<{
32-
ShuttleServiceResult: ShuttleServiceResult;
33-
}>(url, { params: { busstopname: code } })
34-
.then((response) => {
35-
const shuttles: NextBusTimings = {};
36-
37-
response.data.ShuttleServiceResult.shuttles.forEach((arrival: Shuttle) => {
38-
const timing: NextBus = {
39-
arrivalTime: convertArrivalTime(arrival.arrivalTime),
40-
nextArrivalTime: convertArrivalTime(arrival.nextArrivalTime),
41-
};
42-
43-
shuttles[arrival.name] = timing;
44-
});
45-
46-
return shuttles;
47-
});
28+
export async function nextBus(name: string): Promise<NextBusTimings> {
29+
const url = `${baseUrl}/ShuttleService?busstopname=${name}`;
30+
const response = await axios.get<{
31+
ShuttleServiceResult: ShuttleServiceResult;
32+
}>(url, { params: { busstopname: name } });
33+
const shuttles: NextBusTimings = {};
34+
response.data.ShuttleServiceResult.shuttles.forEach((arrival: Shuttle) => {
35+
const timing: NextBus = {
36+
arrivalTime: convertArrivalTime(arrival.arrivalTime),
37+
nextArrivalTime: convertArrivalTime(arrival.nextArrivalTime),
38+
};
39+
shuttles[arrival.name] = timing;
40+
});
41+
return shuttles;
4842
}

0 commit comments

Comments
 (0)