From d4e18307076ea9a21b5d1ea0d764ecf22cc6c5af Mon Sep 17 00:00:00 2001 From: wlt233 <1486185683@qq.com> Date: Wed, 20 Nov 2024 09:27:51 +0800 Subject: [PATCH] fix bug --- conf.ini | 2 +- cookie.py | 1 + ticket.py | 47 +++++++++++++++++++++++++++++------------------ 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/conf.ini b/conf.ini index ea54961..7dd249f 100644 --- a/conf.ini +++ b/conf.ini @@ -5,7 +5,7 @@ interval1 = 1000 interval2 = 200 username = theo.bal.d2.79.8@gmail.com password = Nijigasaki1214 -cookie = ACEUCI=1; SCOUTER=x3ufs2bk0gtfnb; ACEFCID=UID-67389CBAB720FFCEC9F932B0; ACEUACS=undefined; _ga=GA1.1.2049452611.1731763387; mxuid=adfc2c71-4270-470e-8f3b-2a2fd4a3d69d; cro_uv_ymd=20241116; AUBS2A39876863068=1731763386998975740%7C2%7C1731763386998975740%7C1%7C17317633868984IOCBA%7C1; TKGLOBAL_SES=AAAAksQgCx3HrMbZ-C8Q4a8OF7LZwjSSMbHXQ_gkXKNPtaBZ0DP_QSmdTuK0lQveeSXo4BSwxtvRo9OD4WViYdsSPQEj5pRbvUsm6d6jYslyjnRoDpZwQsCV0CjGsyvIM_091D1w0eBvx6rVbjVnBnxllrnc-a-oWhNCcl3K5HFCw8PZbOevceZeq0ehbH8V9P_nhIOF2OyAhZc4stxhX23MdrQ.A; TKGLOBAL_CHK=AAAA3IJ6EckOmfIjG5SsEq5qztrr2Ci3F_OcQTu08pzfHOH716Y1fLsBshnBYMkuQnq3bWsz54bKfN_J7ysH5worAENBJYnoojtwXTZOy-zXH9SGBZheCRTD2eHTsWZFFryeygVKcdQ-bWdwM4bh2o1saOwwTWbQXrCY01KPpTtPehesqsXWufdrmFEex_V1Q0Pu4PpjOJLFiOkSprULOsmfBkLzI8IzOzrJVTonn3VYx7pry3PQhn3GSufXb57qF6brdTCjjU-o6_R2RWs0AmC5hf-pF2bCz-Nz47dW_IRxuTh7.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0blyfE2vaEPPlAjz0WWu1CyQElwW7xOPNMJbAvG0C3Xetd0uRVNKIcOmkrntjsUdVJw1%2B0cRWQQtVUaFVFw8q8%2Bl%2BCM%2BVUMqV8Z65cXCbYJZvCFaP7ouPKvQQWFVeI2n7FoY%2FeQnXiFHSybX57ta9SO6JcX4QqExHibxz5TzGmkBPXQb8Lzzm%2FTwdAmduRJdEHneggoMOvM4wHdO2xTJtaWZJ58a2nsIdLVu%2BzXqYsR090dooQVwlz1PpV2j71UjFikGlhOwZKuK5VpOlmS0QHLBJMRwFjDiDiEs8I7b6d2zdA9AQ0%2FlJBhI7Or7uWpLHAbkYqQA8zTogOctJNClb02588JtPZreQbU856A3cPqb7%2Fm%2F1612XUuDfV8Vsd7wq3qLNmCLkusAwKuK5JzpD2wZM6F71axRirFVrFqYfE4EnHAxXv1ypG%2FbMW50axnDvhXDSn%2FcGtvYtDqDQp1GS4iuEFACw%3D%3D; TKGLOBAL_MASKING_ID="the*************@gmail.com"; TKLINK_CAPTCHA_KEY=a8158c12-611d-46fb-80c3-0b9c60fb0b3b; TKLINK_CHK_NO="440HDivEvWtEVVh/EDZOWA=="; _ga_PVZX56STJJ=GS1.1.1731763387.1.1.1731763396.51.0.0; ASBS2A39876863068=1731763386998975740%7C1731763396197348795%7C1731763386998975740%7C0%7Cbookmark; ARBS2A39876863068=httpswwwticketlinkcokrglobalzhreserveplanschedule1740993756bookmark; wcCookieV2=103.151.173.97_T_132595_WC; TKLINK_CHK_KEY="ib9jMGXRtT88MAqAlQB40n9Uq+v7KAdAHrzqv3owngNS12qAsUkRGXUroqKOHbZRR921ddScoA1uw47YaqYByw==" +cookie = ACEUCI=1; SCOUTER=z6ph4u1deb204u; ACEFCID=UID-673D38B48105D9BC9EA2E369; ACEUACS=undefined; mxuid=b2a36a92-6b16-4cc6-80fb-dcb1d78feb7f; _ga=GA1.1.1008724382.1732065461; cro_uv_ymd=20241120; AUBS2A39876863068=1732065460168009428%7C2%7C1732065460168009428%7C1%7C17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mthIWA%3D%3D; TKGLOBAL_MASKING_ID="the*************@gmail.com"; TKLINK_CAPTCHA_KEY=7ef90da8-7f27-43b7-ae84-e137a9797e83; TKLINK_CHK_NO="YA4lkNLqiTppsaxqa01UMQ=="; _ga_PVZX56STJJ=GS1.1.1732065461.1.1.1732065470.51.0.0; ASBS2A39876863068=1732065460168009428%7C1732065470362990697%7C1732065460168009428%7C0%7Cbookmark; ARBS2A39876863068=httpswwwticketlinkcokrglobalzhreserveplanschedule1740993756bookmark; wcCookieV2=103.151.173.99_T_545239_WC; TKLINK_CHK_KEY="lIyMcI96w4HioEx1dAFT2/Ij5QA4kzsfV7S6hzqsfdsOmfD3zeAJl3dOnDKupxGN48JrkQZDNJRSW2TYi+dygQ==" [seat] seats = diff --git a/cookie.py b/cookie.py index 333adc4..3f1e003 100644 --- a/cookie.py +++ b/cookie.py @@ -36,6 +36,7 @@ def get_cookie(username, password, headless): driver.switch_to.window(driver.window_handles[-1]) driver.get("https://www.ticketlink.co.kr/global/zh/reserve/plan/schedule/1740993756") + #if not headless: time.sleep(10) driver.find_element(by=By.ID,value="captcha_img").screenshot("./data/captcha.jpg") with open("./data/captcha.jpg", "rb") as f: diff --git a/ticket.py b/ticket.py index fb317aa..697fdb3 100644 --- a/ticket.py +++ b/ticket.py @@ -21,8 +21,9 @@ from cookie import get_cookie logger.add("./data/log/{time}.log") # seat data -COOKIE, USERNAME, PASSWORD, HEADLESS, PROXY = "", "", "", "", "" +COOKIE, USERNAME, PASSWORD, HEADLESS, PROXY, SEATS_SPEC = "", "", "", "", "", "" SEATS_IGNORE = [] +COOKIE_TIME = time.time() with open("./data/able_d1.json", "r") as f: able_d1 = json.load(f) with open("./data/able_d2.json", "r") as f: @@ -127,21 +128,23 @@ async def search_seats(seats): for k, l in able_d1.items(): for seat in l: seat_id = str(seat["logicalSeatId"]) - if "FLOOR" in seat['mapInfo'] and not sold_d1[seat_id]: - if not seat_id in SEATS_IGNORE: - logger.success(f"发现内场票:d1 {seat['mapInfo']} {seat_id}") - seats[1].append(seat) - else: - logger.warning(f"发现内场票:d1 {seat['mapInfo']} 在忽略列表中") + if not "FLOOR" in seat['mapInfo'] or sold_d1[seat_id]: continue + if int(seat["mapInfo"].split()[3][:-1]) >= 8: continue + if not seat_id in SEATS_IGNORE: + logger.success(f"发现内场票:d1 {seat['mapInfo']} {seat_id}") + seats[1].append(seat) + else: + logger.warning(f"发现内场票:d1 {seat['mapInfo']} 在忽略列表中") for k, l in able_d2.items(): for seat in l: seat_id = str(seat["logicalSeatId"]) - if "FLOOR" in seat['mapInfo'] and not sold_d2[seat_id]: - if not seat_id in SEATS_IGNORE: - logger.success(f"发现内场票:d2 {seat['mapInfo']} {seat_id}") - seats[2].append(seat) - else: - logger.warning(f"发现内场票:d2 {seat['mapInfo']} 在忽略列表中") + if not "FLOOR" in seat['mapInfo'] or sold_d2[seat_id]: continue + if int(seat["mapInfo"].split()[3][:-1]) >= 8: continue + if not seat_id in SEATS_IGNORE: + logger.success(f"发现内场票:d2 {seat['mapInfo']} {seat_id}") + seats[2].append(seat) + else: + logger.warning(f"发现内场票:d2 {seat['mapInfo']} 在忽略列表中") @@ -168,7 +171,7 @@ def parse_seat(seat): } async def lock_ticket(day, seats): - global COOKIE + global COOKIE, COOKIE_TIME if not seats: return if len(seats) > 4: seats = seats[:4] day_code = 552446605 if day == 1 else 1740993756 @@ -222,14 +225,15 @@ async def lock_ticket(day, seats): logger.error(msg) except: logger.critical(f"锁票失败!可能是 cookie 过期了!正在尝试更新 cookie!") - update_cookie() + if time.time() - COOKIE_TIME > 60: + update_cookie() # cookie def update_cookie(): - global COOKIE, USERNAME, PASSWORD, HEADLESS + global COOKIE, USERNAME, PASSWORD, HEADLESS, COOKIE_TIME for i in range(5): COOKIE = get_cookie(USERNAME, PASSWORD, HEADLESS) if COOKIE: @@ -239,6 +243,7 @@ def update_cookie(): with open("./conf.ini", 'w', encoding="utf8") as f: config.write(f) logger.info("cookie 更新成功!") + COOKIE_TIME = time.time() return logger.critical("登陆失败,无法获取 cookie!") os.system("pause") @@ -249,6 +254,7 @@ def update_cookie(): # main loop state machine async def loop(interval1, interval2, seats): + global SEATS_SPEC while True: if not (seats[1] or seats[2]): t = time.time() @@ -265,9 +271,14 @@ async def loop(interval1, interval2, seats): await asyncio.sleep(interval1 / 1000) else: event_loop = asyncio.get_event_loop() + t = time.time() while True: event_loop.create_task(lock_ticket(1, seats[1])) event_loop.create_task(lock_ticket(2, seats[2])) + if not SEATS_SPEC and time.time() - t > 30: + seats[1].clear() + seats[2].clear() + break if not (seats[1] or seats[2]): break else: @@ -293,8 +304,8 @@ if __name__ == "__main__": PROXY = config.get("conf", "proxy") or None interval1 = int(config.get("conf", "interval1") or 10000) interval2 = int(config.get("conf", "interval2") or 1000) - seats_str = config.get("seat", "seats") - seats_list = seats_str.split(",") if seats_str else [] + SEATS_SPEC = config.get("seat", "seats") + seats_list = SEATS_SPEC.split(",") if SEATS_SPEC else [] ignore_list = config.get("seat", "ignore").split(",") logger.info(f"cookie = {COOKIE[:50]}...") logger.info(f"proxy = {PROXY}")