名称: swiss-transport
描述: 瑞士公共交通实时信息。适用于查询瑞士境内的火车、巴士、有轨电车或船只时刻表。支持车站搜索、发车时刻表、从A地到B地的行程规划以及班次详情查询。可用于类似“从苏黎世出发的下一班火车是几点?”、“如何从伯尔尼前往日内瓦?”或“显示巴塞尔SBB站的发车班次”等查询。
主页: https://transport.opendata.ch
使用官方 transport.opendata.ch API 查询瑞士公共交通(SBB、BLS、ZVV 等)。
curl -s "https://transport.opendata.ch/v1/locations?query=Zürich" | jq -r '.stations[] | "\(.name) (\(.id))"'
curl -s "https://transport.opendata.ch/v1/stationboard?station=Zürich%20HB&limit=10" | \
jq -r '.stationboard[] | "\(.stop.departure[11:16]) \(.category) \(.number) → \(.to)"'
curl -s "https://transport.opendata.ch/v1/connections?from=Zürich&to=Bern&limit=3" | \
jq -r '.connections[] | "出发: \(.from.departure[11:16]) | 到达: \(.to.arrival[11:16]) | 时长: \(.duration[3:]) | 换乘次数: \(.transfers)"'
curl -s "https://transport.opendata.ch/v1/connections?from=Zürich%20HB&to=Bern&limit=1" | \
jq '.connections[0].sections[] | {from: .departure.station.name, to: .arrival.station.name, departure: .departure.departure, arrival: .arrival.arrival, transport: .journey.category, line: .journey.number}'
/v1/locations - 搜索车站curl "https://transport.opendata.ch/v1/locations?query=<station-name>"
参数:
- query(必需):要搜索的车站名称
- type(可选):按类型筛选(station、address、poi)
/v1/stationboard - 发车时刻表curl "https://transport.opendata.ch/v1/stationboard?station=<station>&limit=<number>"
参数:
- station(必需):车站名称或ID
- limit(可选):结果数量(默认40)
- transportations[](可选):按交通类型筛选(ice_tgv_rj、ec_ic、ir、re_d、ship、s_sn_r、bus、cableway、arz_ext、tramway_underground)
- datetime(可选):ISO格式的日期/时间
/v1/connections - 行程规划器curl "https://transport.opendata.ch/v1/connections?from=<start>&to=<destination>&limit=<number>"
参数:
- from(必需):起点站
- to(必需):终点站
- via[](可选):途经站
- date(可选):日期(YYYY-MM-DD)
- time(可选):时间(HH:MM)
- isArrivalTime(可选):0(出发时间,默认)或1(到达时间)
- limit(可选):班次数量(最多16个)
使用 scripts/journey.py 进行格式化的行程规划:
python3 scripts/journey.py "Zürich HB" "Bern"
python3 scripts/journey.py "Basel" "Lugano" --limit 5