2023-03-22, fine-tune for ibon.

master
CHUN YU YAO 2023-03-25 23:07:16 +08:00
parent 229e714930
commit 13a8c5f1eb
3 changed files with 51 additions and 39 deletions

View File

@ -53,7 +53,7 @@ import argparse
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.03.21)" CONST_APP_VERSION = u"MaxBot (2023.03.22)"
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"
@ -4918,10 +4918,21 @@ def cityline_performance(driver, config_dict):
if click_ret: if click_ret:
break break
def ibon_date_auto_select(driver, auto_select_mode, date_keyword, auto_reload_coming_soon_page_enable): def ibon_date_auto_select(driver, config_dict):
show_debug_message = True # debug. show_debug_message = True # debug.
show_debug_message = False # online show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
auto_select_mode = config_dict["tixcraft"]["date_auto_select"]["mode"]
date_keyword = config_dict["tixcraft"]["date_auto_select"]["date_keyword"].strip()
auto_reload_coming_soon_page_enable = config_dict["tixcraft"]["auto_reload_coming_soon_page"]
if show_debug_message:
print("date_keyword:", date_keyword)
print("auto_reload_coming_soon_page_enable:", auto_reload_coming_soon_page_enable)
ret = False ret = False
matched_blocks = None matched_blocks = None
@ -5054,6 +5065,8 @@ def ibon_date_auto_select(driver, auto_select_mode, date_keyword, auto_reload_co
target_area = matched_blocks[target_row_index] target_area = matched_blocks[target_row_index]
if target_area is not None: if target_area is not None:
is_button_clicked = False
for i in range(3):
el_btn = None el_btn = None
try: try:
my_css_selector = "button.btn" my_css_selector = "button.btn"
@ -5066,15 +5079,22 @@ def ibon_date_auto_select(driver, auto_select_mode, date_keyword, auto_reload_co
if el_btn.is_enabled(): if el_btn.is_enabled():
el_btn.click() el_btn.click()
print("buy icon pressed.") print("buy icon pressed.")
ret = True is_button_clicked = True
except Exception as exc: except Exception as exc:
pass
# use plan B # use plan B
'''
try: try:
print("force to click by js.") print("force to click by js.")
driver.execute_script("arguments[0].click();", el_btn) driver.execute_script("arguments[0].click();", el_btn)
ret = True ret = True
except Exception as exc: except Exception as exc:
pass pass
'''
if is_button_clicked:
break
ret = is_button_clicked
else: else:
# no target to click. # no target to click.
if auto_reload_coming_soon_page_enable: if auto_reload_coming_soon_page_enable:
@ -5088,30 +5108,15 @@ def ibon_date_auto_select(driver, auto_select_mode, date_keyword, auto_reload_co
pass pass
return ret return ret
def ibon_activity_info(driver, config_dict):
show_debug_message = True # debug.
show_debug_message = False # online
date_auto_select_mode = config_dict["tixcraft"]["date_auto_select"]["mode"]
date_keyword = config_dict["tixcraft"]["date_auto_select"]["date_keyword"].strip()
auto_reload_coming_soon_page_enable = config_dict["tixcraft"]["auto_reload_coming_soon_page"]
if show_debug_message:
print("date_keyword:", date_keyword)
print("auto_reload_coming_soon_page_enable:", auto_reload_coming_soon_page_enable)
is_date_assign_by_bot = ibon_date_auto_select(driver, date_auto_select_mode, date_keyword, auto_reload_coming_soon_page_enable)
return is_date_assign_by_bot
def ibon_area_auto_select(driver, config_dict, area_keyword_1, area_keyword_1_and, area_keyword_exclude): def ibon_area_auto_select(driver, config_dict, area_keyword_1, area_keyword_1_and, area_keyword_exclude):
show_debug_message = True # debug. show_debug_message = True # debug.
show_debug_message = False # online show_debug_message = False # online
area_auto_select_mode = config_dict["tixcraft"]["area_auto_select"]["mode"]
if config_dict["advanced"]["verbose"]: if config_dict["advanced"]["verbose"]:
show_debug_message = True show_debug_message = True
area_auto_select_mode = config_dict["tixcraft"]["area_auto_select"]["mode"]
is_price_assign_by_bot = False is_price_assign_by_bot = False
is_need_refresh = False is_need_refresh = False
@ -5124,7 +5129,7 @@ def ibon_area_auto_select(driver, config_dict, area_keyword_1, area_keyword_1_an
area_list = None area_list = None
try: try:
#print("try to find cityline area block") #print("try to find cityline area block")
my_css_selector = "div.col-md-5 > table > tbody > tr" my_css_selector = "div.col-md-5 > table > tbody > tr[onclick=\"onTicketArea(this.id)\"]"
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 #ticket-price-tbl date list fail") print("find #ticket-price-tbl date list fail")
@ -5164,6 +5169,9 @@ def ibon_area_auto_select(driver, config_dict, area_keyword_1, area_keyword_1_an
pass pass
if row_is_enabled: if row_is_enabled:
pass
# each row to check is too slow.
'''
row_is_enabled = False row_is_enabled = False
try: try:
row_id_string = str(row.get_attribute('id')) row_id_string = str(row.get_attribute('id'))
@ -5172,6 +5180,7 @@ def ibon_area_auto_select(driver, config_dict, area_keyword_1, area_keyword_1_an
row_is_enabled = True row_is_enabled = True
except Exception as exc: except Exception as exc:
pass pass
'''
if row_is_enabled: if row_is_enabled:
formated_area_list.append(row) formated_area_list.append(row)
@ -6498,7 +6507,7 @@ def ibon_main(driver, url, config_dict, ibon_dict):
date_auto_select_enable = config_dict["tixcraft"]["date_auto_select"]["enable"] date_auto_select_enable = config_dict["tixcraft"]["date_auto_select"]["enable"]
if date_auto_select_enable: if date_auto_select_enable:
is_match_target_feature = True is_match_target_feature = True
ibon_activity_info(driver, config_dict) is_date_assign_by_bot = ibon_date_auto_select(driver, config_dict)
if not is_match_target_feature: if not is_match_target_feature:
# validation question url: # validation question url:
@ -6529,7 +6538,10 @@ def ibon_main(driver, url, config_dict, ibon_dict):
else: else:
is_sold_out = ibon_check_sold_out(driver) is_sold_out = ibon_check_sold_out(driver)
if is_sold_out: if is_sold_out:
print("is_sold_out, go back , and refresh.")
# plan-A
#is_button_clicked = force_press_button(driver, By.CSS_SELECTOR, 'a.btn.btn-primary') #is_button_clicked = force_press_button(driver, By.CSS_SELECTOR, 'a.btn.btn-primary')
# plan-B, easy and better than plan-A
driver.back() driver.back()
driver.refresh() driver.refresh()

View File

@ -22,7 +22,7 @@ import base64
import threading import threading
import subprocess import subprocess
CONST_APP_VERSION = u"MaxBot (2023.03.21)" CONST_APP_VERSION = u"MaxBot (2023.03.22)"
CONST_MAXBOT_LAUNCHER_FILE = "config_launcher.json" CONST_MAXBOT_LAUNCHER_FILE = "config_launcher.json"
CONST_MAXBOT_CONFIG_FILE = "settings.json" CONST_MAXBOT_CONFIG_FILE = "settings.json"

View File

@ -24,7 +24,7 @@ import time
import threading import threading
import subprocess import subprocess
CONST_APP_VERSION = u"MaxBot (2023.03.21)" CONST_APP_VERSION = u"MaxBot (2023.03.22)"
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"