← 返回
未分类 中文

Hong Kong Green Minibus Arrival

Real-time arrival information for Hong Kong Green Mini Buses (GMB). Supports fuzzy stop name matching and multi-region route lookup.
香港绿色小巴(GMB)实时到站信息。支持模糊站点名称匹配及跨区路线查询。
stevenho1394 stevenho1394 来源
未分类 clawhub v1.0.0 1 版本 99701.5 Key: 无需
★ 0
Stars
📥 334
下载
💾 0
安装
1
版本
#latest

概述

Implementation Notes

API Endpoints (Base URL: https://data.etagmb.gov.hk)

  • GET /route - List all routes grouped by region (HKI, KLN, NT)
  • GET /route/{region}/{route} - Get route details including directions (route_seq) and route_id
  • GET /stop-route/{stop_id} - Get stop names (name_en, name_tc) and the routes serving that stop
  • GET /eta/stop/{stop_id} - Get real-time ETA for all routes at that stop

Additionally, static route data is sourced from:

  • https://hkbus.github.io/hk-bus-crawling/routeFareList.min.json - Contains mapping from route identifiers to stop ID sequences for GMB (and other operators).

Script: gmb_arrival.py

Key functions:

  • searchRoutes(route): Queries /route, finds which regions contain this route number. If none, suggests similar route numbers.
  • get_gmb_arrival(route, direction, stop_name, region):
  1. Fetch /route/{region}/{route} to obtain route_id and the direction details (origin/destination names).
  2. Construct composite route key using the origin/destination English names and load from routeFareList.json to get the ordered list of stop IDs for that direction.
  3. For each stop ID along the route, fetch /stop-route/{stop_id} to retrieve stop names (cached).
  4. Match the user-provided stop_name (case-insensitive) exactly; if not found, perform fuzzy matching and return suggestions.
  5. Once stop ID is identified, call /eta/stop/{stop_id}.
  6. Filter ETA entries for the desired route_id and route_seq (direction), extract up to 3 next arrival timestamps, format as "HH:MM HKT".
  7. Return JSON: { "stopId": "...", "stopName": "...", "arrivals": [ "17:35 HKT", ... ] }.

Caching Strategy

  • routes_all.json: All route list (1 hour)
  • route_details.json: Route details per region/route (5 minutes)
  • routeFareList.json: Static route-to-stop mapping (1 day)
  • stop_names.json: Stop ID to names mapping (1 week)
  • ETA responses: 30 seconds

Cache files stored in data/ subdirectory.

Error Handling

  • Network errors and API failures are caught and reported in JSON with an error field.
  • If route not found: returns found: false with suggestions array.
  • If stop name not found: returns error with suggestions mapping suggestion → stop ID.
  • If no active ETA: returns empty arrivals array with an informative message.

Usage Example (Command Line)

# Search route
python3 gmb_arrival.py searchRoutes 1
# => {"route":"1","found":true,"regions":["HKI","KLN","NT"]}

# Get arrival for route 1 direction 1 (The Peak → Central) at "Hong Kong Station Minibus Terminus" in HKI
python3 gmb_arrival.py getGMBArrival 1 1 "Hong Kong Station Minibus Terminus" HKI
# => {"stopId":"20014492","stopName":"Hong Kong Station Minibus Terminus","arrivals":["14:38 HKT","14:45 HKT","14:52 HKT"]}

Notes

  • Direction sequence: For each GMB route, the API defines route_seq 1 and 2. Use searchRoutes then inspect route details to determine which sequence corresponds to your desired direction, or use getGMBArrival directly if you know the direction number.
  • Stop names are matched case-insensitively. Chinese or English names both work.
  • The static routeFareList may lag behind official data by up to one day but is generally reliable.
  • Rate limits: The script caches aggressively to minimize API calls; still, avoid excessive polling (ETA updates every minute).

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-31 17:16 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

data-analysis

Hong Kong Horse Racing

stevenho1394
获取香港赛马会赛马卡,包含马匹详情、赔率及每场推荐投注。支持日期选择、级别筛选、排除项、单...
★ 0 📥 558
life-service

Hong Kong Supermarket Shopping

stevenho1394
帮助用户在香港超市查找最优优惠,实时使用消费者委员会价格数据,查询任意商品的最低价门店及当前价格。
★ 0 📥 679
life-service

KMB and LWB Bus Arrivals

stevenho1394
使用官方 API 按路线、方向和站点实时获取 KMB 公交到站时间,精准提供下班车 ETA。
★ 0 📥 816