跳至內容
tdx-tw
使用指南

軌道

查詢臺鐵、高鐵、捷運、輕軌與阿里山林鐵。

軌道系統以代碼指定:

代碼系統代碼系統
TRA臺鐵THSR高鐵
TRTC臺北捷運NTMC新北捷運環狀線
NTDLRT淡海輕軌NTALRT安坑輕軌
TYMC桃園捷運TMRT臺中捷運
KRTC高雄捷運KLRT高雄輕軌
TRTCMG貓空纜車AFR阿里山林鐵

查詢一個車站

station = client.rail_station("TRA", "1000")

for train in station.trains():
    print(train.train_number, train.destination, train.departure_time, train.delay_minutes)

trains() 取得臺鐵與捷運的即時列車,高鐵則為今天的班次。車站代碼可用 client.rail.stations(system) 查詢。同一個物件還提供:

方法內容
info()車站資料
exits()、facilities()出入口與設施
journeys_to(station_id)今天或指定日期前往另一站的車次
fares_to(station_id)前往另一站的票價

起訖站時刻與票價

from datetime import date, timedelta

tomorrow = date.today() + timedelta(days=1)
for journey in client.rail.journeys("THSR", "1000", "1070", tomorrow):
    print(journey.train.number, journey.origin.departure_time, journey.destination.arrival_time)

for fare in client.rail.fares("THSR", origin="1000", destination="1070"):
    for price in fare.prices:
        print(price.ticket_type, price.fare_class, price.cabin_class, price.price)

列車動態

for status in client.rail.train_status():
    print(status.train_number, status.station_name, status.delay_minutes)

for entry in client.rail.metro_board("TRTC"):
    print(entry.station_name, entry.headsign, entry.estimate_seconds)

座位

高鐵座位可依起訖站、車站或日期查詢,臺鐵座位可依車次或時段查詢:

for seat in client.rail.seat_status("THSR", "1000", "1070", tomorrow):
    print(seat)
類別方法
車站stations、station_exits、station_facilities、station_transfers、metro_platforms、transfer_groups
路線lines、routes、line_stations、route_stations、shapes、line_transfers、line_networks
時刻表daily_timetables、recurring_timetables、special_timetables、station_timetables、daily_station_timetables、journeys、taiwan_railway_journey_timetables、metro_first_last、metro_frequencies、metro_travel_times、timetable_dates
動態station_board、train_status、train_delays、metro_board、metro_positions、alerts、news
座位seat_status、seat_status_by_time、high_speed_seat_board、high_speed_seat_legs、high_speed_seat_statuses、free_seating_cars
票價與距離fares、fares_by_station_name、segment_distances、journey_distances

所有參數與欄位見軌道 API。