Skip to content

Instantly share code, notes, and snippets.

@j-min j-min/korail_example.py
Last active Sep 15, 2019

Embed
What would you like to do?
Korean express train ticket reservation example
# pip install korail2
# https://github.com/carpedm20/korail2
from korail2 import Korail, NoResultsError, KorailError
from time import sleep
import os
# Login
EMAIL = '' # email
PW = '' # password
korail = Korail(EMAIL, PW)
# Ticket Information
dep = '서울' # 출발
arr = '구포' # 도착
date = '20190909' # YYYYMMDD
time = '110000' # HHMMSS
train_type = '100' # KTX
# Reservation
while True:
try:
trains = korail.search_train(dep, arr, date, time, train_type=train_type)
reservation = korail.reserve(trains[0])
print(reservation)
os.system('say -v Yuna "티켓이 예약되었어요!"')
break
except NoResultsError:
sleep(1)
continue
except KorailError:
sleep(1)
continue
# pip install SRTpy heconvert
# https://github.com/bluesid/SRTpy (originally from https://github.com/dotaitch/SRTpy)
from SRTpy import Srt
from heconvert.converter import h2e
from time import sleep
# Login
EMAIL = '' # email
PW = '' # password
srt = Srt(EMAIL, PW)
# Ticket Information
dep = '동대구' # 출발
arr = '수서' # 도착
date = '20180926' # YYYYMMDD
time = '110000' # HHMMSS
# Reservation
while True:
trains = srt.search(h2e(dep), h2e(arr), date, time)
if len(trains) > 0:
reservation = srt.reserve(trains[0])
print(reservation)
break
sleep(1)
@j-min

This comment has been minimized.

Copy link
Owner Author

commented Sep 9, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.