介绍
# UK Trains
查询 National Rail Darwin API 以获取实时列车出发和到达信息。
## 设置
需要免费的 Darwin API 令牌: 1. 在 https://realtime.nationalrail.co.uk/OpenLDBWSRegistration/ 注册 2. 在环境中设置 `NATIONAL_RAIL_TOKEN`(或在 skills.entries.uk-trains.apiKey 中配置)
## 命令
```bash # Departures ./scripts/trains.py departures PAD ./scripts/trains.py departures PAD to OXF --rows 5
# Arrivals ./scripts/trains.py arrivals MAN ./scripts/trains.py arrivals MAN from EUS
# Station search ./scripts/trains.py search paddington ./scripts/trains.py search kings ```
## 车站代码
使用 3 字母 CRS 代码: - `PAD` = London Paddington - `EUS` = London Euston - `KGX` = London Kings Cross - `VIC` = London Victoria - `WAT` = London Waterloo - `MAN` = Manchester Piccadilly - `BHM` = Birmingham New Street - `EDB` = Edinburgh Waverley - `GLC` = Glasgow Central - `BRI` = Bristol Temple Meads - `LDS` = Leeds - `LIV` = Liverpool Lime Street - `RDG` = Reading - `OXF` = Oxford - `CBG` = Cambridge
## 响应格式
JSON 包含: - `locationName`、`crs` - 车站信息 - `messages[]` - 服务警报 - `trainServices[]` - 列车列表: - `std`/`sta` - 计划出发/到达时间 - `etd`/`eta` - 预计时间("On time"、"Delayed" 或实际时间) - `platform` - 站台号码 - `operator` - 列车运营公司 - `destination[].name` - 终点站 - `isCancelled`、`cancelReason`、`delayReason` - 扰动信息
## 消息模板
使用此紧凑格式进行 WhatsApp/聊天回复:
``` 🚂 {Origin} → {Destination}
*{dep} → {arr}* │📍{platform} │ 🚃 {coaches} {status}
*{dep} → {arr}* │📍{platform} │ 🚃 {coaches} {status} ```
### 元素 - **头部:** 🚂 表情符号 + 起点 → 终点 - **时间:** 粗体,出发 → 到达时间 - **站台:** 📍 + 号码(如果未知则为 "TBC") - **车厢:** 🚃 + 空格 + 号码 - **状态:** - ✅ 准点 - ⚠️ 延误(预计 {时间}) - ❌ 已取消 — {原因} - 🔄 始发站
### 示例
``` 🚂 Hemel Hempstead → Euston
*20:18 → 20:55* │📍4 │ 🚃 4 ✅ On time
*20:55 → 21:30* │📍4 │ 🚃 12 ✅ On time
*21:11 → 21:41* │📍4 │ 🚃 8 ✅ On time ```
### 获取到达时间
要显示到达时间,请进行两次 API 调用: 1. `departures {origin} to {dest}` — 获取出发时间 + 服务 ID 2. `arrivals {dest} from {origin}` — 获取到达时间
通过 serviceID 中的数字前缀匹配服务(例如,`4748110HEMLHMP_` 匹配 `4748110EUSTON__`)。
### 注意事项 - 用空行分隔每个服务 - 如果编组数据不可用,则省略车厢信息 - 对于延误,显示预计时间:`⚠️ Delayed (exp 20:35)`