From 2220c32cf21bcb0b20fca3903e2f808bda501d11 Mon Sep 17 00:00:00 2001 From: CHUN YU YAO Date: Thu, 12 Jan 2023 19:41:49 +0800 Subject: [PATCH] 2023-01-12 ver.3, support only ocr captcha without auto submit. --- chrome_tixcraft.py | 37 +++++++++++++++++++--------- settings.json | 2 +- settings.py | 60 +++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 81 insertions(+), 18 deletions(-) diff --git a/chrome_tixcraft.py b/chrome_tixcraft.py index 03cb4ac..7385440 100644 --- a/chrome_tixcraft.py +++ b/chrome_tixcraft.py @@ -48,7 +48,7 @@ except Exception as exc: import ssl ssl._create_default_https_context = ssl._create_unverified_context -CONST_APP_VERSION = u"MaxBot (2023.01.12)2版" +CONST_APP_VERSION = u"MaxBot (2023.01.12)3版" CONST_HOMEPAGE_DEFAULT = "https://tixcraft.com" @@ -61,7 +61,6 @@ CONST_SELECT_OPTIONS_ARRAY = [CONST_FROM_TOP_TO_BOTTOM, CONST_FROM_BOTTOM_TO_TOP CONT_STRING_1_SEATS_REMAINING = [u'@1 seat(s) remaining',u'剩餘 1@',u'@1 席残り'] - def get_app_root(): # 讀取檔案裡的參數值 basis = "" @@ -1608,7 +1607,17 @@ def tixcraft_verify(driver, presale_code): return ret -def tixcraft_manully_keyin_verify_code(driver, ocr_answer = ""): +def tixcraft_toast(driver, message): + toast_element = None + try: + my_css_selector = ".remark-word" + toast_element = driver.find_element(By.CSS_SELECTOR, my_css_selector) + if not toast_element is None: + driver.execute_script("arguments[0].innerHTML='%s';" % message, toast_element) + except Exception as exc: + print("find toast element fail") + +def tixcraft_manully_keyin_verify_code(driver, answer = "", auto_submit = False): is_verifyCode_editing = False # manually keyin verify code. @@ -1630,10 +1639,14 @@ def tixcraft_manully_keyin_verify_code(driver, ocr_answer = ""): if is_visible: try: form_verifyCode.click() - if len(ocr_answer)==4: - #print("start to auto submit.") - form_verifyCode.send_keys(ocr_answer) + #print("start to fill answer.") + form_verifyCode.send_keys(answer) + if auto_submit: form_verifyCode.send_keys(Keys.ENTER) + else: + driver.execute_script("document.getElementById(\"TicketForm_verifyCode\").select();") + tixcraft_toast(driver, "※ Press Enter if answer is: " + answer) + is_verifyCode_editing = True except Exception as exc: print("click form_verifyCode fail, tring to use javascript.") @@ -1648,7 +1661,7 @@ def tixcraft_manully_keyin_verify_code(driver, ocr_answer = ""): return is_verifyCode_editing #PS: credit to LinShihJhang's share -def tixcraft_auto_ocr(driver, ocr): +def tixcraft_auto_ocr(driver, ocr, ocr_captcha_with_submit): print("start to ddddocr") orc_answer = None if not ocr is None: @@ -1674,9 +1687,10 @@ def tixcraft_auto_ocr(driver, ocr): if not orc_answer is None: print("orc_answer:", orc_answer) if len(orc_answer)==4: - tixcraft_manully_keyin_verify_code(driver, orc_answer) + tixcraft_manully_keyin_verify_code(driver, answer = orc_answer) else: tixcraft_manully_keyin_verify_code(driver) + tixcraft_toast(driver, "※ Ocr fail...") else: tixcraft_manully_keyin_verify_code(driver) @@ -1684,7 +1698,8 @@ def tixcraft_ticket_main(driver, config_dict, ocr): is_finish_checkbox_click = False auto_check_agree = config_dict["auto_check_agree"] - ocr_captcha_enable = config_dict["ocr_captcha"] + ocr_captcha_enable = config_dict["ocr_captcha"]["enable"] + ocr_captcha_with_submit = config_dict["ocr_captcha"]["auto_submit"] if auto_check_agree: tixcraft_ticket_agree(driver) @@ -1742,7 +1757,7 @@ def tixcraft_ticket_main(driver, config_dict, ocr): if not ocr_captcha_enable: is_verifyCode_editing = tixcraft_manully_keyin_verify_code(driver) else: - tixcraft_auto_ocr(driver, ocr) + tixcraft_auto_ocr(driver, ocr, ocr_captcha_with_submit) is_verifyCode_editing = True print("is_finish_checkbox_click:", is_finish_checkbox_click) @@ -5138,7 +5153,7 @@ def main(): ocr = None try: - if config_dict["ocr_captcha"]: + if config_dict["ocr_captcha"]["enable"]: ocr = ddddocr.DdddOcr() except Exception as exc: pass diff --git a/settings.json b/settings.json index 73c74a8..e8347a7 100644 --- a/settings.json +++ b/settings.json @@ -1 +1 @@ -{"homepage": "https://tixcraft.com", "browser": "chrome", "language": "\u7e41\u9ad4\u4e2d\u6587", "ticket_number": 2, "pass_1_seat_remaining": true, "auto_check_agree": true, "ocr_captcha": true, "kktix": {"auto_press_next_step_button": true, "auto_fill_ticket_number": true, "area_mode": "from top to bottom", "area_keyword_1": "", "area_keyword_1_and": "", "area_keyword_2": "", "area_keyword_2_and": "", "auto_guess_options": false, "user_guess_string": ""}, "tixcraft": {"date_auto_select": {"enable": true, "date_keyword": "", "mode": "from top to bottom"}, "area_auto_select": {"enable": true, "area_keyword_1": "", "area_keyword_2": "", "area_keyword_3": "", "area_keyword_4": "", "mode": "from top to bottom"}, "pass_date_is_sold_out": true, "auto_reload_coming_soon_page": true, "presale_code": ""}, "advanced": {"play_captcha_sound": {"enable": true, "filename": "ding-dong.wav"}, "facebook_account": "", "kktix_account": "", "adblock_plus_enable": false}, "debug": false} \ No newline at end of file +{"homepage": "https://tixcraft.com", "browser": "chrome", "language": "\u7e41\u9ad4\u4e2d\u6587", "ticket_number": 2, "pass_1_seat_remaining": true, "auto_check_agree": true, "ocr_captcha": {"enable": true, "auto_submit": false}, "kktix": {"auto_press_next_step_button": true, "auto_fill_ticket_number": true, "area_mode": "from top to bottom", "area_keyword_1": "", "area_keyword_1_and": "", "area_keyword_2": "", "area_keyword_2_and": "", "auto_guess_options": false, "user_guess_string": ""}, "tixcraft": {"date_auto_select": {"enable": true, "date_keyword": "", "mode": "from top to bottom"}, "area_auto_select": {"enable": true, "area_keyword_1": "", "area_keyword_2": "", "area_keyword_3": "", "area_keyword_4": "", "mode": "from top to bottom"}, "pass_date_is_sold_out": true, "auto_reload_coming_soon_page": true, "presale_code": ""}, "advanced": {"play_captcha_sound": {"enable": true, "filename": "ding-dong.wav"}, "facebook_account": "", "kktix_account": "", "adblock_plus_enable": true}, "debug": false} \ No newline at end of file diff --git a/settings.py b/settings.py index 5d0c404..5d22e55 100644 --- a/settings.py +++ b/settings.py @@ -19,7 +19,7 @@ import json import webbrowser import pyperclip -CONST_APP_VERSION = u"MaxBot (2023.01.12)2版" +CONST_APP_VERSION = u"MaxBot (2023.01.12)3版" CONST_FROM_TOP_TO_BOTTOM = u"from top to bottom" CONST_FROM_BOTTOM_TO_TOP = u"from bottom to top" @@ -77,6 +77,7 @@ def load_translate(): en_us["area_keyword_4"] = 'Area Keyword #4' en_us["pass_1_seat_remaining"] = 'Pass 1 seat remaining' en_us["ocr_captcha"] = 'OCR captcha' + en_us["ocr_captcha_with_submit"] = 'After guess auto submit' en_us["preference"] = 'Preference' en_us["advanced"] = 'Advanced' @@ -133,6 +134,7 @@ def load_translate(): zh_tw["area_keyword_4"] = '區域關鍵字 #4' zh_tw["pass_1_seat_remaining"] = '避開「剩餘 1」的區域' zh_tw["ocr_captcha"] = '猜測驗證碼' + zh_tw["ocr_captcha_with_submit"] = '猜測後自動送出' zh_tw["preference"] = '偏好設定' zh_tw["advanced"] = '進階設定' @@ -189,6 +191,7 @@ def load_translate(): zh_cn["area_keyword_4"] = '区域关键字 #4' zh_cn["pass_1_seat_remaining"] = '避开“剩余 1”的区域' zh_cn["ocr_captcha"] = '猜测验证码' + zh_cn["ocr_captcha_with_submit"] = '猜测后自动送出' zh_cn["preference"] = '偏好设定' zh_cn["advanced"] = '進階設定' @@ -246,6 +249,7 @@ def load_translate(): ja_jp["area_keyword_4"] = 'エリアキーワード #4' ja_jp["pass_1_seat_remaining"] = '「1 席残り」エリアは避ける' ja_jp["ocr_captcha"] = 'キャプチャを推測する' + ja_jp["ocr_captcha_with_submit"] = '提出で推測した後' ja_jp["preference"] = '設定' ja_jp["advanced"] = '高度な設定' @@ -296,7 +300,9 @@ def get_default_config(): config_dict["ticket_number"] = 2 config_dict["pass_1_seat_remaining"] = True config_dict["auto_check_agree"] = True - config_dict["ocr_captcha"] = True + config_dict["ocr_captcha"] = {} + config_dict["ocr_captcha"]["enable"] = True + config_dict["ocr_captcha"]["auto_submit"] = False config_dict['kktix']={} config_dict["kktix"]["auto_press_next_step_button"] = True @@ -418,6 +424,7 @@ def btn_save_act(language_code, slience_mode=False): global txt_captcha_sound_filename global chk_state_adblock_plus global chk_state_ocr_captcha + global chk_state_ocr_captcha_with_submit is_all_data_correct = True @@ -490,7 +497,9 @@ def btn_save_act(language_code, slience_mode=False): config_dict["advanced"]["kktix_account"] = txt_kktix_account.get().strip() config_dict["advanced"]["adblock_plus_enable"] = bool(chk_state_adblock_plus.get()) - config_dict["ocr_captcha"] = bool(chk_state_ocr_captcha.get()) + config_dict["ocr_captcha"] = {} + config_dict["ocr_captcha"]["enable"] = bool(chk_state_ocr_captcha.get()) + config_dict["ocr_captcha"]["auto_submit"] = bool(chk_state_ocr_captcha_with_submit.get()) # save config. if is_all_data_correct: @@ -651,6 +660,7 @@ def applyNewLanguage(): global lbl_auto_reload_coming_soon_page global lbl_presale_code global lbl_ocr_captcha + global lbl_ocr_captcha_with_submit # for checkbox global chk_pass_1_seat_remaining @@ -666,6 +676,7 @@ def applyNewLanguage(): global chk_play_captcha_sound global chk_adblock_plus global chk_ocr_captcha + global chk_ocr_captcha_with_sumit global tabControl @@ -708,6 +719,7 @@ def applyNewLanguage(): lbl_auto_reload_coming_soon_page.config(text=translate[language_code]["auto_reload_coming_soon_page"]) lbl_presale_code.config(text=translate[language_code]["user_guess_string"]) lbl_ocr_captcha.config(text=translate[language_code]["ocr_captcha"]) + lbl_ocr_captcha_with_submit.config(text=translate[language_code]["ocr_captcha_with_submit"]) chk_pass_1_seat_remaining.config(text=translate[language_code]["enable"]) chk_auto_check_agree.config(text=translate[language_code]["enable"]) @@ -721,6 +733,7 @@ def applyNewLanguage(): chk_play_captcha_sound.config(text=translate[language_code]["enable"]) chk_adblock_plus.config(text=translate[language_code]["enable"]) chk_ocr_captcha.config(text=translate[language_code]["enable"]) + chk_ocr_captcha_with_sumit.config(text=translate[language_code]["enable"]) tabControl.tab(0, text=translate[language_code]["preference"]) tabControl.tab(1, text=translate[language_code]["advanced"]) @@ -793,6 +806,24 @@ def showHideBlocks(): showHideTixcraftBlocks() showHidePass1SeatRemaining() + showHideOcrCaptchaWithSubmit() + +def showHideOcrCaptchaWithSubmit(): + global chk_state_ocr_captcha + is_ocr_captcha_enable = bool(chk_state_ocr_captcha.get()) + + global ocr_captcha_with_submit_index + global lbl_ocr_captcha_with_submit + global chk_ocr_captcha_with_sumit + + if is_ocr_captcha_enable: + # show. + lbl_ocr_captcha_with_submit.grid(column=0, row=ocr_captcha_with_submit_index, sticky = E) + chk_ocr_captcha_with_sumit.grid(column=1, row=ocr_captcha_with_submit_index, sticky = W) + else: + # hide + lbl_ocr_captcha_with_submit.grid_forget() + chk_ocr_captcha_with_sumit.grid_forget() def showHidePass1SeatRemaining(): global combo_ticket_number @@ -1450,12 +1481,29 @@ def PreferenctTab(root, config_dict, language_code, UI_PADDING_X): global chk_state_ocr_captcha chk_state_ocr_captcha = BooleanVar() - chk_state_ocr_captcha.set(config_dict['ocr_captcha']) + chk_state_ocr_captcha.set(config_dict['ocr_captcha']["enable"]) global chk_ocr_captcha - chk_ocr_captcha = Checkbutton(frame_group_tixcraft, text=translate[language_code]['enable'], variable=chk_state_ocr_captcha) + chk_ocr_captcha = Checkbutton(frame_group_tixcraft, text=translate[language_code]['enable'], variable=chk_state_ocr_captcha, command=showHideOcrCaptchaWithSubmit) chk_ocr_captcha.grid(column=1, row=group_row_count, sticky = W) + group_row_count+=1 + + global ocr_captcha_with_submit_index + ocr_captcha_with_submit_index = group_row_count + + global lbl_ocr_captcha_with_submit + lbl_ocr_captcha_with_submit = Label(frame_group_tixcraft, text=translate[language_code]['ocr_captcha_with_submit']) + lbl_ocr_captcha_with_submit.grid(column=0, row=ocr_captcha_with_submit_index, sticky = E) + + global chk_state_ocr_captcha_with_submit + chk_state_ocr_captcha_with_submit = BooleanVar() + chk_state_ocr_captcha_with_submit.set(config_dict['ocr_captcha']["auto_submit"]) + + global chk_ocr_captcha_with_sumit + chk_ocr_captcha_with_sumit = Checkbutton(frame_group_tixcraft, text=translate[language_code]['enable'], variable=chk_state_ocr_captcha_with_submit) + chk_ocr_captcha_with_sumit.grid(column=1, row=group_row_count, sticky = W) + global frame_group_tixcraft_index frame_group_tixcraft_index = row_count #PS: don't need show when onload(), because show/hide block will load again. @@ -1768,7 +1816,7 @@ def main(): load_GUI(root, config_dict) GUI_SIZE_WIDTH = 460 - GUI_SIZE_HEIGHT = 575 + GUI_SIZE_HEIGHT = 594 GUI_SIZE_MACOS = str(GUI_SIZE_WIDTH) + 'x' + str(GUI_SIZE_HEIGHT) GUI_SIZE_WINDOWS=str(GUI_SIZE_WIDTH-60) + 'x' + str(GUI_SIZE_HEIGHT-90)