Last active
September 15, 2019 09:43
-
-
Save j-min/454177149e8e5e4d2090bfe3e3d9f504 to your computer and use it in GitHub Desktop.
Korean express train ticket reservation example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
Author
j-min
commented
Sep 9, 2019
•
- The original project (https://github.com/dotaitch/SRTpy) seems to be deleted 😢
- Update (2019.09.15): https://github.com/bluesid/SRTpy seems to be a copy of the original project.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment