-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
115 lines (104 loc) · 4.01 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import time
# import winsound as sd
from korail2 import *
from datetime import datetime
from SRT import SRT
# def beepsound():
# fr = 2500 # range : 37 ~ 32767
# du = 30000 # 1000 ms ==1second
# sd.Beep(fr, du) # winsound.Beep(frequency, duration)
def send_telegram_message(reservation):
bot_token = "6794329002:AAEiWc8Ji5dN3-X2kU_W7qJJBTD_jQRVWPY"
chat_id = "-4014888163"
text = f"예약성공 10분 안에 예매해야함:{reservation}"
url = f"https://api.telegram.org/bot{bot_token}/sendMessage"
data = {
"chat_id": chat_id,
"text": text
}
response = requests.post(url, data=data)
return response.json()
def reserve_ktx():
# KORAIL_ID = '1463203706'
# KORAIL_PW = 'ahfmsek2!'
KORAIL_ID = '1260025642'
KORAIL_PW = 'Eos5k907!@'
PUSHOVER_APP_TOKEN = 'APP_TOKEN'
PUSHOVER_USER_TOKEN = 'USER_TOKEN'
DEP = '서울'
ARV = '구포'
DEP_DATE = '20240210'
DEP_TIME = '125000'
LIMIT_DEP_TIME_STRING = '132000'
LIMIT_DEP_TIME_DATETIME = datetime.strptime(LIMIT_DEP_TIME_STRING, "%H%M%S")
PSGRS = [AdultPassenger(1)]
TRAIN_TYPE = TrainType.KTX
k = Korail(KORAIL_ID, KORAIL_PW, auto_login=False)
if not k.login():
print("login fail")
is_continue = True
while is_continue:
try:
trains = k.search_train(DEP, ARV, DEP_DATE, DEP_TIME, passengers=PSGRS, train_type=TRAIN_TYPE)
print(f"train_list:{trains}")
if len(trains) > 0:
for idx, train in enumerate(trains):
DEP_TIME_DATETIME = datetime.strptime(train.dep_time, "%H%M%S")
if DEP_TIME_DATETIME <= LIMIT_DEP_TIME_DATETIME:
k.reserve(trains[idx], passengers=PSGRS)
message = f"예약성공- 기차시간:{train.dep_time}//{datetime.now()}"
print(message)
send_telegram_message(message)
is_continue = False
else:
print(f"예약안함- 기차시간 초과:{train.dep_time}//{datetime.now()}")
if not is_continue:
pass
# beepsound()
time.sleep(0.5)
except Exception as e:
if "No Results" in str(e):
print(f"No Results//{datetime.now().time()},{e}")
time.sleep(0.5)
continue
if "잔여석없음" in str(e):
print(f"잔여석없음//{datetime.now().time()}")
time.sleep(0.5)
continue
k.login()
print(f"로그인 다시 시도 error:{e}")
if "매크로" in str(e):
print("매크로 감지로 1분 휴식")
time.sleep(60)
continue
continue
def reserve_srt():
srt = SRT("010-2366-0150", "Eos5k907!@")
dep = '평택지제'
arr = '울산(통도사)'
date = '20231126'
start_time = '170000'
time_limit = '170500'
is_continue = True
if srt.is_login:
while is_continue:
try:
trains = srt.search_train(dep, arr, date, start_time,
time_limit
)
print(f"train_list:{trains}")
if len(trains) > 0:
for idx, train in enumerate(trains):
reservation = srt.reserve(trains[idx])
print(f"예약성공:{reservation}")
send_telegram_message(reservation)
is_continue = False
with open(file="reserve.log", mode="a+") as f:
f.write(f"{reservation}//{datetime.now()}")
time.sleep(0.5)
except Exception as e:
print(f"로그인 다시 시도 error:{e}")
srt = SRT("010-2366-0150", "Eos5k907!@")
continue
if __name__ == "__main__":
reserve_ktx()