fine tune some codes

master
CHUN YU YAO 2023-03-24 00:49:02 +08:00
parent 6977bb588f
commit 229e714930
1 changed files with 57 additions and 66 deletions

View File

@ -2063,8 +2063,10 @@ def tixcraft_keyin_captcha_code(driver, answer = "", auto_submit = False):
except Exception as exc: except Exception as exc:
print("find verify code fail") print("find verify code fail")
pass pass
if inputed_value is None: if inputed_value is None:
inputed_value = "" inputed_value = ""
if answer==inputed_value: if answer==inputed_value:
# no need to send key. # no need to send key.
is_visible = False is_visible = False
@ -2080,22 +2082,24 @@ def tixcraft_keyin_captcha_code(driver, answer = "", auto_submit = False):
driver.execute_script("document.getElementById(\"TicketForm_verifyCode\").focus();") driver.execute_script("document.getElementById(\"TicketForm_verifyCode\").focus();")
is_verifyCode_editing = True is_verifyCode_editing = True
except Exception as exc: except Exception as exc:
print("click form_verifyCode fail.") #print("click form_verifyCode fail.")
pass
#print("start to fill answer.") if len(answer) > 0:
try: #print("start to fill answer.")
if len(answer) > 0: try:
form_verifyCode.clear()
form_verifyCode.send_keys(answer) form_verifyCode.send_keys(answer)
if auto_submit:
form_verifyCode.send_keys(Keys.ENTER) if auto_submit:
is_verifyCode_editing = False form_verifyCode.send_keys(Keys.ENTER)
is_form_sumbited = True is_verifyCode_editing = False
else: is_form_sumbited = True
driver.execute_script("document.getElementById(\"TicketForm_verifyCode\").select();") else:
if len(answer) > 0: driver.execute_script("document.getElementById(\"TicketForm_verifyCode\").select();")
tixcraft_toast(driver, "※ 按 Enter 如果答案是: " + answer) tixcraft_toast(driver, "※ 按 Enter 如果答案是: " + answer)
except Exception as exc: except Exception as exc:
print("send_keys ocr answer fail.") print("send_keys ocr answer fail.")
return is_verifyCode_editing, is_form_sumbited return is_verifyCode_editing, is_form_sumbited
@ -2222,21 +2226,17 @@ def tixcraft_auto_ocr(driver, ocr, away_from_keyboard_enable, previous_answer, C
return is_need_redo_ocr, previous_answer, is_form_sumbited return is_need_redo_ocr, previous_answer, is_form_sumbited
def tixcraft_ticket_main(driver, config_dict, ocr, Captcha_Browser, domain_name): def tixcraft_ticket_main_agree(driver, config_dict):
auto_check_agree = config_dict["auto_check_agree"] auto_check_agree = config_dict["auto_check_agree"]
ocr_captcha_enable = config_dict["ocr_captcha"]["enable"]
away_from_keyboard_enable = config_dict["ocr_captcha"]["force_submit"]
if not ocr_captcha_enable:
away_from_keyboard_enable = False
ocr_captcha_image_source = config_dict["ocr_captcha"]["image_source"]
if auto_check_agree: if auto_check_agree:
for i in range(3): for i in range(3):
is_finish_checkbox_click = tixcraft_ticket_agree(driver) is_finish_checkbox_click = tixcraft_ticket_agree(driver)
if is_finish_checkbox_click: if is_finish_checkbox_click:
break break
def tixcraft_ticket_main(driver, config_dict, ocr, Captcha_Browser, domain_name):
tixcraft_ticket_main_agree(driver, config_dict)
# allow agree not enable to assign ticket number. # allow agree not enable to assign ticket number.
form_select = None form_select = None
try: try:
@ -2267,8 +2267,8 @@ def tixcraft_ticket_main(driver, config_dict, ocr, Captcha_Browser, domain_name)
except Exception as exc: except Exception as exc:
pass pass
is_ticket_number_assigned = False
if not select_obj is None: if not select_obj is None:
is_ticket_number_assigned = False
row_text = None row_text = None
try: try:
row_text = select_obj.first_selected_option.text row_text = select_obj.first_selected_option.text
@ -2281,38 +2281,40 @@ def tixcraft_ticket_main(driver, config_dict, ocr, Captcha_Browser, domain_name)
# ticket assign. # ticket assign.
is_ticket_number_assigned = True is_ticket_number_assigned = True
is_verifyCode_editing = False # must wait select object ready to assign ticket number.
if not is_ticket_number_assigned:
# only this case: "ticket number changed by bot" to play sound!
# PS: I assume each time assign ticket number will succufully changed, so let sound play first.
check_and_play_sound_for_captcha(config_dict)
# must wait select object ready to assign ticket number. ticket_number = str(config_dict["ticket_number"])
if not is_ticket_number_assigned: is_ticket_number_assigned = tixcraft_ticket_number_auto_fill(driver, select_obj, ticket_number)
# only this case:"ticket number changed by bot" to play sound!
# PS: I assume each time assign ticket number will succufully changed, so let sound play first.
check_and_play_sound_for_captcha(config_dict)
ticket_number = str(config_dict["ticket_number"]) # must wait ticket number assign to focus captcha.
is_ticket_number_assigned = tixcraft_ticket_number_auto_fill(driver, select_obj, ticket_number) if is_ticket_number_assigned:
tixcraft_ticket_main_ocr(driver, config_dict, ocr, Captcha_Browser, domain_name)
# must wait ticket number assign to focus captcha. def tixcraft_ticket_main_ocr(driver, config_dict, ocr, Captcha_Browser, domain_name):
if is_ticket_number_assigned: away_from_keyboard_enable = config_dict["ocr_captcha"]["force_submit"]
if not ocr_captcha_enable: if not config_dict["ocr_captcha"]["enable"]:
is_verifyCode_editing = tixcraft_keyin_captcha_code(driver) away_from_keyboard_enable = False
else: ocr_captcha_image_source = config_dict["ocr_captcha"]["image_source"]
previous_answer = None
is_verifyCode_editing = True
for redo_ocr in range(999):
is_need_redo_ocr, previous_answer, is_form_sumbited = tixcraft_auto_ocr(driver, ocr, away_from_keyboard_enable, previous_answer, Captcha_Browser, ocr_captcha_image_source, domain_name)
if is_form_sumbited:
# start next loop.
is_verifyCode_editing = False
break
if not away_from_keyboard_enable: if not config_dict["ocr_captcha"]["enable"]:
break tixcraft_keyin_captcha_code(driver)
else:
previous_answer = None
for redo_ocr in range(999):
is_need_redo_ocr, previous_answer, is_form_sumbited = tixcraft_auto_ocr(driver, ocr, away_from_keyboard_enable, previous_answer, Captcha_Browser, ocr_captcha_image_source, domain_name)
if is_form_sumbited:
# start next loop.
break
if not is_need_redo_ocr: if not away_from_keyboard_enable:
break break
return is_verifyCode_editing if not is_need_redo_ocr:
break
def kktix_confirm_order_button(driver): def kktix_confirm_order_button(driver):
ret = False ret = False
@ -5888,8 +5890,6 @@ def ticketmaster_assign_ticket_number(driver, config_dict):
# ticket assign. # ticket assign.
is_ticket_number_assigned = True is_ticket_number_assigned = True
is_verifyCode_editing = False
if show_debug_message: if show_debug_message:
print('is_ticket_number_assigned:', is_ticket_number_assigned) print('is_ticket_number_assigned:', is_ticket_number_assigned)
@ -5912,9 +5912,8 @@ def ticketmaster_captcha(driver, config_dict, ocr, Captcha_Browser, domain_name)
auto_check_agree = config_dict["auto_check_agree"] auto_check_agree = config_dict["auto_check_agree"]
ocr_captcha_enable = config_dict["ocr_captcha"]["enable"]
away_from_keyboard_enable = config_dict["ocr_captcha"]["force_submit"] away_from_keyboard_enable = config_dict["ocr_captcha"]["force_submit"]
if not ocr_captcha_enable: if not config_dict["ocr_captcha"]["enable"]:
away_from_keyboard_enable = False away_from_keyboard_enable = False
ocr_captcha_image_source = config_dict["ocr_captcha"]["image_source"] ocr_captcha_image_source = config_dict["ocr_captcha"]["image_source"]
@ -5924,16 +5923,14 @@ def ticketmaster_captcha(driver, config_dict, ocr, Captcha_Browser, domain_name)
if is_finish_checkbox_click: if is_finish_checkbox_click:
break break
if not ocr_captcha_enable: if not config_dict["ocr_captcha"]["enable"]:
is_verifyCode_editing = tixcraft_keyin_captcha_code(driver) tixcraft_keyin_captcha_code(driver)
else: else:
previous_answer = None previous_answer = None
is_verifyCode_editing = True
for redo_ocr in range(999): for redo_ocr in range(999):
is_need_redo_ocr, previous_answer, is_form_sumbited = tixcraft_auto_ocr(driver, ocr, away_from_keyboard_enable, previous_answer, Captcha_Browser, ocr_captcha_image_source, domain_name) is_need_redo_ocr, previous_answer, is_form_sumbited = tixcraft_auto_ocr(driver, ocr, away_from_keyboard_enable, previous_answer, Captcha_Browser, ocr_captcha_image_source, domain_name)
if is_form_sumbited: if is_form_sumbited:
# start next loop. # start next loop.
is_verifyCode_editing = False
break break
if not away_from_keyboard_enable: if not away_from_keyboard_enable:
@ -5970,9 +5967,7 @@ def tixcraft_main(driver, url, config_dict, tixcraft_dict, ocr, Captcha_Browser)
if area_auto_select_enable: if area_auto_select_enable:
tixcraft_area_auto_select(driver, url, config_dict) tixcraft_area_auto_select(driver, url, config_dict)
else: else:
# area auto select is too difficult! # area auto select is too difficult, skip in this version.
pass
ticketmaster_assign_ticket_number(driver, config_dict) ticketmaster_assign_ticket_number(driver, config_dict)
# https://ticketmaster.sg/ticket/check-captcha/23_blackpink/954/5/75 # https://ticketmaster.sg/ticket/check-captcha/23_blackpink/954/5/75
@ -5991,7 +5986,7 @@ def tixcraft_main(driver, url, config_dict, tixcraft_dict, ocr, Captcha_Browser)
# main app, to select ticket number. # main app, to select ticket number.
if '/ticket/ticket/' in url: if '/ticket/ticket/' in url:
domain_name = url.split('/')[2] domain_name = url.split('/')[2]
is_verifyCode_editing = tixcraft_ticket_main(driver, config_dict, ocr, Captcha_Browser, domain_name) tixcraft_ticket_main(driver, config_dict, ocr, Captcha_Browser, domain_name)
if '/ticket/checkout' in url: if '/ticket/checkout' in url:
if config_dict["advanced"]["headless"]: if config_dict["advanced"]["headless"]:
@ -8193,9 +8188,8 @@ def kham_auto_ocr(driver, config_dict, ocr, away_from_keyboard_enable, previous_
return is_need_redo_ocr, previous_answer, is_form_sumbited return is_need_redo_ocr, previous_answer, is_form_sumbited
def kham_captcha(driver, config_dict, ocr, Captcha_Browser, model_name): def kham_captcha(driver, config_dict, ocr, Captcha_Browser, model_name):
ocr_captcha_enable = config_dict["ocr_captcha"]["enable"]
away_from_keyboard_enable = config_dict["ocr_captcha"]["force_submit"] away_from_keyboard_enable = config_dict["ocr_captcha"]["force_submit"]
if not ocr_captcha_enable: if not config_dict["ocr_captcha"]["enable"]:
away_from_keyboard_enable = False away_from_keyboard_enable = False
ocr_captcha_image_source = config_dict["ocr_captcha"]["image_source"] ocr_captcha_image_source = config_dict["ocr_captcha"]["image_source"]
@ -8204,7 +8198,6 @@ def kham_captcha(driver, config_dict, ocr, Captcha_Browser, model_name):
is_cpatcha_sent = False is_cpatcha_sent = False
previous_answer = None previous_answer = None
is_verifyCode_editing = True
for redo_ocr in range(999): for redo_ocr in range(999):
is_need_redo_ocr, previous_answer, is_form_sumbited = kham_auto_ocr(driver, config_dict, ocr, away_from_keyboard_enable, previous_answer, Captcha_Browser, ocr_captcha_image_source, model_name) is_need_redo_ocr, previous_answer, is_form_sumbited = kham_auto_ocr(driver, config_dict, ocr, away_from_keyboard_enable, previous_answer, Captcha_Browser, ocr_captcha_image_source, model_name)
@ -8571,15 +8564,13 @@ def ticketplus_order(driver, config_dict, ocr, Captcha_Browser):
pass pass
ocr_captcha_enable = config_dict["ocr_captcha"]["enable"]
away_from_keyboard_enable = config_dict["ocr_captcha"]["force_submit"] away_from_keyboard_enable = config_dict["ocr_captcha"]["force_submit"]
if not ocr_captcha_enable: if not config_dict["ocr_captcha"]["enable"]:
away_from_keyboard_enable = False away_from_keyboard_enable = False
ocr_captcha_image_source = config_dict["ocr_captcha"]["image_source"] ocr_captcha_image_source = config_dict["ocr_captcha"]["image_source"]
is_cpatcha_sent = False is_cpatcha_sent = False
previous_answer = None previous_answer = None
is_verifyCode_editing = True
for redo_ocr in range(999): for redo_ocr in range(999):
is_need_redo_ocr, previous_answer, is_form_sumbited = ticketplus_auto_ocr(driver, config_dict, ocr, away_from_keyboard_enable, previous_answer, Captcha_Browser, ocr_captcha_image_source) is_need_redo_ocr, previous_answer, is_form_sumbited = ticketplus_auto_ocr(driver, config_dict, ocr, away_from_keyboard_enable, previous_answer, Captcha_Browser, ocr_captcha_image_source)