rewirte kktix remaining seat number check, fami-ticket support auto dictionary keyin.

master
Max 2023-11-06 18:43:57 +08:00 committed by GitHub
parent 187cc2a560
commit 6ac7514f54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 97 additions and 21 deletions

View File

@ -55,7 +55,7 @@ import webbrowser
import chromedriver_autoinstaller import chromedriver_autoinstaller
CONST_APP_VERSION = "MaxBot (2023.11.02)" CONST_APP_VERSION = "MaxBot (2023.11.03)"
CONST_MAXBOT_CONFIG_FILE = "settings.json" CONST_MAXBOT_CONFIG_FILE = "settings.json"
CONST_MAXBOT_LAST_URL_FILE = "MAXBOT_LAST_URL.txt" CONST_MAXBOT_LAST_URL_FILE = "MAXBOT_LAST_URL.txt"
@ -352,7 +352,6 @@ def get_brave_bin_path():
return brave_path return brave_path
def get_chrome_options(webdriver_path, config_dict): def get_chrome_options(webdriver_path, config_dict):
adblock_plus_enable = config_dict["advanced"]["adblock_plus_enable"]
browser=config_dict["browser"] browser=config_dict["browser"]
chrome_options = webdriver.ChromeOptions() chrome_options = webdriver.ChromeOptions()
@ -362,12 +361,13 @@ def get_chrome_options(webdriver_path, config_dict):
chrome_options = webdriver.SafariOptions() chrome_options = webdriver.SafariOptions()
# some windows cause: timed out receiving message from renderer # some windows cause: timed out receiving message from renderer
if adblock_plus_enable: if config_dict["advanced"]["adblock_plus_enable"]:
# PS: this is ocx version. # PS: this is ocx version.
extension_list = get_favoriate_extension_path(webdriver_path) extension_list = get_favoriate_extension_path(webdriver_path)
for ext in extension_list: for ext in extension_list:
if os.path.exists(ext): if os.path.exists(ext):
chrome_options.add_extension(ext) chrome_options.add_extension(ext)
chrome_options.add_argument('--disable-features=TranslateUI') chrome_options.add_argument('--disable-features=TranslateUI')
chrome_options.add_argument('--disable-translate') chrome_options.add_argument('--disable-translate')
chrome_options.add_argument('--lang=zh-TW') chrome_options.add_argument('--lang=zh-TW')
@ -3486,7 +3486,7 @@ def kktix_input_captcha_text(captcha_password_input_element, inferred_answer_str
return is_captcha_sent return is_captcha_sent
def kktix_travel_price_list(driver, config_dict, kktix_area_keyword): def kktix_travel_price_list(driver, config_dict, kktix_area_auto_select_mode, kktix_area_keyword):
show_debug_message = True # debug. show_debug_message = True # debug.
show_debug_message = False # online show_debug_message = False # online
@ -3557,6 +3557,9 @@ def kktix_travel_price_list(driver, config_dict, kktix_area_keyword):
if '完売' in row_text: if '完売' in row_text:
row_text = "" row_text = ""
if not('<input type=' in row_html):
row_text = ""
if len(row_text) > 0: if len(row_text) > 0:
if reset_row_text_if_match_keyword_exclude(config_dict, row_text): if reset_row_text_if_match_keyword_exclude(config_dict, row_text):
row_text = "" row_text = ""
@ -3565,6 +3568,49 @@ def kktix_travel_price_list(driver, config_dict, kktix_area_keyword):
# clean stop word. # clean stop word.
row_text = format_keyword_string(row_text) row_text = format_keyword_string(row_text)
if len(row_text) > 0:
if ticket_number > 1:
# start to check danger notice.
# 剩 n 張票 / n Left / 残り n 枚
ticket_count = 999
# for cht.
if ' danger' in row_html and '' in row_text and '' in row_text:
tmp_array = row_html.split('')
tmp_array = tmp_array[1].split('')
if len(tmp_array) > 0:
tmp_ticket_count = tmp_array[0].strip()
if tmp_ticket_count.isdigit():
ticket_count = int(tmp_ticket_count)
if show_debug_message:
print("found ticket 剩:", tmp_ticket_count)
# for ja.
if ' danger' in row_html and '残り' in row_text and '' in row_text:
tmp_array = row_html.split('残り')
tmp_array = tmp_array[1].split('')
if len(tmp_array) > 0:
tmp_ticket_count = tmp_array[0].strip()
if tmp_ticket_count.isdigit():
ticket_count = int(tmp_ticket_count)
if show_debug_message:
print("found ticket 残り:", tmp_ticket_count)
# for en.
if ' danger' in row_html and ' Left ' in row_html:
tmp_array = row_html.split(' Left ')
tmp_array = tmp_array[0].split('>')
if len(tmp_array) > 0:
tmp_ticket_count = tmp_array[len(tmp_array)-1].strip()
if tmp_ticket_count.isdigit():
if show_debug_message:
print("found ticket left:", tmp_ticket_count)
ticket_count = int(tmp_ticket_count)
if ticket_count < ticket_number:
# skip this row, due to no ticket remaining.
if show_debug_message:
print("found ticket left:", tmp_ticket_count, ",but target ticket:", ticket_number)
row_text = ""
if len(row_text) > 0:
# check ticket input textbox. # check ticket input textbox.
ticket_price_input = None ticket_price_input = None
try: try:
@ -3590,22 +3636,6 @@ def kktix_travel_price_list(driver, config_dict, kktix_area_keyword):
# no need to travel # no need to travel
break break
is_danger_notice = False
if ticket_number > 1:
# start to check danger notice.
span_danger_popup = None
try:
span_danger_popup = row.find_element(By.CSS_SELECTOR, "span.danger")
if span_danger_popup.is_displayed():
is_danger_notice = True
except Exception as exc:
pass
if is_danger_notice:
# PS: not ALL danger notice are "only 1 seat remaining"...
# TODO: check real remaining value instead of check css style.
continue
if is_visible: if is_visible:
is_match_area = False is_match_area = False
match_area_code = 0 match_area_code = 0
@ -3644,6 +3674,11 @@ def kktix_travel_price_list(driver, config_dict, kktix_area_keyword):
if is_match_area: if is_match_area:
areas.append(ticket_price_input) areas.append(ticket_price_input)
# from top to bottom, match first to break.
if kktix_area_auto_select_mode == CONST_FROM_TOP_TO_BOTTOM:
break
if is_travel_interrupted: if is_travel_interrupted:
# not sure to break or continue..., maybe break better. # not sure to break or continue..., maybe break better.
break break
@ -3669,7 +3704,7 @@ def kktix_assign_ticket_number(driver, config_dict, kktix_area_keyword):
ticket_number = config_dict["ticket_number"] ticket_number = config_dict["ticket_number"]
kktix_area_auto_select_mode = config_dict["area_auto_select"]["mode"] kktix_area_auto_select_mode = config_dict["area_auto_select"]["mode"]
is_ticket_number_assigned, areas = kktix_travel_price_list(driver, config_dict, kktix_area_keyword) is_ticket_number_assigned, areas = kktix_travel_price_list(driver, config_dict, kktix_area_auto_select_mode, kktix_area_keyword)
is_need_refresh = False is_need_refresh = False
@ -4719,6 +4754,43 @@ def get_fami_target_area(driver, config_dict, area_keyword_item):
return matched_blocks return matched_blocks
def fami_verify(driver, config_dict, fail_list):
show_debug_message = True # debug.
show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
answer_list = []
question_text = ""
#if len(question_text) > 0:
if True:
#write_question_to_file(question_text)
answer_list = get_answer_list_from_user_guess_string(config_dict)
if len(answer_list)==0:
if config_dict["advanced"]["auto_guess_options"]:
answer_list = guess_tixcraft_question(driver, question_text)
inferred_answer_string = ""
for answer_item in answer_list:
if not answer_item in fail_list:
inferred_answer_string = answer_item
break
if show_debug_message:
print("inferred_answer_string:", inferred_answer_string)
print("answer_list:", answer_list)
# PS: auto-focus() when empty inferred_answer_string with empty inputed text value.
input_text_css = "#verifyPrefAnswer"
next_step_button_css = ""
submit_by_enter = True
check_input_interval = 0.2
is_answer_sent, fail_list = fill_common_verify_form(driver, config_dict, inferred_answer_string, fail_list, input_text_css, next_step_button_css, submit_by_enter, check_input_interval)
return fail_list
def fami_activity(driver): def fami_activity(driver):
#print("fami_activity bingo") #print("fami_activity bingo")
@ -7683,6 +7755,9 @@ def famiticket_main(driver, url, config_dict, fami_dict):
if '/Home/Activity/Info/' in url: if '/Home/Activity/Info/' in url:
fami_dict["last_activity"] = url fami_dict["last_activity"] = url
fami_activity(driver) fami_activity(driver)
fami_dict["fail_list"] = fami_verify(driver, config_dict, fami_dict["fail_list"])
else:
fami_dict["fail_list"] = []
if '/Sales/Home/Index/' in url: if '/Sales/Home/Index/' in url:
if config_dict["tixcraft"]["date_auto_select"]["enable"]: if config_dict["tixcraft"]["date_auto_select"]["enable"]:
@ -12057,6 +12132,7 @@ def main(args):
kktix_dict["kktix_register_status_last"] = None kktix_dict["kktix_register_status_last"] = None
fami_dict = {} fami_dict = {}
fami_dict["fail_list"] = []
fami_dict["last_activity"]="" fami_dict["last_activity"]=""
ibon_dict = {} ibon_dict = {}