Skip to content

Instantly share code, notes, and snippets.

@j-min
Last active September 15, 2019 09:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j-min/454177149e8e5e4d2090bfe3e3d9f504 to your computer and use it in GitHub Desktop.
Save j-min/454177149e8e5e4d2090bfe3e3d9f504 to your computer and use it in GitHub Desktop.
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
Copy link
Author

j-min commented Sep 9, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment