2023-06-27: ticketplus support two dislay layout

master
Max 2023-06-28 16:10:58 +08:00 committed by GitHub
parent f4c64a3799
commit b03b8c5c5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 122 additions and 17 deletions

View File

@ -53,7 +53,7 @@ import webbrowser
import argparse import argparse
import itertools import itertools
CONST_APP_VERSION = "MaxBot (2023.6.26)" CONST_APP_VERSION = "MaxBot (2023.6.27)"
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"
@ -10199,7 +10199,7 @@ def ticketplus_date_auto_select(driver, config_dict):
return is_date_clicked return is_date_clicked
def ticketplus_order_expansion_auto_select(driver, config_dict, area_keyword_item): def ticketplus_order_expansion_auto_select(driver, config_dict, area_keyword_item, current_layout_style):
show_debug_message = True # debug. show_debug_message = True # debug.
show_debug_message = False # online show_debug_message = False # online
@ -10214,12 +10214,17 @@ def ticketplus_order_expansion_auto_select(driver, config_dict, area_keyword_ite
area_list = None area_list = None
try: try:
#print("try to find cityline area block") # style 2: .text-title
my_css_selector = "div.rwd-margin > div.text-title" my_css_selector = "div.rwd-margin > div.text-title"
if current_layout_style == 1:
# style 1: .text-title
my_css_selector = "div.v-expansion-panels > div.v-expansion-panel"
area_list = driver.find_elements(By.CSS_SELECTOR, my_css_selector) area_list = driver.find_elements(By.CSS_SELECTOR, my_css_selector)
except Exception as exc: except Exception as exc:
print("find .v-expansion-panel date list fail") if current_layout_style == 1:
print(exc) print("find .v-expansion-panels date list fail")
if current_layout_style == 2:
print("find .text-title date list fail")
formated_area_list = None formated_area_list = None
if area_list is not None: if area_list is not None:
@ -10246,12 +10251,17 @@ def ticketplus_order_expansion_auto_select(driver, config_dict, area_keyword_ite
if row_text is None: if row_text is None:
row_text = "" row_text = ""
# for style_2
if '剩餘 0' in row_text: if '剩餘 0' in row_text:
row_text = "" row_text = ""
if '已售完' in row_text: if '已售完' in row_text:
row_text = "" row_text = ""
# for style_1
if '剩餘0' in row_text:
row_text = ""
if len(row_text) > 0: if len(row_text) > 0:
row_text = reset_row_text_if_match_area_keyword_exclude(config_dict, row_text) row_text = reset_row_text_if_match_area_keyword_exclude(config_dict, row_text)
@ -10345,6 +10355,25 @@ def ticketplus_order_expansion_auto_select(driver, config_dict, area_keyword_ite
if show_debug_message: if show_debug_message:
print("matched_blocks is empty, is_need_refresh") print("matched_blocks is empty, is_need_refresh")
# for style_1, need click once.
if show_debug_message:
print("current_layout_style:", current_layout_style)
if current_layout_style==1:
if target_area is not None:
try:
if target_area.is_enabled():
target_area.click()
except Exception as exc:
print("click target_area link fail")
print(exc)
# use plan B
try:
print("force to click by js.")
driver.execute_script("arguments[0].click();", target_area)
except Exception as exc:
pass
is_price_assign_by_bot = False is_price_assign_by_bot = False
if target_area is not None: if target_area is not None:
ticket_number_div = None ticket_number_div = None
@ -10396,7 +10425,7 @@ def ticketplus_order_expansion_auto_select(driver, config_dict, area_keyword_ite
return is_need_refresh, is_price_assign_by_bot return is_need_refresh, is_price_assign_by_bot
def ticketplus_order_expansion_panel(driver, config_dict): def ticketplus_order_expansion_panel(driver, config_dict, current_layout_style):
show_debug_message = True # debug. show_debug_message = True # debug.
show_debug_message = False # online show_debug_message = False # online
@ -10423,14 +10452,14 @@ def ticketplus_order_expansion_panel(driver, config_dict):
area_keyword_array = [] area_keyword_array = []
for area_keyword_item in area_keyword_array: for area_keyword_item in area_keyword_array:
is_need_refresh, is_price_assign_by_bot = ticketplus_order_expansion_auto_select(driver, config_dict, area_keyword_item) is_need_refresh, is_price_assign_by_bot = ticketplus_order_expansion_auto_select(driver, config_dict, area_keyword_item, current_layout_style)
if not is_need_refresh: if not is_need_refresh:
break break
else: else:
print("is_need_refresh for keyword:", area_keyword_item) print("is_need_refresh for keyword:", area_keyword_item)
else: else:
# empty keyword, match all. # empty keyword, match all.
is_need_refresh, is_price_assign_by_bot = ticketplus_order_expansion_auto_select(driver, config_dict, "") is_need_refresh, is_price_assign_by_bot = ticketplus_order_expansion_auto_select(driver, config_dict, "", current_layout_style)
if is_need_refresh: if is_need_refresh:
try: try:
@ -10441,21 +10470,47 @@ def ticketplus_order_expansion_panel(driver, config_dict):
return is_price_assign_by_bot return is_price_assign_by_bot
def ticketplus_order(driver, config_dict, ocr, Captcha_Browser): def ticketplus_order(driver, config_dict, ocr, Captcha_Browser):
show_debug_message = True # debug.
show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
next_step_button = None next_step_button = None
is_button_disabled = False is_button_disabled = False
current_layout_style = 0
try: try:
# for style_2
my_css_selector = "div.order-footer > div.container > div.row > div > button.nextBtn" my_css_selector = "div.order-footer > div.container > div.row > div > button.nextBtn"
next_step_button = driver.find_element(By.CSS_SELECTOR, my_css_selector) next_step_button = driver.find_element(By.CSS_SELECTOR, my_css_selector)
if not next_step_button is None: if not next_step_button is None:
if not next_step_button.is_enabled(): if not next_step_button.is_enabled():
is_button_disabled = True is_button_disabled = True
current_layout_style = 2
except Exception as exc: except Exception as exc:
print("find next_step_button fail") if show_debug_message:
print(exc) print("find next_step_button (style_2) fail")
#print(exc)
pass
# for style_1
try:
my_css_selector = "div.order-footer > div.container > div.row > div > div.row > div > button.nextBtn"
next_step_button = driver.find_element(By.CSS_SELECTOR, my_css_selector)
if not next_step_button is None:
if not next_step_button.is_enabled():
is_button_disabled = True
current_layout_style = 1
except Exception as exc2:
if show_debug_message:
print("find next_step_button (style_1) fail")
#print(exc2)
pass
#print("is_button_disabled:", is_button_disabled) #print("is_button_disabled:", is_button_disabled)
if is_button_disabled: if is_button_disabled:
is_price_assign_by_bot = ticketplus_order_expansion_panel(driver, config_dict) is_price_assign_by_bot = ticketplus_order_expansion_panel(driver, config_dict, current_layout_style)
if is_price_assign_by_bot: if is_price_assign_by_bot:
if config_dict["ocr_captcha"]["enable"]: if config_dict["ocr_captcha"]["enable"]:
ticketplus_order_ocr(driver, config_dict, ocr, Captcha_Browser) ticketplus_order_ocr(driver, config_dict, ocr, Captcha_Browser)
@ -10639,9 +10694,9 @@ def ticketplus_check_and_renew_captcha(driver):
if len(v_messages_string) > 0: if len(v_messages_string) > 0:
is_messages_popup = True is_messages_popup = True
print("error message popup, refresh captcha images.") print("error message popup, refresh captcha images.")
my_css_selector = "div.recaptcha-area > div > div > span > i" my_css_selector = "div.recaptcha-area > div > div > span > i"
is_refresh_button_pressed = force_press_button(driver, By.CSS_SELECTOR, my_css_selector) is_refresh_button_pressed = force_press_button(driver, By.CSS_SELECTOR, my_css_selector)
except Exception as exc: except Exception as exc:
pass pass
return is_messages_popup return is_messages_popup
@ -10715,8 +10770,13 @@ def ticketplus_keyin_captcha_code(driver, answer = "", auto_submit = False):
# ticketplus not able to send enter key. # ticketplus not able to send enter key.
#form_verifyCode.send_keys(Keys.ENTER) #form_verifyCode.send_keys(Keys.ENTER)
# for style_2
my_css_selector = "div.order-footer > div.container > div.row > div > button.nextBtn" my_css_selector = "div.order-footer > div.container > div.row > div > button.nextBtn"
is_form_sumbited = force_press_button(driver, By.CSS_SELECTOR, my_css_selector) is_form_sumbited = force_press_button(driver, By.CSS_SELECTOR, my_css_selector)
if not is_form_sumbited:
# for style_1
my_css_selector = "div.order-footer > div.container > div.row > div > div.row > div > button.nextBtn"
is_form_sumbited = force_press_button(driver, By.CSS_SELECTOR, my_css_selector)
is_verifyCode_editing = False is_verifyCode_editing = False
else: else:
print("select all captcha text") print("select all captcha text")
@ -10729,6 +10789,53 @@ def ticketplus_keyin_captcha_code(driver, answer = "", auto_submit = False):
return is_verifyCode_editing, is_form_sumbited return is_verifyCode_editing, is_form_sumbited
def ticketplus_account_auto_focus(driver, config_dict):
# manually keyin verify code.
form_account = None
try:
my_css_selector = 'input[placeholder="手機號碼 *"]'
form_account = driver.find_element(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
pass
#print("find account input fail")
if form_account is not None:
#print("found account field")
inputed_value = None
try:
inputed_value = form_account.get_attribute('value')
except Exception as exc:
#print("find verify code fail")
pass
if inputed_value is None:
inputed_value = ""
#print("inputed_value:", inputed_value)
if inputed_value == "手機號碼 *":
try:
form_account.clear()
form_account.click()
except Exception as exc:
print("clear account fail")
pass
else:
if len(inputed_value) > 0:
#print("account text inputed.")
pass
else:
try:
# solution 1: js.
driver.execute_script("if(!(document.activeElement === arguments[0])){arguments[0].focus();}", form_account)
# solution 2: selenium.
#form_account.click()
#wait user input.
time.sleep(0.2)
except Exception as exc:
print("auto-focus account fail")
pass
def ticketplus_main(driver, url, config_dict, ocr, Captcha_Browser): def ticketplus_main(driver, url, config_dict, ocr, Captcha_Browser):
home_url_list = ['https://ticketplus.com.tw/'] home_url_list = ['https://ticketplus.com.tw/']
for each_url in home_url_list: for each_url in home_url_list:
@ -10738,6 +10845,8 @@ def ticketplus_main(driver, url, config_dict, ocr, Captcha_Browser):
if not Captcha_Browser is None: if not Captcha_Browser is None:
Captcha_Browser.Set_cookies(driver.get_cookies()) Captcha_Browser.Set_cookies(driver.get_cookies())
Captcha_Browser.Set_Domain(domain_name) Captcha_Browser.Set_Domain(domain_name)
ticketplus_account_auto_focus(driver, config_dict)
break break
# https://ticketplus.com.tw/activity/XXX # https://ticketplus.com.tw/activity/XXX
@ -10802,11 +10911,7 @@ def main(args):
Captcha_Browser = None Captcha_Browser = None
try: try:
if config_dict["ocr_captcha"]["enable"]: if config_dict["ocr_captcha"]["enable"]:
ocr_beta_mode = True ocr = ddddocr.DdddOcr(show_ad=False, beta=config_dict["ocr_captcha"]["beta"])
if "ticketplus" in config_dict["homepage"]:
#ocr_beta_mode = False
pass
ocr = ddddocr.DdddOcr(show_ad=False, beta=ocr_beta_mode)
Captcha_Browser = NonBrowser() Captcha_Browser = NonBrowser()
if len(config_dict["advanced"]["tixcraft_sid"]) > 1: if len(config_dict["advanced"]["tixcraft_sid"]) > 1: