HK Bus ETA / MTR ETA
Use the bundled script to answer Hong Kong bus route + stop queries and MTR heavy rail station + direction queries quickly and consistently.
Quick start
Run the bundled script from the skill directory:
Bus
Legacy bus invocation still works:
CODEBLOCK0
Equivalent explicit subcommand:
CODEBLOCK1
Examples:
CODEBLOCK2
MTR heavy rail
Structured station-to-station query:
CODEBLOCK3
Natural-language prompt parsing:
CODEBLOCK4
Examples:
CODEBLOCK5
Or use an absolute path rooted at the installed skill folder if needed.
Extraction workflow
A. Bus queries
- 1. Extract the route first.
- Examples:
74X,
A41,
20,
NA31.
- 2. Extract the stop or area keyword next.
- Accept stop names, stations, estates, landmarks, districts, malls, piers, airports, hospitals, or short area names.
- Treat messages like
74X 九龍灣幾耐到,
A41 青衣站有冇車,
城巴20啟德幾時到 as route + place queries.
- 3. Infer operator if the user says it explicitly.
-
九巴 →
--operator kmb
-
龍運 /
Long Win →
--operator lwb
-
城巴 /
Citybus →
--operator citybus
- If the user does not say, default to KMB. If the route obviously looks like a Citybus-only route or the first attempt fails, retry with
--operator citybus.
- 4. If the user hints at direction or destination, pass it through.
-
去機場,
往尖沙咀,
outbound,
返去 often imply direction disambiguation.
- Use
--direction outbound or
--direction inbound when the user's wording clearly prefers one side.
- 5. Run the bus query.
- If multiple stop matches appear, summarize each clearly with operator, direction, stop name, sequence, and destination.
- Report ETA in natural language, usually in minutes first.
- If no match appears, say so and ask for a more specific stop name, estate, station, or direction.
B. MTR heavy rail queries
- 1. Detect that the prompt is station + destination/direction based, not bus-route based.
- Strong triggers:
X站去Y方向,
X去Y下一班,
往Y有冇車,
X站到Y幾點有車.
- 2. Extract the origin station and target station/direction anchor.
- Examples:
-
火炭站去金鐘方向幾點有車 → origin
火炭, target
金鐘
-
金鐘去北角下一班港島線幾時 → origin
金鐘, target
北角, line hint
ISL
-
荃灣站往中環方向有冇車 → origin
荃灣, target
中環
- 3. If the message names a line, pass it as
--line.
- Common mappings:
-
東鐵線 →
EAL
-
港島線 →
ISL
-
荃灣線 →
TWL
-
觀塘線 →
KTL
-
將軍澳線 →
TKL
-
屯馬線 →
TML
-
東涌線 →
TCL
-
機場快綫 /
Airport Express →
AEL
-
南港島線 →
SIL
-
迪士尼線 →
DRL
- 4. Prefer
mtr-text when the user phrased the request naturally and it fits the built-in patterns. - If parsing feels ambiguous, use
mtr <origin> <destination> directly instead of guessing from a messy sentence. - The script resolves line/station mapping from the official MTR lines-and-stations CSV, then filters trains from the official MTR schedule endpoint that actually pass the requested target station.
- If multiple line candidates remain, list them instead of pretending certainty.
Reporting guidance
- - Prefer a concise answer like
74X 喺九龍灣下一班大約 3 分鐘後到。 or INLINECODE61 - If there are multiple likely matches, list them instead of guessing.
- If there is no ETA, say that clearly rather than implying no service.
- Use
--json only when structured output is easier for follow-up processing.
Operator / data-source notes
- -
kmb: official data.etabus.gov.hk KMB endpoints. - INLINECODE65 : handled through the same KMB-family endpoint structure used by Long Win routes in the KMB dataset.
- INLINECODE66 : official
rt.data.gov.hk/v2/transport/citybus endpoints. - INLINECODE68 : official
rt.data.gov.hk/v1/transport/mtr/getSchedule.php endpoint plus the official MTR lines/stations CSV from opendata.mtr.com.hk.
Matching behavior
- - Bus stop matching is flexible substring/token matching against Traditional Chinese, Simplified Chinese, and English stop names.
- MTR station matching is flexible against Chinese name, English name, and station code.
- For MTR, destination matching is by path logic, not just terminal-code equality: trains are kept only if their displayed destination would carry the passenger past the requested target station on that line.
- If the user gives only a broad area or a very ambiguous station name, refine from the returned candidates.
Scope and limitations
- - Bus coverage here remains KMB, Long Win, and Citybus only.
- MTR coverage added here is heavy rail only. Light Rail, buses branded under MTR, and airport/feeder bus services are out of scope.
- INLINECODE71 handles common natural-language forms like
X站去Y方向幾點有車, X去Y下一班, and X往Y有冇車; unusual phrasings may need manual extraction with mtr <origin> <destination>. - Very ambiguous interchange stations or cross-line phrasing may return multiple candidates and need clarification.
- The script does not plan multi-leg journeys; it answers next-train ETA for a specific origin station toward a target station on a line that passes both.
scripts/
- -
scripts/hk_bus_eta.py — query KMB/LWB/Citybus bus ETA, and MTR heavy rail ETA using either structured station arguments or a short natural-language MTR prompt.
香港巴士抵站時間 / 港鐵抵站時間
使用配套腳本快速且一致地回答香港巴士路線+車站查詢及港鐵重鐵車站+方向查詢。
快速開始
從技能目錄執行配套腳本:
巴士
舊式巴士調用方式仍然有效:
bash
python3 scripts/hkbuseta.py <路線> <車站關鍵詞>
等效的明確子命令:
bash
python3 scripts/hkbuseta.py bus <路線> <車站關鍵詞>
範例:
bash
python3 scripts/hkbuseta.py 74X 九龍灣
python3 scripts/hkbuseta.py bus A41 青衣 --operator lwb
python3 scripts/hkbuseta.py bus 20 啟德 --operator citybus
python3 scripts/hkbuseta.py bus 20 Kai Tak --operator citybus --direction outbound
python3 scripts/hkbuseta.py bus 74X 九龍灣 --direction outbound
python3 scripts/hkbuseta.py bus 74X 九龍灣 --json
港鐵重鐵
結構化的車站到車站查詢:
bash
python3 scripts/hkbuseta.py mtr <起點站> <終點站>
自然語言提示解析:
bash
python3 scripts/hkbuseta.py mtr-text 火炭站去金鐘方向幾點有車
範例:
bash
python3 scripts/hkbuseta.py mtr 火炭 金鐘
python3 scripts/hkbuseta.py mtr 火炭 金鐘 --line EAL
python3 scripts/hkbuseta.py mtr-text 火炭站去金鐘方向幾點有車
python3 scripts/hkbuseta.py mtr-text 金鐘去北角下一班港島線幾時
python3 scripts/hkbuseta.py mtr-text 荃灣站往中環方向有冇車 --json
如有需要,也可使用已安裝技能資料夾的絕對路徑。
提取工作流程
A. 巴士查詢
- 1. 首先提取路線。
- 範例:74X、A41、20、NA31。
- 2. 接著提取車站或區域關鍵詞。
- 接受車站名稱、車站、屋苑、地標、地區、商場、碼頭、機場、醫院或簡短區域名稱。
- 將 74X 九龍灣幾耐到、A41 青衣站有冇車、城巴20啟德幾時到 等訊息視為路線+地點查詢。
- 3. 如果使用者明確說出營運商,則推斷營運商。
- 九巴 → --operator kmb
- 龍運 / Long Win → --operator lwb
- 城巴 / Citybus → --operator citybus
- 如果使用者未說明,預設為九巴。如果路線明顯是城巴專營路線或首次嘗試失敗,則以 --operator citybus 重試。
- 4. 如果使用者提示方向或目的地,則傳遞該資訊。
- 去機場、往尖沙咀、outbound、返去 通常暗示需要區分方向。
- 當使用者的措辭明顯偏向某一方向時,使用 --direction outbound 或 --direction inbound。
- 5. 執行巴士查詢。
- 如果出現多個車站匹配結果,則清楚總結每個結果,包括營運商、方向、車站名稱、順序和目的地。
- 以自然語言報告預計抵達時間,通常先以分鐘為單位。
- 如果沒有匹配結果,則說明情況並要求提供更具體的車站名稱、屋苑、車站或方向。
B. 港鐵重鐵查詢
- 1. 檢測提示是基於車站+目的地/方向,而非基於巴士路線。
- 強烈觸發詞:X站去Y方向、X去Y下一班、往Y有冇車、X站到Y幾點有車。
- 2. 提取起點站和目標站/方向錨點。
- 範例:
- 火炭站去金鐘方向幾點有車 → 起點 火炭,目標 金鐘
- 金鐘去北角下一班港島線幾時 → 起點 金鐘,目標 北角,路線提示 ISL
- 荃灣站往中環方向有冇車 → 起點 荃灣,目標 中環
- 3. 如果訊息中提及路線名稱,則以 --line 傳遞。
- 常見對應:
- 東鐵線 → EAL
- 港島線 → ISL
- 荃灣線 → TWL
- 觀塘線 → KTL
- 將軍澳線 → TKL
- 屯馬線 → TML
- 東涌線 → TCL
- 機場快綫 / Airport Express → AEL
- 南港島線 → SIL
- 迪士尼線 → DRL
- 4. 當使用者以自然方式提出請求且符合內建模式時,優先使用 mtr-text。
- 如果解析感覺不明確,則直接使用 mtr <起點> <終點>,而非從雜亂的句子中猜測。
- 腳本從官方港鐵路線及車站 CSV 解析路線/車站對應,然後從官方港鐵時刻表端點篩選實際經過所請求目標車站的列車。
- 如果仍有多個路線候選項,則列出它們,而非假裝確定。
報告指引
- - 優先使用簡潔的回答,例如 74X 喺九龍灣下一班大約 3 分鐘後到。 或 火炭去金鐘方向下一班東鐵線大約 2 分鐘後到,4 號月台。
- 如果有多個可能的匹配結果,則列出它們,而非猜測。
- 如果沒有預計抵達時間,則清楚說明,而非暗示沒有服務。
- 僅在結構化輸出更便於後續處理時使用 --json。
營運商/資料來源說明
- - kmb:官方 data.etabus.gov.hk 九巴端點。
- lwb:透過九巴資料集中龍運路線使用的同一九巴系列端點結構處理。
- citybus:官方 rt.data.gov.hk/v2/transport/citybus 端點。
- mtr:官方 rt.data.gov.hk/v1/transport/mtr/getSchedule.php 端點,加上來自 opendata.mtr.com.hk 的官方港鐵路線/車站 CSV。
匹配行為
- - 巴士站匹配是針對繁體中文、簡體中文和英文車站名稱的靈活子字串/詞元匹配。
- 港鐵車站匹配是針對中文名稱、英文名稱和車站代碼的靈活匹配。
- 對於港鐵,目的地匹配是基於路徑邏輯,而非僅是終點站代碼相等:僅保留那些顯示的目的地能讓乘客在該路線上行經所請求目標車站的列車。
- 如果使用者僅提供廣泛區域或非常模糊的車站名稱,則從返回的候選項中進行細化。
範圍與限制
- - 此處的巴士覆蓋範圍僅限於九巴、龍運和城巴。
- 此處新增的港鐵覆蓋範圍僅限於重鐵。輕鐵、港鐵品牌巴士以及機場/接駁巴士服務不在範圍內。
- mtr-text 處理常見的自然語言形式,如 X站去Y方向幾點有車、X去Y下一班 和 X往Y有冇車;不常見的措辭可能需要使用 mtr <起點> <終點> 進行手動提取。
- 非常模糊的轉乘站或跨路線措辭可能返回多個候選項,需要澄清。
- 腳本不規劃多段行程;它回答從特定起點站到同一路線經過的目標站的下一班列車預計抵達時間。
scripts/
- - scripts/hkbuseta.py — 使用結構化的車站參數或簡短的港鐵自然語言提示,查詢九巴/龍運/城巴巴士預計抵達時間,以及港鐵重鐵預計抵達時間。