2023-02-16, support guess anwser dictionary for tixcraft

master
CHUN YU YAO 2023-02-18 00:54:16 +08:00
parent 8aba8df753
commit 531d93c870
2 changed files with 98 additions and 60 deletions

View File

@ -50,7 +50,7 @@ except Exception as exc:
import ssl import ssl
ssl._create_default_https_context = ssl._create_unverified_context ssl._create_default_https_context = ssl._create_unverified_context
CONST_APP_VERSION = u"MaxBot (2023.02.14)" CONST_APP_VERSION = u"MaxBot (2023.02.16)"
CONST_HOMEPAGE_DEFAULT = "https://tixcraft.com" CONST_HOMEPAGE_DEFAULT = "https://tixcraft.com"
URL_GOOGLE_OAUTH = 'https://accounts.google.com/o/oauth2/v2/auth/oauthchooseaccount?redirect_uri=https%3A%2F%2Fdevelopers.google.com%2Foauthplayground&prompt=consent&response_type=code&client_id=407408718192.apps.googleusercontent.com&scope=email&access_type=offline&flowName=GeneralOAuthFlow' URL_GOOGLE_OAUTH = 'https://accounts.google.com/o/oauth2/v2/auth/oauthchooseaccount?redirect_uri=https%3A%2F%2Fdevelopers.google.com%2Foauthplayground&prompt=consent&response_type=code&client_id=407408718192.apps.googleusercontent.com&scope=email&access_type=offline&flowName=GeneralOAuthFlow'
@ -1697,15 +1697,8 @@ def tixcraft_ticket_number_auto_fill(driver, select_obj, ticket_number):
return is_ticket_number_assigned return is_ticket_number_assigned
def tixcraft_verify(driver, presale_code): def guess_tixcraft_question(driver):
show_debug_message = True # debug. inferred_answer_string = None
show_debug_message = False # online
ret = False
inferred_answer_string = None
if len(presale_code) > 0:
inferred_answer_string = presale_code
form_select = None form_select = None
try: try:
@ -1761,11 +1754,30 @@ def tixcraft_verify(driver, presale_code):
if '已詳閱' in html_text or '請詳閱' in html_text: if '已詳閱' in html_text or '請詳閱' in html_text:
if '輸入【同意】' in html_text: if '輸入【同意】' in html_text:
inferred_answer_string = '同意' inferred_answer_string = '同意'
return inferred_answer_string
def tixcraft_verify(driver, presale_code, presale_code_delimiter, answer_index):
show_debug_message = True # debug.
show_debug_message = False # online
inferred_answer_string = None
answer_list = []
if len(presale_code) > 0:
inferred_answer_string = presale_code
if len(presale_code_delimiter) > 0:
if presale_code_delimiter in presale_code:
answer_list = presale_code.split(presale_code_delimiter)
if len(answer_list) > 0:
if answer_index < len(answer_list)-1:
inferred_answer_string = answer_list[answer_index+1]
if inferred_answer_string is None:
inferred_answer_string = guess_tixcraft_question(driver)
if show_debug_message: if show_debug_message:
print("inferred_answer_string:", inferred_answer_string) print("inferred_answer_string:", inferred_answer_string)
form_input = None form_input = None
try: try:
form_input = driver.find_element(By.CSS_SELECTOR, '#checkCode') form_input = driver.find_element(By.CSS_SELECTOR, '#checkCode')
@ -1791,50 +1803,55 @@ def tixcraft_verify(driver, presale_code):
# PS: sometime may send key twice... # PS: sometime may send key twice...
form_input.clear() form_input.clear()
form_input.send_keys(inferred_answer_string) form_input.send_keys(inferred_answer_string)
form_input.send_keys(Keys.ENTER)
is_password_sent = True is_password_sent = True
# guess answer mode.
if len(presale_code_delimiter) > 0:
answer_index += 1
if show_debug_message: if show_debug_message:
print("sent password by bot.") print("sent password by bot:", inferred_answer_string)
except Exception as exc: except Exception as exc:
pass pass
else:
if inputed_value == inferred_answer_string:
if show_debug_message:
print("sent password by previous time.")
is_password_sent = True
try:
form_input.send_keys(Keys.ENTER)
except Exception as exc:
pass
if inputed_value == inferred_answer_string: # guess answer mode.
if show_debug_message: if len(presale_code_delimiter) > 0:
print("sent password by previous time.") if answer_index > -1:
is_password_sent = True # here not is first option.
inferred_answer_previous = None
if answer_index < len(answer_list)-1:
inferred_answer_previous = answer_list[answer_index]
if inputed_value == inferred_answer_previous:
try:
form_input.clear()
form_input.send_keys(inferred_answer_string)
form_input.send_keys(Keys.ENTER)
is_password_sent = True
if show_debug_message:
print("sent password by bot:", inferred_answer_string, "at index:", answer_index+2)
answer_index += 1
except Exception as exc:
pass
if is_password_sent: if is_password_sent:
submit_btn = None for i in range(3):
try: time.sleep(0.1)
submit_btn = driver.find_element(By.ID, 'submitButton') alert_ret = check_pop_alert(driver)
except Exception as exc: if alert_ret:
if show_debug_message: if show_debug_message:
print("find submit button fail") print("press accept button at time #", i+1)
print(exc) break
pass
is_submited = False
if not submit_btn is None:
for i in range(3):
try:
if submit_btn.is_enabled():
submit_btn.click()
is_submited = True
if show_debug_message:
print("press submit button at time #", i+1)
except Exception as exc:
pass
if is_submited:
break
if is_submited:
for i in range(3):
time.sleep(0.1)
alert_ret = check_pop_alert(driver)
if alert_ret:
if show_debug_message:
print("press accept button at time #", i+1)
break
else: else:
if len(inputed_value)==0: if len(inputed_value)==0:
try: try:
@ -1842,7 +1859,7 @@ def tixcraft_verify(driver, presale_code):
except Exception as exc: except Exception as exc:
pass pass
return ret return answer_index
def tixcraft_change_captcha(driver,url): def tixcraft_change_captcha(driver,url):
try: try:
@ -5565,7 +5582,7 @@ def list_all_cookies(driver):
cookies_dict[cookie['name']] = cookie['value'] cookies_dict[cookie['name']] = cookie['value']
print(cookies_dict) print(cookies_dict)
def tixcraft_main(driver, url, config_dict, is_verifyCode_editing, ocr, Captcha_Browser): def tixcraft_main(driver, url, config_dict, answer_index, is_verifyCode_editing, ocr, Captcha_Browser):
home_url_list = ['https://tixcraft.com/','https://www.tixcraft.com/','https://indievox.com/','https://www.indievox.com/','https://teamear.tixcraft.com/activity'] home_url_list = ['https://tixcraft.com/','https://www.tixcraft.com/','https://indievox.com/','https://www.indievox.com/','https://teamear.tixcraft.com/activity']
for each_url in home_url_list: for each_url in home_url_list:
if each_url == url: if each_url == url:
@ -5597,7 +5614,10 @@ def tixcraft_main(driver, url, config_dict, is_verifyCode_editing, ocr, Captcha_
if '/ticket/verify/' in url: if '/ticket/verify/' in url:
presale_code = config_dict["tixcraft"]["presale_code"] presale_code = config_dict["tixcraft"]["presale_code"]
tixcraft_verify(driver, presale_code) presale_code_delimiter = config_dict["tixcraft"]["presale_code_delimiter"]
answer_index = tixcraft_verify(driver, presale_code, presale_code_delimiter, answer_index)
else:
answer_index = -1
# main app, to select ticket number. # main app, to select ticket number.
if '/ticket/ticket/' in url: if '/ticket/ticket/' in url:
@ -5607,7 +5627,7 @@ def tixcraft_main(driver, url, config_dict, is_verifyCode_editing, ocr, Captcha_
else: else:
is_verifyCode_editing = False is_verifyCode_editing = False
return is_verifyCode_editing return answer_index, is_verifyCode_editing
def kktix_main(driver, url, config_dict, answer_index, kktix_register_status_last): def kktix_main(driver, url, config_dict, answer_index, kktix_register_status_last):
auto_press_next_step_button = config_dict["kktix"]["auto_press_next_step_button"] auto_press_next_step_button = config_dict["kktix"]["auto_press_next_step_button"]
@ -7777,7 +7797,7 @@ def main():
# for Max's manuall test. # for Max's manuall test.
if '/Downloads/varify.html' in url: if '/Downloads/varify.html' in url:
tixcraft_verify(driver, "") answer_index = tixcraft_verify(driver, "", "", answer_index)
tixcraft_family = False tixcraft_family = False
if 'tixcraft.com' in url: if 'tixcraft.com' in url:
@ -7787,7 +7807,7 @@ def main():
tixcraft_family = True tixcraft_family = True
if tixcraft_family: if tixcraft_family:
is_verifyCode_editing = tixcraft_main(driver, url, config_dict, is_verifyCode_editing, ocr, Captcha_Browser) answer_index, is_verifyCode_editing = tixcraft_main(driver, url, config_dict, answer_index, is_verifyCode_editing, ocr, Captcha_Browser)
# for kktix.cc and kktix.com # for kktix.cc and kktix.com
if 'kktix.c' in url: if 'kktix.c' in url:

View File

@ -20,7 +20,7 @@ import webbrowser
import pyperclip import pyperclip
import base64 import base64
CONST_APP_VERSION = u"MaxBot (2023.02.14)" CONST_APP_VERSION = u"MaxBot (2023.02.16)"
CONST_FROM_TOP_TO_BOTTOM = u"from top to bottom" CONST_FROM_TOP_TO_BOTTOM = u"from top to bottom"
CONST_FROM_BOTTOM_TO_TOP = u"from bottom to top" CONST_FROM_BOTTOM_TO_TOP = u"from bottom to top"
@ -73,6 +73,7 @@ def load_translate():
en_us["and"] = 'And with' en_us["and"] = 'And with'
en_us["auto_guess_options"] = 'Guess Options in Question' en_us["auto_guess_options"] = 'Guess Options in Question'
en_us["user_guess_string"] = 'Fill This Answer in Question' en_us["user_guess_string"] = 'Fill This Answer in Question'
en_us["presale_code_delimiter"] = 'Answer delimiter'
en_us["date_auto_select"] = 'Date Auto Select' en_us["date_auto_select"] = 'Date Auto Select'
en_us["date_select_order"] = 'Date select order' en_us["date_select_order"] = 'Date select order'
@ -147,6 +148,7 @@ def load_translate():
zh_tw["and"] = '而且(同列)' zh_tw["and"] = '而且(同列)'
zh_tw["auto_guess_options"] = '自動猜測驗證問題' zh_tw["auto_guess_options"] = '自動猜測驗證問題'
zh_tw["user_guess_string"] = '在驗證問題中填寫此答案' zh_tw["user_guess_string"] = '在驗證問題中填寫此答案'
zh_tw["presale_code_delimiter"] = '答案中的分隔符號'
zh_tw["date_auto_select"] = '日期自動點選' zh_tw["date_auto_select"] = '日期自動點選'
zh_tw["date_select_order"] = '日期排序方式' zh_tw["date_select_order"] = '日期排序方式'
@ -221,6 +223,7 @@ def load_translate():
zh_cn["and"] = '而且(同列)' zh_cn["and"] = '而且(同列)'
zh_cn["auto_guess_options"] = '自动猜测验证问题' zh_cn["auto_guess_options"] = '自动猜测验证问题'
zh_cn["user_guess_string"] = '在验证问题中填写此答案' zh_cn["user_guess_string"] = '在验证问题中填写此答案'
zh_cn["presale_code_delimiter"] = '答案中的分隔符号'
zh_cn["date_auto_select"] = '日期自动点选' zh_cn["date_auto_select"] = '日期自动点选'
zh_cn["date_select_order"] = '日期排序方式' zh_cn["date_select_order"] = '日期排序方式'
@ -296,6 +299,7 @@ def load_translate():
ja_jp["and"] = 'そして(同列)' ja_jp["and"] = 'そして(同列)'
ja_jp["auto_guess_options"] = '自動推測検証問題' ja_jp["auto_guess_options"] = '自動推測検証問題'
ja_jp["user_guess_string"] = '質問に回答を記入' ja_jp["user_guess_string"] = '質問に回答を記入'
ja_jp["presale_code_delimiter"] = '回答区切り'
ja_jp["date_auto_select"] = '日付自動選択' ja_jp["date_auto_select"] = '日付自動選択'
ja_jp["date_select_order"] = '日付のソート方法' ja_jp["date_select_order"] = '日付のソート方法'
@ -435,6 +439,7 @@ def get_default_config():
config_dict["tixcraft"]["pass_date_is_sold_out"] = True config_dict["tixcraft"]["pass_date_is_sold_out"] = True
config_dict["tixcraft"]["auto_reload_coming_soon_page"] = True config_dict["tixcraft"]["auto_reload_coming_soon_page"] = True
config_dict["tixcraft"]["presale_code"] = "" config_dict["tixcraft"]["presale_code"] = ""
config_dict["tixcraft"]["presale_code_delimiter"] = ""
config_dict['advanced']={} config_dict['advanced']={}
@ -533,6 +538,7 @@ def btn_save_act(language_code, slience_mode=False):
global chk_state_pass_date_is_sold_out global chk_state_pass_date_is_sold_out
global chk_state_auto_reload_coming_soon_page global chk_state_auto_reload_coming_soon_page
global txt_presale_code global txt_presale_code
global txt_presale_code_delimiter
global txt_facebook_account global txt_facebook_account
global txt_kktix_account global txt_kktix_account
@ -628,6 +634,7 @@ def btn_save_act(language_code, slience_mode=False):
config_dict["tixcraft"]["pass_date_is_sold_out"] = bool(chk_state_pass_date_is_sold_out.get()) config_dict["tixcraft"]["pass_date_is_sold_out"] = bool(chk_state_pass_date_is_sold_out.get())
config_dict["tixcraft"]["auto_reload_coming_soon_page"] = bool(chk_state_auto_reload_coming_soon_page.get()) config_dict["tixcraft"]["auto_reload_coming_soon_page"] = bool(chk_state_auto_reload_coming_soon_page.get())
config_dict["tixcraft"]["presale_code"] = txt_presale_code.get().strip() config_dict["tixcraft"]["presale_code"] = txt_presale_code.get().strip()
config_dict["tixcraft"]["presale_code_delimiter"] = txt_presale_code_delimiter.get().strip()
config_dict["advanced"]["play_captcha_sound"]["enable"] = bool(chk_state_play_captcha_sound.get()) config_dict["advanced"]["play_captcha_sound"]["enable"] = bool(chk_state_play_captcha_sound.get())
config_dict["advanced"]["play_captcha_sound"]["filename"] = txt_captcha_sound_filename.get().strip() config_dict["advanced"]["play_captcha_sound"]["filename"] = txt_captcha_sound_filename.get().strip()
@ -820,6 +827,7 @@ def applyNewLanguage():
global lbl_pass_date_is_sold_out global lbl_pass_date_is_sold_out
global lbl_auto_reload_coming_soon_page global lbl_auto_reload_coming_soon_page
global lbl_presale_code global lbl_presale_code
global lbl_presale_code_delimiter
global lbl_ocr_captcha global lbl_ocr_captcha
global lbl_ocr_captcha_force_submit global lbl_ocr_captcha_force_submit
global lbl_ocr_captcha_image_source global lbl_ocr_captcha_image_source
@ -888,6 +896,7 @@ def applyNewLanguage():
lbl_pass_date_is_sold_out.config(text=translate[language_code]["pass_date_is_sold_out"]) lbl_pass_date_is_sold_out.config(text=translate[language_code]["pass_date_is_sold_out"])
lbl_auto_reload_coming_soon_page.config(text=translate[language_code]["auto_reload_coming_soon_page"]) 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_presale_code.config(text=translate[language_code]["user_guess_string"])
lbl_presale_code_delimiter.config(text=translate[language_code]["presale_code_delimiter"])
lbl_ocr_captcha.config(text=translate[language_code]["ocr_captcha"]) lbl_ocr_captcha.config(text=translate[language_code]["ocr_captcha"])
lbl_ocr_captcha_force_submit.config(text=translate[language_code]["ocr_captcha_force_submit"]) lbl_ocr_captcha_force_submit.config(text=translate[language_code]["ocr_captcha_force_submit"])
lbl_ocr_captcha_image_source.config(text=translate[language_code]["ocr_captcha_image_source"]) lbl_ocr_captcha_image_source.config(text=translate[language_code]["ocr_captcha_image_source"])
@ -1173,7 +1182,6 @@ def PreferenctTab(root, config_dict, language_code, UI_PADDING_X):
pass_date_is_sold_out_enable = False pass_date_is_sold_out_enable = False
auto_reload_coming_soon_page_enable = True auto_reload_coming_soon_page_enable = True
presale_code = ""
# read config. # read config.
homepage = config_dict["homepage"] homepage = config_dict["homepage"]
@ -1223,7 +1231,6 @@ def PreferenctTab(root, config_dict, language_code, UI_PADDING_X):
area_keyword_4 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_4"].strip() area_keyword_4 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_4"].strip()
pass_date_is_sold_out_enable = config_dict["tixcraft"]["pass_date_is_sold_out"] pass_date_is_sold_out_enable = config_dict["tixcraft"]["pass_date_is_sold_out"]
auto_reload_coming_soon_page_enable = config_dict["tixcraft"]["auto_reload_coming_soon_page"] auto_reload_coming_soon_page_enable = config_dict["tixcraft"]["auto_reload_coming_soon_page"]
presale_code = config_dict["tixcraft"]["presale_code"].strip()
# output config: # output config:
print("setting app version", CONST_APP_VERSION) print("setting app version", CONST_APP_VERSION)
@ -1697,12 +1704,23 @@ def PreferenctTab(root, config_dict, language_code, UI_PADDING_X):
lbl_presale_code.grid(column=0, row=group_row_count, sticky = E) lbl_presale_code.grid(column=0, row=group_row_count, sticky = E)
global txt_presale_code global txt_presale_code
txt_presale_code_value = StringVar(frame_group_tixcraft, value=presale_code) txt_presale_code_value = StringVar(frame_group_tixcraft, value=config_dict['tixcraft']["presale_code"])
txt_presale_code = Entry(frame_group_tixcraft, width=20, textvariable = txt_presale_code_value) txt_presale_code = Entry(frame_group_tixcraft, width=20, textvariable = txt_presale_code_value)
txt_presale_code.grid(column=1, row=group_row_count, sticky = W) txt_presale_code.grid(column=1, row=group_row_count, sticky = W)
group_row_count+=1 group_row_count+=1
global lbl_presale_code_delimiter
lbl_presale_code_delimiter = Label(frame_group_tixcraft, text=translate[language_code]['presale_code_delimiter'])
lbl_presale_code_delimiter.grid(column=0, row=group_row_count, sticky = E)
global txt_presale_code_delimiter
txt_presale_code_delemiter_value = StringVar(frame_group_tixcraft, value=config_dict['tixcraft']["presale_code_delimiter"])
txt_presale_code_delimiter = Entry(frame_group_tixcraft, width=20, textvariable = txt_presale_code_delemiter_value)
txt_presale_code_delimiter.grid(column=1, row=group_row_count, sticky = W)
group_row_count+=1
global lbl_ocr_captcha global lbl_ocr_captcha
lbl_ocr_captcha = Label(frame_group_tixcraft, text=translate[language_code]['ocr_captcha']) lbl_ocr_captcha = Label(frame_group_tixcraft, text=translate[language_code]['ocr_captcha'])
lbl_ocr_captcha.grid(column=0, row=group_row_count, sticky = E) lbl_ocr_captcha.grid(column=0, row=group_row_count, sticky = E)
@ -2219,10 +2237,10 @@ def main():
load_GUI(root, config_dict) load_GUI(root, config_dict)
GUI_SIZE_WIDTH = 510 GUI_SIZE_WIDTH = 510
GUI_SIZE_HEIGHT = 594 GUI_SIZE_HEIGHT = 619
GUI_SIZE_MACOS = str(GUI_SIZE_WIDTH) + 'x' + str(GUI_SIZE_HEIGHT) 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-70) GUI_SIZE_WINDOWS=str(GUI_SIZE_WIDTH-60) + 'x' + str(GUI_SIZE_HEIGHT-55)
GUI_SIZE =GUI_SIZE_MACOS GUI_SIZE =GUI_SIZE_MACOS