Usage of korail for attacking targets without prior mutual consent is illegal. It's the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program. Only use for educational purposes.
Korail (www.letskorail.com) wrapper for Python.
This project was inspired from korail of devxoul.
The documentation is available at here
To install korail2, simply:
$ pip install korail2
Or, you can use:
$ easy_install korail2
Or, you can also install manually:
$ git clone git://github.com/carpedm20/korail2.git
$ cd korail2
$ python setup.py install
First, you need to create a Korail object.
>>> from korail2 import *
>>> korail = Korail("12345678", YOUR_PASSWORD) # with membership number
>>> korail = Korail("carpedm20@gmail.com", YOUR_PASSWORD) # with email
>>> korail = Korail("010-9964-xxxx", YOUR_PASSWORD) # with phone numberIf you do not want login automatically,
>>> korail = Korail("12345678", YOUR_PASSWORD, auto_login=False)
>>> korail.login()
TrueWhen you want change ID using existing object,
>>> korail.login(ANOTHER_ID, ANOTHER_PASSWORD)
TrueYou can search train schedules search_train and search_train_allday methods.
search_trainreturns 10 results max. Faster thansearch_train_allday.search_train_alldayreturns all results after the time.search_train_alldayusessearch_trainrepeatedly.
search_train and search_train_allday methods take these arguments:
- dep : A departure station in Korean ex) '์์ธ'
- arr : A arrival station in Korean ex) '๋ถ์ฐ'
- date : (optional) A departure date in
yyyyMMddformat - time : (optional) A departure time in
hhmmssformat - train_type: (optional) A type of train. You can use constants of TrainType class here.
default value is TrainType.ALL.
- 00: TrainType.KTX - KTX
- 01: TrainType.SAEMAEUL - ์๋ง์ํธ
- 02: TrainType.MUGUNGHWA - ๋ฌด๊ถํํธ
- 03: TrainType.TONGGEUN - ํต๊ทผ์ด์ฐจ
- 04: TrainType.NURIRO - ๋๋ฆฌ๋ก
- 05: TrainType.ALL - ์ ์ฒด
- 06: TrainType.AIRPORT - ๊ณตํญ์งํต
- 07: TrainType.KTX_SANCHEON - KTX-์ฐ์ฒ
- 08: TrainType.ITX_SAEMAEUL - ITX-์๋ง์
- 09: TrainType.ITX_CHEONGCHUN - ITX-์ฒญ์ถ
- (optional) passengers=None : List of Passenger Objects. None means 1 AdultPassenger.
- (optional) include_no_seats=False : When True, a result includes trains which has no seats.
Below is a sample usage of search_train:
>>> dep = '์์ธ'
>>> arr = '๋๋๊ตฌ'
>>> date = '20140815'
>>> time = '144000'
>>> trains = korail.search_train(dep, arr, date, time)
[[KTX] 8์ 3์ผ, ์์ธ~๋ถ์ฐ(11:00~13:42) ํน์ค,์ผ๋ฐ์ค ์์ฝ๊ฐ๋ฅ,
[ITX-์๋ง์] 8์ 3์ผ, ์์ธ~๋ถ์ฐ(11:04~16:00) ์ผ๋ฐ์ค ์์ฝ๊ฐ๋ฅ,
[KTX] 8์ 3์ผ, ์์ธ~๋ถ์ฐ(12:00~14:43) ํน์ค,์ผ๋ฐ์ค ์์ฝ๊ฐ๋ฅ,
[KTX] 8์ 3์ผ, ์์ธ~๋ถ์ฐ(12:30~15:13) ํน์ค,์ผ๋ฐ์ค ์์ฝ๊ฐ๋ฅ,
[KTX] 8์ 3์ผ, ์์ธ~๋ถ์ฐ(12:40~15:45) ํน์ค,์ผ๋ฐ์ค ์์ฝ๊ฐ๋ฅ,
[KTX] 8์ 3์ผ, ์์ธ~๋ถ์ฐ(12:55~15:26) ํน์ค,์ผ๋ฐ์ค ์์ฝ๊ฐ๋ฅ,
[KTX] 8์ 3์ผ, ์์ธ~๋ถ์ฐ(13:00~15:37) ํน์ค,์ผ๋ฐ์ค ์์ฝ๊ฐ๋ฅ,
[KTX] 8์ 3์ผ, ์์ธ~๋ถ์ฐ(13:10~15:58) ํน์ค,์ผ๋ฐ์ค ์์ฝ๊ฐ๋ฅ]When you want to see sold-out trains.
>>> trains = korail.search_train(dep, arr, date, time, include_no_seats=True)
[[KTX] 8์ 3์ผ, ์์ธ~๋ถ์ฐ(11:00~13:42) ํน์ค,์ผ๋ฐ์ค ์์ฝ๊ฐ๋ฅ,
[ITX-์๋ง์] 8์ 3์ผ, ์์ธ~๋ถ์ฐ(11:04~16:00) ์ผ๋ฐ์ค ์์ฝ๊ฐ๋ฅ,
[๋ฌด๊ถํํธ] 8์ 3์ผ, ์์ธ~๋ถ์ฐ(11:08~16:54) ์
์ ์ญ๋ฐ๋งค์ค,
[ITX-์๋ง์] 8์ 3์ผ, ์์ธ~๋ถ์ฐ(11:50~16:50) ์
์ ์ญ๋ฐ๋งค์ค,
[KTX] 8์ 3์ผ, ์์ธ~๋ถ์ฐ(12:00~14:43) ํน์ค,์ผ๋ฐ์ค ์์ฝ๊ฐ๋ฅ,
[KTX] 8์ 3์ผ, ์์ธ~๋ถ์ฐ(12:30~15:13) ํน์ค,์ผ๋ฐ์ค ์์ฝ๊ฐ๋ฅ,
[KTX] 8์ 3์ผ, ์์ธ~๋ถ์ฐ(12:40~15:45) ํน์ค,์ผ๋ฐ์ค ์์ฝ๊ฐ๋ฅ,
[KTX] 8์ 3์ผ, ์์ธ~๋ถ์ฐ(12:55~15:26) ํน์ค,์ผ๋ฐ์ค ์์ฝ๊ฐ๋ฅ,
[KTX] 8์ 3์ผ, ์์ธ~๋ถ์ฐ(13:00~15:37) ํน์ค,์ผ๋ฐ์ค ์์ฝ๊ฐ๋ฅ,
[KTX] 8์ 3์ผ, ์์ธ~๋ถ์ฐ(13:10~15:58) ํน์ค,์ผ๋ฐ์ค ์์ฝ๊ฐ๋ฅ]passengers is a list(or tuple) of Passeger Objects.
By this, you can search for multiple passengers.
There are 3 types of Passengers now, AdultPassenger, ChildPassenger and SeniorPassenger.
# for 1 adult, 1 child
>>> psgrs = [AdultPassenger(), ChildPassenger()]
# for 2 adults, 1 child
>>> psgrs = [AdultPassenger(2), ChildPassenger(1)]
# ditto. They are being added each other by same group.
>>> psgrs = [AdultPassenger(), AdultPassenger(), ChildPassenger()]
# for 2 adults, 1 child, 1 senior
>>> psgrs = [AdultPassenger(2), ChildPassenger(), SeniorPassenger()]
# for 1 adult, It supports negative count or zero count.
# But it uses passengers which the sum is greater than zero.
>>> psgrs = [AdultPassenger(2), AdultPassenger(-1)]
>>> psgrs = [AdultPassenger(), SeniorPassenger(0)]
# Nothing
>>> psgrs = [AdultPassenger(0), SeniorPassenger(0)]
# then search or reserve train
>>> trains = korail.search_train(dep, arr, date, time, passengers=psgrs)
...
>>> korail.reserve(trains[0], psgrs)
...You can get your tickets with tickets method.
>>> trains = korail.search_train(dep, arr, date, time)
>>> seat = korail.reserve(trains[0])
>>> seat
[KTX] 8์ 23์ผ, ์์ธ~๋๋๊ตฌ(15:30~17:19) 42500์(1์), ๊ตฌ์
๊ธฐํ 8์ 18์ผ 14:05Multiple.
>>> trains = korail.search_train(dep, arr, date, time)
>>> seat = korail.reserve(trains[0], passengers=psgrs)
>>> seat
[KTX] 8์ 23์ผ, ์์ธ~๋๋๊ตฌ(15:30~17:19) 42500์(3์), ๊ตฌ์
๊ธฐํ 8์ 18์ผ 14:05When tickets are not enough much for passengers, it raises SoldOutError.
If you want to select priority of seat grade, general or special, There are 4 options in ReserveOption class.
- GENERAL_FIRST : Economic than Comfortable.
- GENERAL_ONLY : Reserve only general seats. You are poorman ;-)
- SPECIAL_FIRST : Comfortable than Economic.
- SPECIAL_ONLY : Richman.
>>> korail.reserve(trains[0], psgrs, ReserveOption.GENERAL_ONLY)You can get your tickes with tickets method.
>>> reservations = korail.reservations()
>>> reservations
[[KTX] 8์ 23์ผ, ์์ธ~๋๋๊ตฌ(14:55~16:45) 42500์(1์), ๊ตฌ์
๊ธฐํ 8์ 18์ผ 14:03,
[๋ฌด๊ถํํธ] 8์ 23์ผ, ์์ธ~๋๋๊ตฌ(15:03~18:48) 21100์(1์), ๊ตฌ์
๊ธฐํ 8์ 18์ผ 14:03,
[KTX] 8์ 23์ผ, ์์ธ~๋๋๊ตฌ(15:30~17:19) 42500์(1์), ๊ตฌ์
๊ธฐํ 8์ 18์ผ 14:05]You can also cancel your reservation using Reservation Object from reservations() call.
>>> korail.cancel(reservations[0])You can see your ticket list with tickets method.
You can get the list of paid tickes with tickets method.
>>> korail = Korail("12345678", YOUR_PASSWORD, want_feedback=True)
>>> tickets = korail.tickets()
์ ์๋ฐ๋งค์ฒ๋ฆฌ,์ ์๋ฐ๊ถ์ฒ๋ฆฌ # You can see these feedbacks when `want_feedback` is True.
>>> print tickets
[[KTX] 8์ 10์ผ, ๋๋๊ตฌ~์ธ์ฐ(09:26~09:54) => 5ํธ 4A, 13900์]- Implement payment API
Source codes are distributed under BSD license.
Taehoon Kim / @carpedm20
Hanson Kim / @sng2c