Created
July 3, 2025 14:28
-
-
Save IJMacD/c33a5c9b5904da234e41a0df7d270dfe to your computer and use it in GitHub Desktop.
Pull journey time/cost for cartesian set of MTR journeys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number} originID | |
* @param {number} destinationID | |
* @returns {Promise<{ time: number, cost: number }|undefined>} | |
*/ | |
async function getRoute(originID, destinationID) { | |
if (originID === destinationID) { | |
return { time: 0, cost: 0 }; | |
} | |
const r = await fetch( | |
`https://www.mtr.com.hk/share/customer/jp/api/HRRoutes/?o=${originID}&d=${destinationID}&lang=E` | |
); | |
if (r.ok) { | |
const data = await r.json(); | |
const route = data.routes[0]; | |
return { | |
time: route.time, | |
cost: +route.fares[0].fareInfo.adult.octopus, | |
}; | |
} | |
} | |
import stations from "./stations.json" with { type: "json" }; | |
const fromStations = [ | |
"Sai Ying Pun", | |
"Kam Sheung Road", | |
"Kennedy Town", | |
"North Point", | |
"Tsim Sha Tsui", | |
"Jordan", | |
"Kwun Tong", | |
"Tseung Kwan O", | |
"Tsuen Wan", | |
"Tai Po Market", | |
]; | |
const toStations = [ | |
"Kowloon Bay", | |
"Central", | |
"Causeway Bay", | |
"Tsim Sha Tsui", | |
"Mong Kok", | |
"Sha Tin", | |
]; | |
for (const toStation of toStations) { | |
const tStation = stations.find((s) => s.name === toStation); | |
if (tStation) { | |
console.log(`To: ${toStation}`); | |
for (const fromStation of fromStations) { | |
const fStation = stations.find((s) => s.name === fromStation); | |
if (fStation) { | |
const result = await getRoute(fStation.id, tStation.id); | |
if (result) { | |
console.log(`${fromStation.padEnd(10, " ")}\t00:${result.time.toFixed(0).padStart(2, "0")}\t$${result.cost}`); | |
} | |
} | |
} | |
console.log(""); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"id": 2, | |
"code": "ADM", | |
"name": "Admiralty", | |
"nameZH": "金鐘", | |
"lines": [ | |
"ISL", | |
"TWL", | |
"SIL" | |
] | |
}, | |
{ | |
"id": 47, | |
"code": "AIR", | |
"name": "Airport", | |
"nameZH": "機場", | |
"lines": [ | |
"AEL" | |
] | |
}, | |
{ | |
"id": 111, | |
"code": "AUS", | |
"name": "Austin", | |
"nameZH": "柯士甸", | |
"lines": [ | |
"WRL" | |
] | |
}, | |
{ | |
"id": 56, | |
"code": "AWE", | |
"name": "AsiaWorld-Expo", | |
"nameZH": "博覽館", | |
"lines": [ | |
"AEL" | |
] | |
}, | |
{ | |
"id": 28, | |
"code": "CAB", | |
"name": "Causeway Bay", | |
"nameZH": "銅鑼灣", | |
"lines": [ | |
"ISL" | |
] | |
}, | |
{ | |
"id": 1, | |
"code": "CEN", | |
"name": "Central", | |
"nameZH": "中環", | |
"lines": [ | |
"ISL", | |
"TWL" | |
] | |
}, | |
{ | |
"id": 12, | |
"code": "CHH", | |
"name": "Choi Hung", | |
"nameZH": "彩虹", | |
"lines": [ | |
"KTL" | |
] | |
}, | |
{ | |
"id": 37, | |
"code": "CHW", | |
"name": "Chai Wan", | |
"nameZH": "柴灣", | |
"lines": [ | |
"ISL" | |
] | |
}, | |
{ | |
"id": 98, | |
"code": "CIO", | |
"name": "City One", | |
"nameZH": "第一城", | |
"lines": [ | |
"MOL" | |
] | |
}, | |
{ | |
"id": 96, | |
"code": "CKT", | |
"name": "Che Kung Temple", | |
"nameZH": "車公廟", | |
"lines": [ | |
"MOL" | |
] | |
}, | |
{ | |
"id": 18, | |
"code": "CSW", | |
"name": "Cheung Sha Wan", | |
"nameZH": "長沙灣", | |
"lines": [ | |
"TWL" | |
] | |
}, | |
{ | |
"id": 11, | |
"code": "DIH", | |
"name": "Diamond Hill", | |
"nameZH": "鑽石山", | |
"lines": [ | |
"KTL" | |
] | |
}, | |
{ | |
"id": 55, | |
"code": "DIS", | |
"name": "Disneyland Resort", | |
"nameZH": "迪士尼", | |
"lines": [ | |
"DRL" | |
] | |
}, | |
{ | |
"id": 80, | |
"code": "ETS", | |
"name": "East Tsim Sha Tsui", | |
"nameZH": "尖東", | |
"lines": [ | |
"WRL" | |
] | |
}, | |
{ | |
"id": 74, | |
"code": "FAN", | |
"name": "Fanling", | |
"nameZH": "粉嶺", | |
"lines": [ | |
"EAL" | |
] | |
}, | |
{ | |
"id": 30, | |
"code": "FOH", | |
"name": "Fortress Hill", | |
"nameZH": "炮台山", | |
"lines": [ | |
"ISL" | |
] | |
}, | |
{ | |
"id": 69, | |
"code": "FOT", | |
"name": "Fo Tan", | |
"nameZH": "火炭", | |
"lines": [ | |
"EAL" | |
] | |
}, | |
{ | |
"id": 51, | |
"code": "HAH", | |
"name": "Hang Hau", | |
"nameZH": "坑口", | |
"lines": [ | |
"TKL" | |
] | |
}, | |
{ | |
"id": 101, | |
"code": "HEO", | |
"name": "Heng On", | |
"nameZH": "恆安", | |
"lines": [ | |
"MOL" | |
] | |
}, | |
{ | |
"id": 36, | |
"code": "HFC", | |
"name": "Heng Fa Chuen", | |
"nameZH": "杏花邨", | |
"lines": [ | |
"ISL" | |
] | |
}, | |
{ | |
"id": 82, | |
"code": "HKU", | |
"name": "HKU", | |
"nameZH": "香港大學", | |
"lines": [ | |
"ISL" | |
] | |
}, | |
{ | |
"id": 39, | |
"code": "HOK", | |
"name": "Hong Kong", | |
"nameZH": "香港", | |
"lines": [ | |
"AEL", | |
"TCL" | |
] | |
}, | |
{ | |
"id": 44, | |
"code": "HOK", | |
"name": "Hong Kong", | |
"nameZH": "香港", | |
"lines": [ | |
"AEL", | |
"TCL" | |
] | |
}, | |
{ | |
"id": 84, | |
"code": "HOM", | |
"name": "Ho Man Tin", | |
"nameZH": "何文田", | |
"lines": [ | |
"KTL" | |
] | |
}, | |
{ | |
"id": 64, | |
"code": "HUH", | |
"name": "Hung Hom", | |
"nameZH": "紅磡", | |
"lines": [ | |
"EAL", | |
"WRL" | |
] | |
}, | |
{ | |
"id": 4, | |
"code": "JOR", | |
"name": "Jordan", | |
"nameZH": "佐敦", | |
"lines": [ | |
"TWL" | |
] | |
}, | |
{ | |
"id": 83, | |
"code": "KET", | |
"name": "Kennedy Town", | |
"nameZH": "堅尼地城", | |
"lines": [ | |
"ISL" | |
] | |
}, | |
{ | |
"id": 13, | |
"code": "KOB", | |
"name": "Kowloon Bay", | |
"nameZH": "九龍灣", | |
"lines": [ | |
"KTL" | |
] | |
}, | |
{ | |
"id": 8, | |
"code": "KOT", | |
"name": "Kowloon Tong", | |
"nameZH": "九龍塘", | |
"lines": [ | |
"EAL", | |
"KTL" | |
] | |
}, | |
{ | |
"id": 40, | |
"code": "KOW", | |
"name": "Kowloon", | |
"nameZH": "九龍", | |
"lines": [ | |
"AEL", | |
"TCL" | |
] | |
}, | |
{ | |
"id": 45, | |
"code": "KOW", | |
"name": "Kowloon", | |
"nameZH": "九龍", | |
"lines": [ | |
"AEL", | |
"TCL" | |
] | |
}, | |
{ | |
"id": 115, | |
"code": "KSR", | |
"name": "Kam Sheung Road", | |
"nameZH": "錦上路", | |
"lines": [ | |
"WRL" | |
] | |
}, | |
{ | |
"id": 22, | |
"code": "KWF", | |
"name": "Kwai Fong", | |
"nameZH": "葵芳", | |
"lines": [ | |
"TWL" | |
] | |
}, | |
{ | |
"id": 23, | |
"code": "KWH", | |
"name": "Kwai Hing", | |
"nameZH": "葵興", | |
"lines": [ | |
"TWL" | |
] | |
}, | |
{ | |
"id": 15, | |
"code": "KWT", | |
"name": "Kwun Tong", | |
"nameZH": "觀塘", | |
"lines": [ | |
"KTL" | |
] | |
}, | |
{ | |
"id": 21, | |
"code": "LAK", | |
"name": "Lai King", | |
"nameZH": "荔景", | |
"lines": [ | |
"TCL", | |
"TWL" | |
] | |
}, | |
{ | |
"id": 38, | |
"code": "LAT", | |
"name": "Lam Tin", | |
"nameZH": "藍田", | |
"lines": [ | |
"KTL" | |
] | |
}, | |
{ | |
"id": 19, | |
"code": "LCK", | |
"name": "Lai Chi Kok", | |
"nameZH": "荔枝角", | |
"lines": [ | |
"TWL" | |
] | |
}, | |
{ | |
"id": 88, | |
"code": "LET", | |
"name": "Lei Tung", | |
"nameZH": "利東", | |
"lines": [ | |
"SIL" | |
] | |
}, | |
{ | |
"id": 57, | |
"code": "LHP", | |
"name": "LOHAS Park", | |
"nameZH": "康城", | |
"lines": [ | |
"TKL" | |
] | |
}, | |
{ | |
"id": 78, | |
"code": "LMC", | |
"name": "Lok Ma Chau", | |
"nameZH": "落馬洲", | |
"lines": [ | |
"EAL" | |
] | |
}, | |
{ | |
"id": 9, | |
"code": "LOF", | |
"name": "Lok Fu", | |
"nameZH": "樂富", | |
"lines": [ | |
"KTL" | |
] | |
}, | |
{ | |
"id": 117, | |
"code": "LOP", | |
"name": "Long Ping", | |
"nameZH": "朗屏", | |
"lines": [ | |
"WRL" | |
] | |
}, | |
{ | |
"id": 76, | |
"code": "LOW", | |
"name": "Lo Wu", | |
"nameZH": "羅湖", | |
"lines": [ | |
"EAL" | |
] | |
}, | |
{ | |
"id": 20, | |
"code": "MEF", | |
"name": "Mei Foo", | |
"nameZH": "美孚", | |
"lines": [ | |
"TWL", | |
"WRL" | |
] | |
}, | |
{ | |
"id": 65, | |
"code": "MKK", | |
"name": "Mong Kok East", | |
"nameZH": "旺角東", | |
"lines": [ | |
"EAL" | |
] | |
}, | |
{ | |
"id": 6, | |
"code": "MOK", | |
"name": "Mong Kok", | |
"nameZH": "旺角", | |
"lines": [ | |
"KTL", | |
"TWL" | |
] | |
}, | |
{ | |
"id": 102, | |
"code": "MOS", | |
"name": "Ma On Shan", | |
"nameZH": "馬鞍山", | |
"lines": [ | |
"MOL" | |
] | |
}, | |
{ | |
"id": 53, | |
"code": "NAC", | |
"name": "Nam Cheong", | |
"nameZH": "南昌", | |
"lines": [ | |
"TCL", | |
"WRL" | |
] | |
}, | |
{ | |
"id": 31, | |
"code": "NOP", | |
"name": "North Point", | |
"nameZH": "北角", | |
"lines": [ | |
"ISL", | |
"TKL" | |
] | |
}, | |
{ | |
"id": 14, | |
"code": "NTK", | |
"name": "Ngau Tau Kok", | |
"nameZH": "牛頭角", | |
"lines": [ | |
"KTL" | |
] | |
}, | |
{ | |
"id": 86, | |
"code": "OCP", | |
"name": "Ocean Park", | |
"nameZH": "海洋公園", | |
"lines": [ | |
"SIL" | |
] | |
}, | |
{ | |
"id": 41, | |
"code": "OLY", | |
"name": "Olympic", | |
"nameZH": "奧運", | |
"lines": [ | |
"TCL" | |
] | |
}, | |
{ | |
"id": 52, | |
"code": "POA", | |
"name": "Po Lam", | |
"nameZH": "寶琳", | |
"lines": [ | |
"TKL" | |
] | |
}, | |
{ | |
"id": 16, | |
"code": "PRE", | |
"name": "Prince Edward", | |
"nameZH": "太子", | |
"lines": [ | |
"KTL", | |
"TWL" | |
] | |
}, | |
{ | |
"id": 32, | |
"code": "QUB", | |
"name": "Quarry Bay", | |
"nameZH": "鰂魚涌", | |
"lines": [ | |
"ISL", | |
"TKL" | |
] | |
}, | |
{ | |
"id": 70, | |
"code": "RAC", | |
"name": "Racecourse", | |
"nameZH": "馬場", | |
"lines": [ | |
"EAL" | |
] | |
}, | |
{ | |
"id": 99, | |
"code": "SHM", | |
"name": "Shek Mun", | |
"nameZH": "石門", | |
"lines": [ | |
"MOL" | |
] | |
}, | |
{ | |
"id": 75, | |
"code": "SHS", | |
"name": "Sheung Shui", | |
"nameZH": "上水", | |
"lines": [ | |
"EAL" | |
] | |
}, | |
{ | |
"id": 68, | |
"code": "SHT", | |
"name": "Sha Tin", | |
"nameZH": "沙田", | |
"lines": [ | |
"EAL" | |
] | |
}, | |
{ | |
"id": 26, | |
"code": "SHW", | |
"name": "Sheung Wan", | |
"nameZH": "上環", | |
"lines": [ | |
"ISL" | |
] | |
}, | |
{ | |
"id": 119, | |
"code": "SIH", | |
"name": "Siu Hong", | |
"nameZH": "兆康", | |
"lines": [ | |
"WRL" | |
] | |
}, | |
{ | |
"id": 7, | |
"code": "SKM", | |
"name": "Shek Kip Mei", | |
"nameZH": "石硤尾", | |
"lines": [ | |
"KTL" | |
] | |
}, | |
{ | |
"id": 35, | |
"code": "SKW", | |
"name": "Shau Kei Wan", | |
"nameZH": "筲箕灣", | |
"lines": [ | |
"ISL" | |
] | |
}, | |
{ | |
"id": 89, | |
"code": "SOH", | |
"name": "South Horizons", | |
"nameZH": "海怡半島", | |
"lines": [ | |
"SIL" | |
] | |
}, | |
{ | |
"id": 17, | |
"code": "SSP", | |
"name": "Sham Shui Po", | |
"nameZH": "深水埗", | |
"lines": [ | |
"TWL" | |
] | |
}, | |
{ | |
"id": 97, | |
"code": "STW", | |
"name": "Sha Tin Wai", | |
"nameZH": "沙田圍", | |
"lines": [ | |
"MOL" | |
] | |
}, | |
{ | |
"id": 54, | |
"code": "SUN", | |
"name": "Sunny Bay", | |
"nameZH": "欣澳", | |
"lines": [ | |
"DRL", | |
"TCL" | |
] | |
}, | |
{ | |
"id": 34, | |
"code": "SWH", | |
"name": "Sai Wan Ho", | |
"nameZH": "西灣河", | |
"lines": [ | |
"ISL" | |
] | |
}, | |
{ | |
"id": 81, | |
"code": "SYP", | |
"name": "Sai Ying Pun", | |
"nameZH": "西營盤", | |
"lines": [ | |
"ISL" | |
] | |
}, | |
{ | |
"id": 33, | |
"code": "TAK", | |
"name": "Tai Koo", | |
"nameZH": "太古", | |
"lines": [ | |
"ISL" | |
] | |
}, | |
{ | |
"id": 72, | |
"code": "TAP", | |
"name": "Tai Po Market", | |
"nameZH": "大埔墟", | |
"lines": [ | |
"EAL" | |
] | |
}, | |
{ | |
"id": 67, | |
"code": "TAW", | |
"name": "Tai Wai", | |
"nameZH": "大圍", | |
"lines": [ | |
"EAL", | |
"MOL" | |
] | |
}, | |
{ | |
"id": 29, | |
"code": "TIH", | |
"name": "Tin Hau", | |
"nameZH": "天后", | |
"lines": [ | |
"ISL" | |
] | |
}, | |
{ | |
"id": 49, | |
"code": "TIK", | |
"name": "Tiu Keng Leng", | |
"nameZH": "調景嶺", | |
"lines": [ | |
"KTL", | |
"TKL" | |
] | |
}, | |
{ | |
"id": 118, | |
"code": "TIS", | |
"name": "Tin Shui Wai", | |
"nameZH": "天水圍", | |
"lines": [ | |
"WRL" | |
] | |
}, | |
{ | |
"id": 50, | |
"code": "TKO", | |
"name": "Tseung Kwan O", | |
"nameZH": "將軍澳", | |
"lines": [ | |
"TKL" | |
] | |
}, | |
{ | |
"id": 100, | |
"code": "TSH", | |
"name": "Tai Shui Hang", | |
"nameZH": "大水坑", | |
"lines": [ | |
"MOL" | |
] | |
}, | |
{ | |
"id": 3, | |
"code": "TST", | |
"name": "Tsim Sha Tsui", | |
"nameZH": "尖沙咀", | |
"lines": [ | |
"TWL" | |
] | |
}, | |
{ | |
"id": 25, | |
"code": "TSW", | |
"name": "Tsuen Wan", | |
"nameZH": "荃灣", | |
"lines": [ | |
"TWL" | |
] | |
}, | |
{ | |
"id": 46, | |
"code": "TSY", | |
"name": "Tsing Yi", | |
"nameZH": "青衣", | |
"lines": [ | |
"AEL", | |
"TCL" | |
] | |
}, | |
{ | |
"id": 42, | |
"code": "TSY", | |
"name": "Tsing Yi", | |
"nameZH": "青衣", | |
"lines": [ | |
"AEL", | |
"TCL" | |
] | |
}, | |
{ | |
"id": 43, | |
"code": "TUC", | |
"name": "Tung Chung", | |
"nameZH": "東涌", | |
"lines": [ | |
"TCL" | |
] | |
}, | |
{ | |
"id": 120, | |
"code": "TUM", | |
"name": "Tuen Mun", | |
"nameZH": "屯門", | |
"lines": [ | |
"WRL" | |
] | |
}, | |
{ | |
"id": 24, | |
"code": "TWH", | |
"name": "Tai Wo Hau", | |
"nameZH": "大窩口", | |
"lines": [ | |
"TWL" | |
] | |
}, | |
{ | |
"id": 73, | |
"code": "TWO", | |
"name": "Tai Wo", | |
"nameZH": "太和", | |
"lines": [ | |
"EAL" | |
] | |
}, | |
{ | |
"id": 114, | |
"code": "TWW", | |
"name": "Tsuen Wan West", | |
"nameZH": "荃灣西", | |
"lines": [ | |
"WRL" | |
] | |
}, | |
{ | |
"id": 71, | |
"code": "UNI", | |
"name": "University", | |
"nameZH": "大學", | |
"lines": [ | |
"EAL" | |
] | |
}, | |
{ | |
"id": 27, | |
"code": "WAC", | |
"name": "Wan Chai", | |
"nameZH": "灣仔", | |
"lines": [ | |
"ISL" | |
] | |
}, | |
{ | |
"id": 87, | |
"code": "WCH", | |
"name": "Wong Chuk Hang", | |
"nameZH": "黃竹坑", | |
"lines": [ | |
"SIL" | |
] | |
}, | |
{ | |
"id": 888, | |
"code": "WEK", | |
"name": "Hong Kong West Kowloon", | |
"nameZH": "香港西九龍", | |
"lines": [ | |
"HSR" | |
] | |
}, | |
{ | |
"id": 85, | |
"code": "WHA", | |
"name": "Whampoa", | |
"nameZH": "黃埔", | |
"lines": [ | |
"KTL" | |
] | |
}, | |
{ | |
"id": 103, | |
"code": "WKS", | |
"name": "Wu Kai Sha", | |
"nameZH": "烏溪沙", | |
"lines": [ | |
"MOL" | |
] | |
}, | |
{ | |
"id": 10, | |
"code": "WTS", | |
"name": "Wong Tai Sin", | |
"nameZH": "黃大仙", | |
"lines": [ | |
"KTL" | |
] | |
}, | |
{ | |
"id": 48, | |
"code": "YAT", | |
"name": "Yau Tong", | |
"nameZH": "油塘", | |
"lines": [ | |
"KTL", | |
"TKL" | |
] | |
}, | |
{ | |
"id": 5, | |
"code": "YMT", | |
"name": "Yau Ma Tei", | |
"nameZH": "油麻地", | |
"lines": [ | |
"KTL", | |
"TWL" | |
] | |
}, | |
{ | |
"id": 116, | |
"code": "YUL", | |
"name": "Yuen Long", | |
"nameZH": "元朗", | |
"lines": [ | |
"WRL" | |
] | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment