2022-11-22, KKTix add keyword #2

master
CHUN YU YAO 2022-11-23 12:39:46 +08:00
parent 42437ff966
commit d9f04e0a84
2 changed files with 248 additions and 259 deletions

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
#encoding=utf-8 #encoding=utf-8
# 'seleniumwire' and 'selenium 4' raise error when running python 2.x # 'seleniumwire' and 'selenium 4' raise error when running python 2.x
# PS: python 2.x will be removed in future. # PS: python 2.x will be removed in future.
#執行方式python chrome_tixcraft.py 或 python3 chrome_tixcraft.py #執行方式python chrome_tixcraft.py 或 python3 chrome_tixcraft.py
import os import os
import sys import sys
@ -39,7 +39,7 @@ warnings.simplefilter('ignore',InsecureRequestWarning)
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 (2022.11.21)" CONST_APP_VERSION = u"MaxBot (2022.11.22)"
CONST_HOMEPAGE_DEFAULT = "https://tixcraft.com" CONST_HOMEPAGE_DEFAULT = "https://tixcraft.com"
CONST_FROM_TOP_TO_BOTTOM = u"from top to bottom" CONST_FROM_TOP_TO_BOTTOM = u"from top to bottom"
@ -236,7 +236,7 @@ def load_chromdriver_uc(webdriver_path, adblock_plus_enable):
return driver return driver
def close_browser_tabs(driver): def close_browser_tabs(driver):
if not driver is None: if not driver is None:
try: try:
window_handles_count = len(driver.window_handles) window_handles_count = len(driver.window_handles)
@ -282,197 +282,144 @@ def get_driver_by_config(config_dict, driver_type):
debugMode = False debugMode = False
if not config_dict is None: # read config.
# read config. homepage = config_dict["homepage"]
if 'homepage' in config_dict: browser = config_dict["browser"]
homepage = config_dict["homepage"]
if 'browser' in config_dict:
browser = config_dict["browser"]
# output debug message in client side. # output debug message in client side.
if 'debug' in config_dict: debugMode = config_dict["debug"]
debugMode = config_dict["debug"] ticket_number = str(config_dict["ticket_number"])
# default ticket number # for ["kktix"]
# 說明:自動選擇的票數 auto_press_next_step_button = config_dict["kktix"]["auto_press_next_step_button"]
#ticket_number = "2" auto_fill_ticket_number = config_dict["kktix"]["auto_fill_ticket_number"]
ticket_number = "" kktix_area_auto_select_mode = config_dict["kktix"]["area_mode"].strip()
if 'ticket_number' in config_dict: if not kktix_area_auto_select_mode in CONST_SELECT_OPTIONS_ARRAY:
ticket_number = str(config_dict["ticket_number"]) kktix_area_auto_select_mode = CONST_SELECT_ORDER_DEFAULT
# for ["kktix"] kktix_area_keyword_1 = config_dict["kktix"]["area_keyword_1"].strip()
if 'kktix' in config_dict: kktix_area_keyword_1_and = config_dict["kktix"]["area_keyword_1_and"].strip()
auto_press_next_step_button = config_dict["kktix"]["auto_press_next_step_button"] kktix_area_keyword_2 = config_dict["kktix"]["area_keyword_2"].strip()
auto_fill_ticket_number = config_dict["kktix"]["auto_fill_ticket_number"] kktix_area_keyword_2_and = config_dict["kktix"]["area_keyword_2_and"].strip()
if 'area_mode' in config_dict["kktix"]: # disable password brute force attack
kktix_area_auto_select_mode = config_dict["kktix"]["area_mode"].strip() # PS: because of the question is always variable.
if not kktix_area_auto_select_mode in CONST_SELECT_OPTIONS_ARRAY:
kktix_area_auto_select_mode = CONST_SELECT_ORDER_DEFAULT
if 'area_keyword' in config_dict["kktix"]: auto_guess_options = config_dict["kktix"]["auto_guess_options"]
kktix_area_keyword = config_dict["kktix"]["area_keyword"]
if kktix_area_keyword is None:
kktix_area_keyword = ""
kktix_area_keyword = kktix_area_keyword.strip()
if 'date_keyword' in config_dict["kktix"]: # for ["tixcraft"]
kktix_date_keyword = config_dict["kktix"]["date_keyword"] date_auto_select_enable = config_dict["tixcraft"]["date_auto_select"]["enable"]
if kktix_date_keyword is None: date_auto_select_mode = config_dict["tixcraft"]["date_auto_select"]["mode"]
kktix_date_keyword = "" if not date_auto_select_mode in CONST_SELECT_OPTIONS_ARRAY:
kktix_date_keyword = kktix_date_keyword.strip() date_auto_select_mode = CONST_SELECT_ORDER_DEFAULT
# disable password brute force attack date_keyword = config_dict["tixcraft"]["date_auto_select"]["date_keyword"].strip()
# PS: because of the question is always variable.
if 'auto_guess_options' in config_dict["kktix"]: area_auto_select_enable = config_dict["tixcraft"]["area_auto_select"]["enable"]
auto_guess_options = config_dict["kktix"]["auto_guess_options"] area_auto_select_mode = config_dict["tixcraft"]["area_auto_select"]["mode"]
if not area_auto_select_mode in CONST_SELECT_OPTIONS_ARRAY:
area_auto_select_mode = CONST_SELECT_ORDER_DEFAULT
# for ["tixcraft"] area_keyword_1 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_1"].strip()
if 'tixcraft' in config_dict: area_keyword_2 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_2"].strip()
date_auto_select_enable = False area_keyword_3 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_3"].strip()
date_auto_select_mode = None area_keyword_4 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_4"].strip()
if 'date_auto_select' in config_dict["tixcraft"]: pass_1_seat_remaining_enable = config_dict["tixcraft"]["pass_1_seat_remaining"]
date_auto_select_enable = config_dict["tixcraft"]["date_auto_select"]["enable"] pass_date_is_sold_out_enable = config_dict["tixcraft"]["pass_date_is_sold_out"]
date_auto_select_mode = config_dict["tixcraft"]["date_auto_select"]["mode"] auto_reload_coming_soon_page_enable = config_dict["tixcraft"]["auto_reload_coming_soon_page"]
if not date_auto_select_mode in CONST_SELECT_OPTIONS_ARRAY: # output config:
date_auto_select_mode = CONST_SELECT_ORDER_DEFAULT print("maxbot app version", CONST_APP_VERSION)
print("python version", platform.python_version())
print("homepage", homepage)
print("browser", browser)
print("ticket_number", ticket_number)
if 'date_keyword' in config_dict["tixcraft"]["date_auto_select"]: # for kktix
date_keyword = config_dict["tixcraft"]["date_auto_select"]["date_keyword"] print("==[kktix]==")
date_keyword = date_keyword.strip() print("auto_press_next_step_button", auto_press_next_step_button)
print("auto_fill_ticket_number", auto_fill_ticket_number)
print("kktix_area_keyword_1", kktix_area_keyword_1)
print("kktix_area_keyword_1_and", kktix_area_keyword_1_and)
print("kktix_area_keyword_2", kktix_area_keyword_2)
print("kktix_area_keyword_2_and", kktix_area_keyword_2_and)
print("auto_guess_options", auto_guess_options)
area_auto_select_enable = False # for tixcraft
area_auto_select_mode = None print("==[tixcraft]==")
print("date_auto_select_enable", date_auto_select_enable)
print("date_auto_select_mode", date_auto_select_mode)
print("date_keyword", date_keyword)
if 'area_auto_select' in config_dict["tixcraft"]: print("area_auto_select_enable", area_auto_select_enable)
area_auto_select_enable = config_dict["tixcraft"]["area_auto_select"]["enable"] print("area_auto_select_mode", area_auto_select_mode)
area_auto_select_mode = config_dict["tixcraft"]["area_auto_select"]["mode"] print("area_keyword_1", area_keyword_1)
print("area_keyword_2", area_keyword_2)
print("area_keyword_3", area_keyword_3)
print("area_keyword_4", area_keyword_4)
if not area_auto_select_mode in CONST_SELECT_OPTIONS_ARRAY: print("pass_1_seat_remaining", pass_1_seat_remaining_enable)
area_auto_select_mode = CONST_SELECT_ORDER_DEFAULT print("pass_date_is_sold_out", pass_date_is_sold_out_enable)
print("auto_reload_coming_soon_page", auto_reload_coming_soon_page_enable)
print("debug Mode", debugMode)
if 'area_keyword_1' in config_dict["tixcraft"]["area_auto_select"]: # entry point
area_keyword_1 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_1"] if homepage is None:
area_keyword_1 = area_keyword_1.strip() homepage = ""
if len(homepage) == 0:
homepage = CONST_HOMEPAGE_DEFAULT
if 'area_keyword_2' in config_dict["tixcraft"]["area_auto_select"]: Root_Dir = get_app_root()
area_keyword_2 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_2"] webdriver_path = os.path.join(Root_Dir, "webdriver")
area_keyword_2 = area_keyword_2.strip() print("platform.system().lower():", platform.system().lower())
if 'area_keyword_3' in config_dict["tixcraft"]["area_auto_select"]: adblock_plus_enable = config_dict["advanced"]["adblock_plus_enable"]
area_keyword_3 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_3"] print("adblock_plus_enable:", adblock_plus_enable)
area_keyword_3 = area_keyword_3.strip()
if 'area_keyword_4' in config_dict["tixcraft"]["area_auto_select"]: if browser == "chrome":
area_keyword_4 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_4"] # method 6: Selenium Stealth
area_keyword_4 = area_keyword_4.strip() if driver_type != "undetected_chromedriver":
driver = load_chromdriver_normal(webdriver_path, driver_type, adblock_plus_enable)
pass_1_seat_remaining_enable = False
if 'pass_1_seat_remaining' in config_dict["tixcraft"]:
pass_1_seat_remaining_enable = config_dict["tixcraft"]["pass_1_seat_remaining"]
pass_date_is_sold_out_enable = False
if 'pass_date_is_sold_out' in config_dict["tixcraft"]:
pass_date_is_sold_out_enable = config_dict["tixcraft"]["pass_date_is_sold_out"]
auto_reload_coming_soon_page_enable = True
if 'auto_reload_coming_soon_page' in config_dict["tixcraft"]:
auto_reload_coming_soon_page_enable = config_dict["tixcraft"]["auto_reload_coming_soon_page"]
# output config:
print("maxbot app version", CONST_APP_VERSION)
print("python version", platform.python_version())
print("homepage", homepage)
print("browser", browser)
print("ticket_number", ticket_number)
# for kktix
print("==[kktix]==")
print("auto_press_next_step_button", auto_press_next_step_button)
print("auto_fill_ticket_number", auto_fill_ticket_number)
print("kktix_area_keyword", kktix_area_keyword)
print("kktix_date_keyword", kktix_date_keyword)
print("auto_guess_options", auto_guess_options)
# for tixcraft
print("==[tixcraft]==")
print("date_auto_select_enable", date_auto_select_enable)
print("date_auto_select_mode", date_auto_select_mode)
print("date_keyword", date_keyword)
print("area_auto_select_enable", area_auto_select_enable)
print("area_auto_select_mode", area_auto_select_mode)
print("area_keyword_1", area_keyword_1)
print("area_keyword_2", area_keyword_2)
print("area_keyword_3", area_keyword_3)
print("area_keyword_4", area_keyword_4)
print("pass_1_seat_remaining", pass_1_seat_remaining_enable)
print("pass_date_is_sold_out", pass_date_is_sold_out_enable)
print("auto_reload_coming_soon_page", auto_reload_coming_soon_page_enable)
print("debug Mode", debugMode)
# entry point
if homepage is None:
homepage = ""
if len(homepage) == 0:
homepage = CONST_HOMEPAGE_DEFAULT
Root_Dir = get_app_root()
webdriver_path = os.path.join(Root_Dir, "webdriver")
print("platform.system().lower():", platform.system().lower())
adblock_plus_enable = config_dict["advanced"]["adblock_plus_enable"]
print("adblock_plus_enable:", adblock_plus_enable)
if browser == "chrome":
# method 6: Selenium Stealth
if driver_type != "undetected_chromedriver":
driver = load_chromdriver_normal(webdriver_path, driver_type, adblock_plus_enable)
else:
# method 5: uc
# multiprocessing not work bug.
if platform.system().lower()=="windows":
if hasattr(sys, 'frozen'):
from multiprocessing import freeze_support
freeze_support()
driver = load_chromdriver_uc(webdriver_path, adblock_plus_enable)
if browser == "firefox":
# default os is linux/mac
chromedriver_path = os.path.join(webdriver_path,"geckodriver")
if platform.system().lower()=="windows":
chromedriver_path = os.path.join(webdriver_path,"geckodriver.exe")
firefox_service = Service(chromedriver_path)
driver = webdriver.Firefox(service=firefox_service)
#print("try to close opened tabs.")
'''
time.sleep(1.0)
for i in range(1):
close_browser_tabs(driver)
'''
if driver is None:
print("create web driver object fail @_@;")
else: else:
try: # method 5: uc
print("goto url:", homepage) # multiprocessing not work bug.
if homepage=="https://tixcraft.com": if platform.system().lower()=="windows":
homepage="https://tixcraft.com/user/changeLanguage/lang/zh_tw" if hasattr(sys, 'frozen'):
driver.get(homepage) from multiprocessing import freeze_support
except WebDriverException as exce2: freeze_support()
print('oh no not again, WebDriverException') driver = load_chromdriver_uc(webdriver_path, adblock_plus_enable)
print('WebDriverException:', exce2)
except Exception as exce1: if browser == "firefox":
print('get URL Exception:', exec1) # default os is linux/mac
pass chromedriver_path = os.path.join(webdriver_path,"geckodriver")
if platform.system().lower()=="windows":
chromedriver_path = os.path.join(webdriver_path,"geckodriver.exe")
firefox_service = Service(chromedriver_path)
driver = webdriver.Firefox(service=firefox_service)
#print("try to close opened tabs.")
'''
time.sleep(1.0)
for i in range(1):
close_browser_tabs(driver)
'''
if driver is None:
print("create web driver object fail @_@;")
else: else:
print("Config error!") try:
print("goto url:", homepage)
if homepage=="https://tixcraft.com":
homepage="https://tixcraft.com/user/changeLanguage/lang/zh_tw"
driver.get(homepage)
except WebDriverException as exce2:
print('oh no not again, WebDriverException')
print('WebDriverException:', exce2)
except Exception as exce1:
print('get URL Exception:', exec1)
pass
return driver return driver
@ -1203,7 +1150,7 @@ def tixcraft_area_auto_select(driver, url, config_dict):
if areas is None: if areas is None:
if show_debug_message: if show_debug_message:
print("use area keyword #2", area_keyword_2) print("use area keyword #2", area_keyword_2)
# only when keyword#2 filled to query. # only when keyword#2 filled to query.
if len(area_keyword_2) > 0 : if len(area_keyword_2) > 0 :
is_need_refresh, areas = get_tixcraft_target_area(el, area_keyword_2, area_auto_select_mode, pass_1_seat_remaining_enable) is_need_refresh, areas = get_tixcraft_target_area(el, area_keyword_2, area_auto_select_mode, pass_1_seat_remaining_enable)
@ -1214,7 +1161,7 @@ def tixcraft_area_auto_select(driver, url, config_dict):
if areas is None: if areas is None:
if show_debug_message: if show_debug_message:
print("use area keyword #3", area_keyword_3) print("use area keyword #3", area_keyword_3)
# only when keyword#3 filled to query. # only when keyword#3 filled to query.
if len(area_keyword_3) > 0 : if len(area_keyword_3) > 0 :
is_need_refresh, areas = get_tixcraft_target_area(el, area_keyword_3, area_auto_select_mode, pass_1_seat_remaining_enable) is_need_refresh, areas = get_tixcraft_target_area(el, area_keyword_3, area_auto_select_mode, pass_1_seat_remaining_enable)
@ -1225,7 +1172,7 @@ def tixcraft_area_auto_select(driver, url, config_dict):
if areas is None: if areas is None:
if show_debug_message: if show_debug_message:
print("use area keyword #4", area_keyword_4) print("use area keyword #4", area_keyword_4)
# only when keyword#4 filled to query. # only when keyword#4 filled to query.
if len(area_keyword_4) > 0 : if len(area_keyword_4) > 0 :
is_need_refresh, areas = get_tixcraft_target_area(el, area_keyword_4, area_auto_select_mode, pass_1_seat_remaining_enable) is_need_refresh, areas = get_tixcraft_target_area(el, area_keyword_4, area_auto_select_mode, pass_1_seat_remaining_enable)
@ -1549,7 +1496,7 @@ def tixcraft_ticket_main(driver, config_dict):
select_obj = Select(form_select) select_obj = Select(form_select)
except Exception as exc: except Exception as exc:
pass pass
is_verifyCode_editing = False is_verifyCode_editing = False
is_assign_ticket_number = False is_assign_ticket_number = False
if not select_obj is None: if not select_obj is None:
@ -1688,7 +1635,7 @@ def kktix_press_next_button(driver):
is_visible = True is_visible = True
except Exception as exc: except Exception as exc:
pass pass
if is_visible: if is_visible:
try: try:
driver.execute_script("arguments[0].click();", next_step_button) driver.execute_script("arguments[0].click();", next_step_button)
@ -1747,10 +1694,10 @@ def kktix_input_captcha_text(captcha_password_input_tag, captcha_password_string
is_cpatcha_sent = True is_cpatcha_sent = True
except Exception as exc: except Exception as exc:
pass pass
return is_cpatcha_sent return is_cpatcha_sent
def kktix_travel_price_list(driver, kktix_area_keyword, kktix_date_keyword): def kktix_travel_price_list(driver, kktix_area_keyword_1, kktix_area_keyword_1_and):
show_debug_message = True # debug. show_debug_message = True # debug.
show_debug_message = False # online show_debug_message = False # online
@ -1774,19 +1721,19 @@ def kktix_travel_price_list(driver, kktix_area_keyword, kktix_date_keyword):
print("start to travel rows..........") print("start to travel rows..........")
else: else:
print("find ticket-price span fail") print("find ticket-price span fail")
is_travel_interrupted = False is_travel_interrupted = False
if price_list_count > 0: if price_list_count > 0:
areas = [] areas = []
# clean stop word. # clean stop word.
kktix_area_keyword = format_keyword_string(kktix_area_keyword) kktix_area_keyword_1 = format_keyword_string(kktix_area_keyword_1)
kktix_date_keyword = format_keyword_string(kktix_date_keyword) kktix_area_keyword_1_and = format_keyword_string(kktix_area_keyword_1_and)
if show_debug_message: if show_debug_message:
print('kktix_area_keyword:', kktix_area_keyword) print('kktix_area_keyword_1:', kktix_area_keyword_1)
print('kktix_date_keyword:', kktix_date_keyword) print('kktix_area_keyword_1_and:', kktix_area_keyword_1_and)
row_index = 0 row_index = 0
for row in ticket_price_list: for row in ticket_price_list:
@ -1825,7 +1772,7 @@ def kktix_travel_price_list(driver, kktix_area_keyword, kktix_date_keyword):
is_visible = ticket_price_input.is_enabled() is_visible = ticket_price_input.is_enabled()
except Exception as exc: except Exception as exc:
pass pass
if len(current_ticket_number) > 0: if len(current_ticket_number) > 0:
if current_ticket_number != "0": if current_ticket_number != "0":
is_ticket_number_assigened = True is_ticket_number_assigened = True
@ -1838,23 +1785,23 @@ def kktix_travel_price_list(driver, kktix_area_keyword, kktix_date_keyword):
is_match_area = False is_match_area = False
match_area_code = 0 match_area_code = 0
if len(kktix_area_keyword) == 0: if len(kktix_area_keyword_1) == 0:
# keyword #1, empty, direct add to list. # keyword #1, empty, direct add to list.
is_match_area = True is_match_area = True
match_area_code = 1 match_area_code = 1
else: else:
# MUST match keyword #1. # MUST match keyword #1.
if kktix_area_keyword in row_text: if kktix_area_keyword_1 in row_text:
#print('match keyword#1') #print('match keyword#1')
# because of logic between keywords is AND! # because of logic between keywords is AND!
if len(kktix_date_keyword) == 0: if len(kktix_area_keyword_1_and) == 0:
#print('keyword#2 is empty, directly match.') #print('keyword#2 is empty, directly match.')
# keyword #2 is empty, direct append. # keyword #2 is empty, direct append.
is_match_area = True is_match_area = True
match_area_code = 2 match_area_code = 2
else: else:
if kktix_date_keyword in row_text: if kktix_area_keyword_1_and in row_text:
#print('match keyword#2') #print('match keyword#2')
is_match_area = True is_match_area = True
match_area_code = 3 match_area_code = 3
@ -1886,11 +1833,11 @@ def kktix_travel_price_list(driver, kktix_area_keyword, kktix_date_keyword):
return is_ticket_number_assigened, areas return is_ticket_number_assigened, areas
def kktix_assign_ticket_number(driver, ticket_number, kktix_area_auto_select_mode, kktix_area_keyword, kktix_date_keyword): def kktix_assign_ticket_number(driver, ticket_number, kktix_area_auto_select_mode, kktix_area_keyword_1, kktix_area_keyword_1_and):
show_debug_message = True # debug. show_debug_message = True # debug.
show_debug_message = False # online show_debug_message = False # online
is_ticket_number_assigened, areas = kktix_travel_price_list(driver, kktix_area_keyword, kktix_date_keyword) is_ticket_number_assigened, areas = kktix_travel_price_list(driver, kktix_area_keyword_1, kktix_area_keyword_1_and)
target_area = None target_area = None
if not is_ticket_number_assigened: if not is_ticket_number_assigened:
@ -2051,7 +1998,7 @@ def kktix_check_agree_checkbox(driver):
is_need_refresh = True is_need_refresh = True
else: else:
is_need_refresh = True is_need_refresh = True
if is_need_refresh: if is_need_refresh:
print("find person_agree_terms checkbox fail, do refresh page.") print("find person_agree_terms checkbox fail, do refresh page.")
@ -2524,17 +2471,23 @@ def kktix_reg_new_main(driver, answer_index, is_finish_checkbox_click, config_di
except Exception as exc: except Exception as exc:
pass pass
#print("find input fail:", exc) #print("find input fail:", exc)
# part 2: assign ticket number # part 2: assign ticket number
ticket_number = str(config_dict["ticket_number"]) ticket_number = str(config_dict["ticket_number"])
is_assign_ticket_number = False is_assign_ticket_number = False
if not registrationsNewApp_div is None: if not registrationsNewApp_div is None:
kktix_area_auto_select_mode = config_dict["kktix"]["area_mode"] kktix_area_auto_select_mode = config_dict["kktix"]["area_mode"]
kktix_area_keyword = config_dict["kktix"]["area_keyword"].strip() kktix_area_keyword_1 = config_dict["kktix"]["area_keyword_1"].strip()
kktix_date_keyword = config_dict["kktix"]["date_keyword"].strip() kktix_area_keyword_1_and = config_dict["kktix"]["area_keyword_1_and"].strip()
kktix_area_keyword_2 = config_dict["kktix"]["area_keyword_2"].strip()
kktix_area_keyword_2_and = config_dict["kktix"]["area_keyword_2_and"].strip()
for retry_index in range(3): for retry_index in range(2):
is_assign_ticket_number = kktix_assign_ticket_number(driver, ticket_number, kktix_area_auto_select_mode, kktix_area_keyword, kktix_date_keyword) is_assign_ticket_number = kktix_assign_ticket_number(driver, ticket_number, kktix_area_auto_select_mode, kktix_area_keyword_1, kktix_area_keyword_1_and)
if not is_assign_ticket_number:
is_assign_ticket_number = kktix_assign_ticket_number(driver, ticket_number, kktix_area_auto_select_mode, kktix_area_keyword_1, kktix_area_keyword_1_and)
if not is_assign_ticket_number:
is_assign_ticket_number = kktix_assign_ticket_number(driver, ticket_number, kktix_area_auto_select_mode, kktix_area_keyword_2, kktix_area_keyword_2_and)
if is_assign_ticket_number: if is_assign_ticket_number:
break break
#print('is_assign_ticket_number:', is_assign_ticket_number) #print('is_assign_ticket_number:', is_assign_ticket_number)
@ -2568,10 +2521,10 @@ def kktix_reg_new_main(driver, answer_index, is_finish_checkbox_click, config_di
is_captcha_appear = True is_captcha_appear = True
if show_debug_message: if show_debug_message:
print("found captcha_inner_div layor.") print("found captcha_inner_div layor.")
auto_guess_options = config_dict["kktix"]["auto_guess_options"] auto_guess_options = config_dict["kktix"]["auto_guess_options"]
captcha_password_string, answer_list, my_answer_delimitor = kktix_reg_new_captcha(registrationsNewApp_div, captcha_inner_div, auto_guess_options) captcha_password_string, answer_list, my_answer_delimitor = kktix_reg_new_captcha(registrationsNewApp_div, captcha_inner_div, auto_guess_options)
if captcha_password_string is not None: if captcha_password_string is not None:
# password is not None, try to send. # password is not None, try to send.
is_cpatcha_sent = kktix_input_captcha_text(captcha_password_input_tag, captcha_password_string) is_cpatcha_sent = kktix_input_captcha_text(captcha_password_input_tag, captcha_password_string)
@ -2603,7 +2556,7 @@ def kktix_reg_new_main(driver, answer_index, is_finish_checkbox_click, config_di
# let user to input answer, bot sleep 1 second. # let user to input answer, bot sleep 1 second.
except Exception as exc: except Exception as exc:
pass pass
if show_debug_message: if show_debug_message:
print("is_captcha_appear:", is_captcha_appear) print("is_captcha_appear:", is_captcha_appear)
print("is_captcha_appear_and_filled_password:", is_captcha_appear_and_filled_password) print("is_captcha_appear_and_filled_password:", is_captcha_appear_and_filled_password)
@ -2615,7 +2568,7 @@ def kktix_reg_new_main(driver, answer_index, is_finish_checkbox_click, config_di
is_do_press_next_button = False is_do_press_next_button = False
if is_assign_ticket_number: if is_assign_ticket_number:
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"]
if auto_press_next_step_button: if auto_press_next_step_button:
if is_finish_checkbox_click: if is_finish_checkbox_click:
is_do_press_next_button = kktix_double_check_all_text_value(driver, ticket_number) is_do_press_next_button = kktix_double_check_all_text_value(driver, ticket_number)
else: else:
@ -2831,7 +2784,7 @@ def get_fami_target_area(driver, date_keyword, area_keyword_1, area_keyword_2, a
except Exception as exc: except Exception as exc:
print("get row text fail") print("get row text fail")
break break
if row_text is None: if row_text is None:
row_text = "" row_text = ""
@ -2851,7 +2804,7 @@ def get_fami_target_area(driver, date_keyword, area_keyword_1, area_keyword_2, a
if area_keyword_1 in area_html_text: if area_keyword_1 in area_html_text:
#print("is_match_area area_keyword_1") #print("is_match_area area_keyword_1")
is_match_area = True is_match_area = True
# check keyword 2 # check keyword 2
if len(area_keyword_2) > 0: if len(area_keyword_2) > 0:
if area_keyword_2 in area_html_text: if area_keyword_2 in area_html_text:
@ -2965,7 +2918,7 @@ def fami_home(driver, url, config_dict):
is_select_box_visible = True is_select_box_visible = True
except Exception as exc: except Exception as exc:
pass pass
is_assign_ticket_number = False is_assign_ticket_number = False
if is_select_box_visible: if is_select_box_visible:
ticket_number_select = None ticket_number_select = None
@ -3477,7 +3430,7 @@ def cityline_next_button_press(driver):
def cityline_performance(driver, config_dict): def cityline_performance(driver, config_dict):
show_debug_message = True # debug. show_debug_message = True # debug.
#show_debug_message = False # online #show_debug_message = False # online
auto_fill_ticket_number = config_dict["kktix"]["auto_fill_ticket_number"] auto_fill_ticket_number = config_dict["kktix"]["auto_fill_ticket_number"]
if auto_fill_ticket_number: if auto_fill_ticket_number:
# click price row. # click price row.
@ -3548,7 +3501,7 @@ def facebook_login(driver, facebook_account):
pass pass
el_pass = None el_pass = None
if is_email_sent: if is_email_sent:
try: try:
el_pass = driver.find_element(By.CSS_SELECTOR, '#pass') el_pass = driver.find_element(By.CSS_SELECTOR, '#pass')
except Exception as exc: except Exception as exc:
@ -3663,7 +3616,11 @@ def main():
#driver_type = 'stealth' #driver_type = 'stealth'
driver_type = 'undetected_chromedriver' driver_type = 'undetected_chromedriver'
driver = get_driver_by_config(config_dict, driver_type) driver = None
if not config_dict is None:
driver = get_driver_by_config(config_dict, driver_type)
else:
print("Config error!")
# internal variable. 說明:這是一個內部變數,請略過。 # internal variable. 說明:這是一個內部變數,請略過。
url = "" url = ""
@ -3702,7 +3659,7 @@ def main():
url = "" url = ""
try: try:
url = driver.current_url url = driver.current_url
except NoSuchWindowException: except NoSuchWindowException:
#print('NoSuchWindowException at this url:', url ) #print('NoSuchWindowException at this url:', url )
#print("last_url:", last_url) #print("last_url:", last_url)
@ -3722,7 +3679,7 @@ def main():
# PS: do nothing... # PS: do nothing...
# PS: current chrome-driver + chrome call current_url cause alert/prompt dialog disappear! # PS: current chrome-driver + chrome call current_url cause alert/prompt dialog disappear!
# raise exception at selenium/webdriver/remote/errorhandler.py # raise exception at selenium/webdriver/remote/errorhandler.py
# after dialog disappear new excpetion: unhandled inspector error: Not attached to an active page # after dialog disappear new excpetion: unhandled inspector error: Not attached to an active page
is_pass_alert = False is_pass_alert = False
is_pass_alert = True is_pass_alert = True

View File

@ -19,7 +19,7 @@ import json
import webbrowser import webbrowser
import pyperclip import pyperclip
CONST_APP_VERSION = u"MaxBot (2022.11.21)" CONST_APP_VERSION = u"MaxBot (2022.11.22)"
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"
@ -262,8 +262,10 @@ def get_default_config():
config_dict["kktix"]["auto_press_next_step_button"] = True config_dict["kktix"]["auto_press_next_step_button"] = True
config_dict["kktix"]["auto_fill_ticket_number"] = True config_dict["kktix"]["auto_fill_ticket_number"] = True
config_dict["kktix"]["area_mode"] = CONST_SELECT_ORDER_DEFAULT config_dict["kktix"]["area_mode"] = CONST_SELECT_ORDER_DEFAULT
config_dict["kktix"]["area_keyword"] = "" config_dict["kktix"]["area_keyword_1"] = ""
config_dict["kktix"]["date_keyword"] = "" config_dict["kktix"]["area_keyword_1_and"] = ""
config_dict["kktix"]["area_keyword_2"] = ""
config_dict["kktix"]["area_keyword_2_and"] = ""
config_dict["kktix"]["auto_guess_options"] = True config_dict["kktix"]["auto_guess_options"] = True
config_dict['tixcraft']={} config_dict['tixcraft']={}
@ -328,8 +330,10 @@ def btn_save_act(slience_mode=False):
global chk_state_auto_press_next_step_button global chk_state_auto_press_next_step_button
global chk_state_auto_fill_ticket_number global chk_state_auto_fill_ticket_number
global txt_kktix_area_keyword global txt_kktix_area_keyword_1
global txt_kktix_date_keyword global txt_kktix_area_keyword_1_and
global txt_kktix_area_keyword_2
global txt_kktix_area_keyword_2_and
# disable password brute force attack # disable password brute force attack
global txt_kktix_answer_dictionary global txt_kktix_answer_dictionary
@ -386,21 +390,17 @@ def btn_save_act(slience_mode=False):
config_dict["ticket_number"] = int(combo_ticket_number.get().strip()) config_dict["ticket_number"] = int(combo_ticket_number.get().strip())
if is_all_data_correct: if is_all_data_correct:
if not 'kktix' in config_dict:
config_dict['kktix']={}
config_dict["kktix"]["auto_press_next_step_button"] = bool(chk_state_auto_press_next_step_button.get()) config_dict["kktix"]["auto_press_next_step_button"] = bool(chk_state_auto_press_next_step_button.get())
config_dict["kktix"]["auto_fill_ticket_number"] = bool(chk_state_auto_fill_ticket_number.get()) config_dict["kktix"]["auto_fill_ticket_number"] = bool(chk_state_auto_fill_ticket_number.get())
config_dict["kktix"]["area_mode"] = combo_kktix_area_mode.get().strip() config_dict["kktix"]["area_mode"] = combo_kktix_area_mode.get().strip()
config_dict["kktix"]["area_keyword"] = txt_kktix_area_keyword.get().strip() config_dict["kktix"]["area_keyword_1"] = txt_kktix_area_keyword_1.get().strip()
config_dict["kktix"]["date_keyword"] = txt_kktix_date_keyword.get().strip() config_dict["kktix"]["area_keyword_1_and"] = txt_kktix_area_keyword_1_and.get().strip()
config_dict["kktix"]["area_keyword_2"] = txt_kktix_area_keyword_2.get().strip()
config_dict["kktix"]["area_keyword_2_and"] = txt_kktix_area_keyword_2_and.get().strip()
# disable password brute force attack # disable password brute force attack
#config_dict["kktix"]["answer_dictionary"] = txt_kktix_answer_dictionary.get().strip() #config_dict["kktix"]["answer_dictionary"] = txt_kktix_answer_dictionary.get().strip()
config_dict["kktix"]["auto_guess_options"] = bool(chk_state_auto_guess_options.get()) config_dict["kktix"]["auto_guess_options"] = bool(chk_state_auto_guess_options.get())
if not 'tixcraft' in config_dict:
config_dict['tixcraft']={}
config_dict["tixcraft"]["date_auto_select"]["enable"] = bool(chk_state_date_auto_select.get()) config_dict["tixcraft"]["date_auto_select"]["enable"] = bool(chk_state_date_auto_select.get())
config_dict["tixcraft"]["date_auto_select"]["date_keyword"] = txt_date_keyword.get().strip() config_dict["tixcraft"]["date_auto_select"]["date_keyword"] = txt_date_keyword.get().strip()
@ -417,12 +417,6 @@ def btn_save_act(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())
if not 'advanced' in config_dict:
config_dict['advanced']={}
if not 'play_captcha_sound' in config_dict['advanced']:
config_dict['advanced']['play_captcha_sound']={}
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()
@ -563,8 +557,10 @@ def applyNewLanguage():
global lbl_auto_press_next_step_button global lbl_auto_press_next_step_button
global lbl_auto_fill_ticket_number global lbl_auto_fill_ticket_number
global lbl_kktix_area_mode global lbl_kktix_area_mode
global lbl_kktix_area_keyword global lbl_kktix_area_keyword_1
global lbl_kktix_area_keyword_and_text global lbl_kktix_area_keyword_1_and_text
global lbl_kktix_area_keyword_2
global lbl_kktix_area_keyword_2_and_text
global lbl_auto_guess_options global lbl_auto_guess_options
# for tixcraft # for tixcraft
@ -612,8 +608,10 @@ def applyNewLanguage():
lbl_auto_press_next_step_button.config(text=translate[language_code]["auto_press_next_step_button"]) lbl_auto_press_next_step_button.config(text=translate[language_code]["auto_press_next_step_button"])
lbl_auto_fill_ticket_number.config(text=translate[language_code]["auto_fill_ticket_number"]) lbl_auto_fill_ticket_number.config(text=translate[language_code]["auto_fill_ticket_number"])
lbl_kktix_area_mode.config(text=translate[language_code]["area_select_order"]) lbl_kktix_area_mode.config(text=translate[language_code]["area_select_order"])
lbl_kktix_area_keyword.config(text=translate[language_code]["area_keyword"]) lbl_kktix_area_keyword_1.config(text=translate[language_code]["area_keyword_1"])
lbl_kktix_area_keyword_and_text.config(text=translate[language_code]["and"]) lbl_kktix_area_keyword_1_and_text.config(text=translate[language_code]["and"])
lbl_kktix_area_keyword_2.config(text=translate[language_code]["area_keyword_2"])
lbl_kktix_area_keyword_2_and_text.config(text=translate[language_code]["and"])
lbl_auto_guess_options.config(text=translate[language_code]["auto_guess_options"]) lbl_auto_guess_options.config(text=translate[language_code]["auto_guess_options"])
lbl_date_auto_select.config(text=translate[language_code]["date_auto_select"]) lbl_date_auto_select.config(text=translate[language_code]["date_auto_select"])
lbl_date_auto_select_mode.config(text=translate[language_code]["date_select_order"]) lbl_date_auto_select_mode.config(text=translate[language_code]["date_select_order"])
@ -839,8 +837,10 @@ def PreferenctTab(root, config_dict, language_code, UI_PADDING_X):
auto_fill_ticket_number = False auto_fill_ticket_number = False
kktix_area_mode = "" kktix_area_mode = ""
kktix_area_keyword = "" kktix_area_keyword_1 = ""
kktix_date_keyword = "" kktix_area_keyword_1_and = ""
kktix_area_keyword_2 = ""
kktix_area_keyword_2_and = ""
# disable password brute force attack # disable password brute force attack
# PS: because of the question is always variable. # PS: because of the question is always variable.
#kktix_answer_dictionary = "" #kktix_answer_dictionary = ""
@ -879,8 +879,10 @@ def PreferenctTab(root, config_dict, language_code, UI_PADDING_X):
kktix_area_mode = config_dict["kktix"]["area_mode"].strip() kktix_area_mode = config_dict["kktix"]["area_mode"].strip()
if not kktix_area_mode in CONST_SELECT_OPTIONS_ARRAY: if not kktix_area_mode in CONST_SELECT_OPTIONS_ARRAY:
kktix_area_mode = CONST_SELECT_ORDER_DEFAULT kktix_area_mode = CONST_SELECT_ORDER_DEFAULT
kktix_area_keyword = config_dict["kktix"]["area_keyword"].strip() kktix_area_keyword_1 = config_dict["kktix"]["area_keyword_1"].strip()
kktix_date_keyword = config_dict["kktix"]["date_keyword"].strip() kktix_area_keyword_1_and = config_dict["kktix"]["area_keyword_1_and"].strip()
kktix_area_keyword_2 = config_dict["kktix"]["area_keyword_2"].strip()
kktix_area_keyword_2_and = config_dict["kktix"]["area_keyword_2_and"].strip()
auto_guess_options = config_dict["kktix"]["auto_guess_options"] auto_guess_options = config_dict["kktix"]["auto_guess_options"]
# disable password brute force attack # disable password brute force attack
@ -922,8 +924,8 @@ def PreferenctTab(root, config_dict, language_code, UI_PADDING_X):
print("auto_press_next_step_button", auto_press_next_step_button) print("auto_press_next_step_button", auto_press_next_step_button)
print("auto_fill_ticket_number", auto_fill_ticket_number) print("auto_fill_ticket_number", auto_fill_ticket_number)
print("kktix_area_mode", kktix_area_mode) print("kktix_area_mode", kktix_area_mode)
print("kktix_area_keyword", kktix_area_keyword) print("kktix_area_keyword_1", kktix_area_keyword_1)
print("kktix_date_keyword", kktix_date_keyword) print("kktix_area_keyword_1_and", kktix_area_keyword_1_and)
# disable password brute force attack # disable password brute force attack
#print("kktix_answer_dictionary", kktix_answer_dictionary) #print("kktix_answer_dictionary", kktix_answer_dictionary)
print("auto_guess_options", auto_guess_options) print("auto_guess_options", auto_guess_options)
@ -1079,33 +1081,63 @@ def PreferenctTab(root, config_dict, language_code, UI_PADDING_X):
group_row_count+=1 group_row_count+=1
global lbl_kktix_area_keyword global lbl_kktix_area_keyword_1
lbl_kktix_area_keyword = Label(frame_group_kktix, text=translate[language_code]['area_keyword']) lbl_kktix_area_keyword_1 = Label(frame_group_kktix, text=translate[language_code]['area_keyword_1'])
lbl_kktix_area_keyword.grid(column=0, row=group_row_count, sticky = E) lbl_kktix_area_keyword_1.grid(column=0, row=group_row_count, sticky = E)
global txt_kktix_area_keyword global txt_kktix_area_keyword_1
txt_kktix_area_keyword_value = StringVar(frame_group_kktix, value=kktix_area_keyword) txt_kktix_area_keyword_1_value = StringVar(frame_group_kktix, value=kktix_area_keyword_1)
txt_kktix_area_keyword = Entry(frame_group_kktix, width=20, textvariable = txt_kktix_area_keyword_value) txt_kktix_area_keyword_1 = Entry(frame_group_kktix, width=20, textvariable = txt_kktix_area_keyword_1_value)
txt_kktix_area_keyword.grid(column=1, row=group_row_count, sticky = W) txt_kktix_area_keyword_1.grid(column=1, row=group_row_count, sticky = W)
group_row_count+=1 group_row_count+=1
lbl_kktix_area_keyword_and_label = Label(frame_group_kktix, text="") lbl_kktix_area_keyword_1_and_label = Label(frame_group_kktix, text="")
lbl_kktix_area_keyword_and_label.grid(column=0, row=group_row_count, sticky = E) lbl_kktix_area_keyword_1_and_label.grid(column=0, row=group_row_count, sticky = E)
global lbl_kktix_area_keyword_and_text global lbl_kktix_area_keyword_1_and_text
lbl_kktix_area_keyword_and_text = Label(frame_group_kktix, text=translate[language_code]['and']) lbl_kktix_area_keyword_1_and_text = Label(frame_group_kktix, text=translate[language_code]['and'])
lbl_kktix_area_keyword_and_text.grid(column=1, row=group_row_count, sticky = W) lbl_kktix_area_keyword_1_and_text.grid(column=1, row=group_row_count, sticky = W)
group_row_count+=1 group_row_count+=1
lbl_kktix_date_keyword = Label(frame_group_kktix, text="") lbl_kktix_area_keyword_1_tmp = Label(frame_group_kktix, text="")
lbl_kktix_date_keyword.grid(column=0, row=group_row_count, sticky = E) lbl_kktix_area_keyword_1_tmp.grid(column=0, row=group_row_count, sticky = E)
global txt_kktix_date_keyword global txt_kktix_area_keyword_1_and
txt_kktix_date_keyword_value = StringVar(frame_group_kktix, value=kktix_date_keyword) txt_kktix_area_keyword_1_and_value = StringVar(frame_group_kktix, value=kktix_area_keyword_1_and)
txt_kktix_date_keyword = Entry(frame_group_kktix, width=20, textvariable = txt_kktix_date_keyword_value) txt_kktix_area_keyword_1_and = Entry(frame_group_kktix, width=20, textvariable = txt_kktix_area_keyword_1_and_value)
txt_kktix_date_keyword.grid(column=1, row=group_row_count, sticky = W) txt_kktix_area_keyword_1_and.grid(column=1, row=group_row_count, sticky = W)
group_row_count+=1
global lbl_kktix_area_keyword_2
lbl_kktix_area_keyword_2 = Label(frame_group_kktix, text=translate[language_code]['area_keyword_2'])
lbl_kktix_area_keyword_2.grid(column=0, row=group_row_count, sticky = E)
global txt_kktix_area_keyword_2
txt_kktix_area_keyword_2_value = StringVar(frame_group_kktix, value=kktix_area_keyword_2)
txt_kktix_area_keyword_2 = Entry(frame_group_kktix, width=20, textvariable = txt_kktix_area_keyword_2_value)
txt_kktix_area_keyword_2.grid(column=1, row=group_row_count, sticky = W)
group_row_count+=1
lbl_kktix_area_keyword_2_and_label = Label(frame_group_kktix, text="")
lbl_kktix_area_keyword_2_and_label.grid(column=0, row=group_row_count, sticky = E)
global lbl_kktix_area_keyword_2_and_text
lbl_kktix_area_keyword_2_and_text = Label(frame_group_kktix, text=translate[language_code]['and'])
lbl_kktix_area_keyword_2_and_text.grid(column=1, row=group_row_count, sticky = W)
group_row_count+=1
lbl_kktix_area_keyword_2_tmp = Label(frame_group_kktix, text="")
lbl_kktix_area_keyword_2_tmp.grid(column=0, row=group_row_count, sticky = E)
global txt_kktix_area_keyword_2_and
txt_kktix_area_keyword_2_and_value = StringVar(frame_group_kktix, value=kktix_area_keyword_2_and)
txt_kktix_area_keyword_2_and = Entry(frame_group_kktix, width=20, textvariable = txt_kktix_area_keyword_2_and_value)
txt_kktix_area_keyword_2_and.grid(column=1, row=group_row_count, sticky = W)
#group_row_count+=1 #group_row_count+=1