Package: korail2
Korail (www.letskorail.com) wrapper for Python.This project was inspired fromkorailofdevxoul.DocumentationThe documentation is available athereInstallingTo install korail2, simply:$ pip install korail2Or, you can use:$ easy_install korail2Or, you can also install manually:$ git clone git://github.com/carpedm20/korail2.git
$ cd korail2
$ python setup.py installUsing1. LoginFirst, you need to create a Korail object.>>>fromkorail2import*>>>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)True2. Search trainYou can search train schedulessearch_trainandsearch_train_alldaymethods.search_trainreturns 10 results max. Faster thansearch_train_allday.search_train_alldayreturns all results after the time.search_train_alldayusessearch_trainrepeatedly.search_trainandsearch_train_alldaymethods take these
arguments:dep : A departure station in Korean ex) ‘서울’arr : A arrival station in Korean ex) ‘부산’date : (optional) A departure date inyyyyMMddformattime : (optional) A departure time inhhmmssformattrain_type: (optional) A type of train. You can use constants of
TrainType class here. default value is TrainType.ALL.00: TrainType.KTX - KTX01: 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 ofsearch_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)특실,일반실예약가능]2-1. Aboutpassengersargumentpassengersis 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)...3. Make a reservationYou can get your tickets withticketsmethod.>>>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)4. Show reservationsYou can get your tickes withticketsmethod.>>>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]5. Cancel reservationYou can also cancel your reservation using Reservation Object from
reservations() call.>>>korail.cancel(reservations[0])6. Get tickets already paidYou can see your ticket list withticketsmethod. You can get the
list of paid tickes withticketsmethod.>>>korail=Korail("12345678",YOUR_PASSWORD,want_feedback=True)>>>tickets=korail.tickets()정상발매처리,정상발권처리# You can see these feedbacks when `want_feedback` is True.>>>printtickets[[KTX]8월10일,동대구~울산(09:26~09:54)=>5호4A,13900원]How do I get the Korail APIExtract Korail apk from mobile phoneDecompile apk usingdex2jarRead a jar code usingjdguiEdit a smaili codeRecompile a new Korail apk usingapktoolKey signing withmotizen-signUpload and run a new Korail apkCapture packets and analyze the APITodoImplement payment APILicenseSource codes are distributed under BSD license.AuthorTaehoon Kim / [@carpedm20](http://carpedm20.github.io/about/) Hanson Kim
/ [@sng2c](https://github.com/sng2c)