irail-cli
CLI for Belgian railways (NMBS/SNCB) via iRail API. No authentication required.
Quick Start
CODEBLOCK0
Authentication
None required. iRail API is public and free to use.
Core Rules
- 1. Always use
--json when parsing output programmatically - Station names are flexible - accepts partial matches, quotes for multi-word
- Time format - HH:MM (24-hour), date format YYYY-MM-DD
- Language options - nl, fr, en, de (default: nl)
Output Formats
| Flag | Format | Use case |
|---|
| (default) | Table | User-facing with colors |
| INLINECODE1 |
JSON | Agent parsing, scripting |
Colors indicate: red = delays, yellow = platform changes.
Workflows
Liveboard (Departures/Arrivals)
CODEBLOCK1
Connections (Route Planning)
CODEBLOCK2
Stations
CODEBLOCK3
Vehicle (Train Info)
CODEBLOCK4
Composition (Train Cars)
CODEBLOCK5
Disturbances
CODEBLOCK6
Scripting Examples
CODEBLOCK7
Environment Variables
| Variable | Description |
|---|
| INLINECODE2 | Default language (nl, fr, en, de) |
| INLINECODE3 |
Default to JSON output |
|
NO_COLOR | Disable colored output |
Language Options
| Code | Language |
|---|
| INLINECODE5 | Dutch (default) |
| INLINECODE6 |
French |
|
en | English |
|
de | German |
CODEBLOCK8
Command Reference
| Command | Description |
|---|
| INLINECODE9 | Station departures/arrivals |
| INLINECODE10 |
Route planning between stations |
|
stations | List/search stations |
|
vehicle | Train information and stops |
|
composition | Train car composition |
|
disturbances | Service disruptions |
|
completion | Shell completions |
Common Patterns
Check if train is delayed
CODEBLOCK9
Get connection with transfers
CODEBLOCK10
Find direct trains only
CODEBLOCK11
Guidelines
- - No authentication needed - API is public
- Be mindful of API usage in loops - add delays between requests
- Station names are case-insensitive and support partial matching
- Delay values are in seconds (divide by 60 for minutes)
Installation
CODEBLOCK12
irail-cli
通过 iRail API 为比利时铁路(NMBS/SNCB)提供的命令行工具。无需认证。
快速开始
bash
车站出发信息
irail liveboard Brugge
查找连接
irail connections Brugge Leuven
查看中断信息
irail disturbances
认证
无需认证。 iRail API 是公开且免费使用的。
核心规则
- 1. 始终使用 --json 进行程序化输出解析
- 车站名称灵活 - 支持部分匹配,多词名称使用引号
- 时间格式 - HH:MM(24小时制),日期格式 YYYY-MM-DD
- 语言选项 - nl、fr、en、de(默认:nl)
输出格式
| 标志 | 格式 | 使用场景 |
|---|
| (默认) | 表格 | 面向用户,带颜色 |
| --json |
JSON | 代理解析、脚本编写 |
颜色表示:红色 = 延误,黄色 = 站台变更。
工作流程
实时看板(出发/到达)
bash
车站出发信息
irail liveboard Brugge
irail liveboard Brussel-Centraal
到达信息(而非出发)
irail liveboard Brugge --arrivals
指定日期/时间
irail liveboard Brugge --time 09:00 --date 2025-02-15
脚本使用的 JSON 格式
irail liveboard Brugge --json
不同语言
irail liveboard Brugge --lang en
连接(路线规划)
bash
查找路线
irail connections Brugge Leuven
指定出发时间
irail connections Brugge Leuven --time 09:00
按到达时间(而非出发时间)
irail connections Brugge Leuven --time 14:00 --arrive-by
更多结果
irail connections Brugge Leuven --results 10
解析用的 JSON 格式
irail connections Brugge Leuven --json
车站
bash
列出所有车站
irail stations
搜索车站
irail stations --search bruss
irail stations --search gent
脚本使用的 JSON 格式
irail stations --json
车辆(列车信息)
bash
显示列车信息
irail vehicle IC1832
包含所有停靠站
irail vehicle IC1832 --stops
JSON 输出
irail vehicle IC1832 --json
编组(列车车厢)
bash
显示列车编组(座位、设施)
irail composition S51507
irail composition IC1832
解析用的 JSON 格式
irail composition S51507 --json
中断信息
bash
所有当前中断
irail disturbances
仅计划内施工
irail disturbances --type planned
仅计划外中断
irail disturbances --type disturbance
脚本使用的 JSON 格式
irail disturbances --json
脚本示例
bash
获取前往目的地的下一班列车
irail connections Brugge Leuven --json | jq -r .[0].departure
查找车站 ID
irail stations --search brussel --json | jq -r .[0].id
检查实时看板是否有延误
irail liveboard Brugge --json | jq [.[] | select(.delay > 0)] | length
获取下一班出发列车的站台
irail liveboard Brugge --json | jq -r .[0].platform
列出所有中断
irail disturbances --json | jq -r .[].title
环境变量
| 变量 | 描述 |
|---|
| IRAILLANG | 默认语言(nl、fr、en、de) |
| IRAILJSON |
默认使用 JSON 输出 |
| NO_COLOR | 禁用彩色输出 |
语言选项
法语 |
| en | 英语 |
| de | 德语 |
bash
irail liveboard Brugge --lang fr
irail connections Brugge Leuven --lang en
命令参考
| 命令 | 描述 |
|---|
| liveboard | 车站出发/到达信息 |
| connections |
车站间路线规划 |
| stations | 列出/搜索车站 |
| vehicle | 列车信息和停靠站 |
| composition | 列车车厢编组 |
| disturbances | 服务中断信息 |
| completion | Shell 补全 |
常见模式
检查列车是否延误
bash
irail vehicle IC1832 --json | jq .delay // 0
获取含换乘的连接
bash
irail connections Brugge Leuven --json | jq .[0].vias | length
仅查找直达列车
bash
irail connections Brugge Leuven --json | jq [.[] | select(.vias == null or (.vias | length) == 0)]
使用指南
- - 无需认证 - API 公开可用
- 在循环中使用 API 时注意频率 - 在请求之间添加延迟
- 车站名称不区分大小写,支持部分匹配
- 延误值以秒为单位(除以 60 转换为分钟)
安装
bash
brew install dedene/tap/irail