2023-01-04, bugs fixed.

master
CHUN YU YAO 2023-01-04 20:02:55 +08:00
parent a1a8dc969e
commit dd8314d37e
2 changed files with 207 additions and 166 deletions

View File

@ -40,7 +40,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 (2023.01.03)" CONST_APP_VERSION = u"MaxBot (2023.01.04)"
CONST_HOMEPAGE_DEFAULT = "https://tixcraft.com" CONST_HOMEPAGE_DEFAULT = "https://tixcraft.com"
@ -1048,7 +1048,6 @@ def tixcraft_date_auto_select(driver, url, config_dict):
is_date_selected = True is_date_selected = True
except Exception as exc: except Exception as exc:
print("try to click .btn-next fail") print("try to click .btn-next fail")
try: try:
driver.execute_script("arguments[0].click();", el) driver.execute_script("arguments[0].click();", el)
except Exception as exc: except Exception as exc:
@ -1196,6 +1195,9 @@ def get_tixcraft_target_area(el, area_keyword, area_auto_select_mode, pass_1_sea
# PS: auto refresh condition 1: no keyword + no hyperlink. # PS: auto refresh condition 1: no keyword + no hyperlink.
# PS: auto refresh condition 2: with keyword + no hyperlink. # PS: auto refresh condition 2: with keyword + no hyperlink.
def tixcraft_area_auto_select(driver, url, config_dict): def tixcraft_area_auto_select(driver, url, config_dict):
show_debug_message = True # debug.
show_debug_message = False # online
# read config. # read config.
area_keyword_1 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_1"].strip() area_keyword_1 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_1"].strip()
area_keyword_2 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_2"].strip() area_keyword_2 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_2"].strip()
@ -1209,9 +1211,6 @@ def tixcraft_area_auto_select(driver, url, config_dict):
if ticket_number == 1: if ticket_number == 1:
pass_1_seat_remaining_enable = False pass_1_seat_remaining_enable = False
show_debug_message = True # debug.
show_debug_message = False # online
if show_debug_message: if show_debug_message:
print("area_keyword_1, area_keyword_2:", area_keyword_1, area_keyword_2) print("area_keyword_1, area_keyword_2:", area_keyword_1, area_keyword_2)
print("area_keyword_3, area_keyword_4:", area_keyword_3, area_keyword_4) print("area_keyword_3, area_keyword_4:", area_keyword_3, area_keyword_4)
@ -1431,7 +1430,7 @@ def tixcraft_ticket_number_auto_fill(driver, select_obj, ticket_number):
def tixcraft_verify(driver, presale_code): def tixcraft_verify(driver, presale_code):
show_debug_message = True # debug. show_debug_message = True # debug.
#show_debug_message = False # online show_debug_message = False # online
ret = False ret = False
@ -1943,7 +1942,7 @@ def kktix_travel_price_list(driver, ticket_number, pass_1_seat_remaining_enable,
def kktix_assign_ticket_number(driver, ticket_number, pass_1_seat_remaining_enable, kktix_area_auto_select_mode, kktix_area_keyword_1, kktix_area_keyword_1_and): def kktix_assign_ticket_number(driver, ticket_number, pass_1_seat_remaining_enable, 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
ticket_number_str = str(ticket_number) ticket_number_str = str(ticket_number)
@ -2567,7 +2566,7 @@ def kktix_double_check_all_text_value(driver, ticket_number_str):
def kktix_reg_new_main(driver, answer_index, is_finish_checkbox_click, config_dict): def kktix_reg_new_main(driver, answer_index, is_finish_checkbox_click, config_dict):
show_debug_message = True # debug. show_debug_message = True # debug.
#show_debug_message = False # online show_debug_message = False # online
# part 1: check div. # part 1: check div.
registrationsNewApp_div = None registrationsNewApp_div = None
@ -2792,95 +2791,89 @@ def kktix_reg_new(driver, url, answer_index, kktix_register_status_last, config_
# PS: it seems use date_auto_select_mode instead of area_auto_select_mode # PS: it seems use date_auto_select_mode instead of area_auto_select_mode
def get_fami_target_area(driver, date_keyword, area_keyword_1, area_keyword_2, area_keyword_3, area_keyword_4, area_auto_select_mode): def get_fami_target_area(driver, date_keyword, area_keyword_1, area_keyword_2, area_keyword_3, area_keyword_4, area_auto_select_mode):
show_debug_message = True # debug. show_debug_message = True # debug.
#show_debug_message = False # online show_debug_message = False # online
areas = None date_keyword = format_keyword_string(date_keyword)
area_keyword_1 = format_keyword_string(area_keyword_1)
area_keyword_2 = format_keyword_string(area_keyword_2)
area_keyword_3 = format_keyword_string(area_keyword_3)
area_keyword_4 = format_keyword_string(area_keyword_4)
area_list = None
try:
if show_debug_message: if show_debug_message:
print("try to find area block by keywords...") print("try to find area block by keywords...")
area_list = None
try:
my_css_selector = "table.session__list > tbody > tr" my_css_selector = "table.session__list > tbody > tr"
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:
print("find #session date list fail")
if show_debug_message:
print(exc)
#PS: some blocks are generate by ajax, not appear at first time.
formated_area_list = None
if area_list is not None: if area_list is not None:
area_list_length = len(area_list) area_list_length = len(area_list)
if show_debug_message: if show_debug_message:
print("lenth of area rows:", area_list_length) print("lenth of area rows:", area_list_length)
if area_list_length > 0: if area_list_length > 0:
ret = True formated_area_list = []
areas = []
if len(date_keyword)==0 and len(area_keyword_1)==0 and len(area_keyword_2) == 0:
# select all.
# PS: must travel to row buttons.
#areas = area_list
# filter list.
row_index = 0 row_index = 0
for row in area_list: for row in area_list:
row_index += 1 row_index += 1
#print("row index:", row_index) row_is_enabled=True
el_btn = None
is_enabled = False try:
my_css_selector = "button" my_css_selector = "button"
td_button = row.find_element(By.TAG_NAME , my_css_selector) el_btn = row.find_element(By.TAG_NAME, my_css_selector)
if td_button is not None: if el_btn is not None:
is_enabled = td_button.is_enabled() if not el_btn.is_enabled():
#print("row's button disabled!")
if not is_enabled: row_is_enabled=False
# must skip this row. except Exception as exc:
continue
else:
if show_debug_message: if show_debug_message:
print("row button is disabled!") print(exc)
pass
if is_enabled: if row_is_enabled:
areas.append(td_button) formated_area_list.append(row)
# PS: it seems use date_auto_select_mode instead of area_auto_select_mode matched_blocks = None
if area_auto_select_mode == CONST_FROM_TOP_TO_BOTTOM: if not formated_area_list is None:
print("only need first item, break area list loop.") if len(formated_area_list) > 0:
break matched_blocks = []
if len(date_keyword)==0 and len(area_keyword_1)==0 and len(area_keyword_2) == 0:
# select all.
matched_blocks = formated_area_list
else: else:
# match keyword. # match keyword.
row_index = 0 row_index = 0
for row in area_list: for row in formated_area_list:
row_index += 1 row_index += 1
#print("row index:", row_index) #print("row index:", row_index)
date_html_text = "" date_html_text = ""
area_html_text = "" area_html_text = ""
row_text = ""
try:
my_css_selector = "td:nth-child(1)" my_css_selector = "td:nth-child(1)"
td_date = row.find_element(By.CSS_SELECTOR, my_css_selector) td_date = row.find_element(By.CSS_SELECTOR, my_css_selector)
if td_date is not None: if td_date is not None:
#print("date:", td_date.text) #print("date:", td_date.text)
date_html_text = td_date.text date_html_text = format_keyword_string(td_date.text)
my_css_selector = "td:nth-child(2)" my_css_selector = "td:nth-child(2)"
td_area = row.find_element(By.CSS_SELECTOR, my_css_selector) td_area = row.find_element(By.CSS_SELECTOR, my_css_selector)
if td_area is not None: if td_area is not None:
#print("area:", td_area.text) #print("area:", td_area.text)
area_html_text = td_area.text area_html_text = format_keyword_string(td_area.text)
is_enabled = False
my_css_selector = "button"
td_button = row.find_element(By.TAG_NAME , my_css_selector)
if td_button is not None:
is_enabled = td_button.is_enabled()
if not is_enabled:
# must skip this row.
continue
else:
if show_debug_message:
print("row button is disabled!")
row_text = ""
try:
row_text = row.text row_text = row.text
except Exception as exc: except Exception as exc:
print("get row text fail") print("get row text fail")
@ -2927,28 +2920,23 @@ def get_fami_target_area(driver, date_keyword, area_keyword_1, area_keyword_2, a
is_match_area = True is_match_area = True
if is_match_date and is_match_area: if is_match_date and is_match_area:
#print("bingo, row text:", row_text) matched_blocks.append(row)
#areas.append(row)
# add button instead of row.
areas.append(td_button)
if area_auto_select_mode == CONST_FROM_TOP_TO_BOTTOM: if area_auto_select_mode == CONST_FROM_TOP_TO_BOTTOM:
print("only need first item, break area list loop.") print("only need first item, break area list loop.")
break break
return_row_count = len(areas)
return_row_count = 0
if not matched_blocks is None:
return_row_count = len(matched_blocks)
if return_row_count==0:
matched_blocks = None
if show_debug_message: if show_debug_message:
print("return_row_count:", return_row_count) print("return_row_count:", return_row_count)
if return_row_count==0:
areas = None
except Exception as exc: return matched_blocks
pass
print("find #session date list fail")
if show_debug_message:
print(exc)
return areas
def fami_activity(driver): def fami_activity(driver):
@ -2990,11 +2978,8 @@ def fami_home(driver, url, config_dict):
is_ticket_number_assigned = False is_ticket_number_assigned = False
ticket_number = str(config_dict["ticket_number"]) ticket_number = str(config_dict["ticket_number"])
date_keyword = config_dict["tixcraft"]["date_auto_select"]["date_keyword"].strip() date_keyword = config_dict["tixcraft"]["date_auto_select"]["date_keyword"].strip()
area_auto_select_mode = config_dict["tixcraft"]["area_auto_select"]["mode"] area_auto_select_mode = config_dict["tixcraft"]["area_auto_select"]["mode"]
area_keyword_1 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_1"].strip() area_keyword_1 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_1"].strip()
area_keyword_2 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_2"].strip() area_keyword_2 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_2"].strip()
area_keyword_3 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_3"].strip() area_keyword_3 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_3"].strip()
@ -3112,21 +3097,24 @@ def fami_home(driver, url, config_dict):
area_target = areas[target_row_index] area_target = areas[target_row_index]
if area_target is not None: if area_target is not None:
#print("area text", area_target.text) el_btn = None
is_visible = False is_visible = False
try: try:
if area_target.is_enabled(): my_css_selector = "button"
el_btn = area_target.find_element(By.TAG_NAME, my_css_selector)
if el_btn is not None:
if el_btn.is_enabled():
is_visible = True is_visible = True
except Exception as exc: except Exception as exc:
pass pass
if is_visible: if is_visible:
try: try:
area_target.click() el_btn.click()
except Exception as exc: except Exception as exc:
print("click buy button fail, start to retry...") print("click buy button fail, start to retry...")
try: try:
driver.execute_script("arguments[0].click();", area_target) driver.execute_script("arguments[0].click();", el_btn)
except Exception as exc: except Exception as exc:
pass pass
@ -3244,6 +3232,7 @@ def urbtix_date_auto_select(driver, auto_select_mode, date_keyword, auto_reload_
matched_blocks.append(row) matched_blocks.append(row)
if show_debug_message: if show_debug_message:
if not matched_blocks is None:
print("after match keyword, found count:", len(matched_blocks)) print("after match keyword, found count:", len(matched_blocks))
else: else:
print("not found date-time-position") print("not found date-time-position")
@ -3330,7 +3319,7 @@ def urbtix_purchase_ticket(driver, config_dict):
# purpose: area auto select # purpose: area auto select
def urbtix_area_auto_select(driver, area_auto_select_mode, area_keyword_1, area_keyword_1_and): def urbtix_area_auto_select(driver, area_auto_select_mode, area_keyword_1, area_keyword_1_and):
show_debug_message = True # debug. show_debug_message = True # debug.
#show_debug_message = False # online show_debug_message = False # online
ret = False ret = False
matched_blocks = None matched_blocks = None
@ -3348,7 +3337,6 @@ def urbtix_area_auto_select(driver, area_auto_select_mode, area_keyword_1, area_
print("find #ticket-price-tbl date list fail") print("find #ticket-price-tbl date list fail")
print(exc) print(exc)
formated_area_list = None formated_area_list = None
if area_list is not None: if area_list is not None:
area_list_count = len(area_list) area_list_count = len(area_list)
@ -3440,10 +3428,12 @@ def urbtix_area_auto_select(driver, area_auto_select_mode, area_keyword_1, area_
if not matched_blocks is None: if not matched_blocks is None:
print("after match keyword, found count:", len(matched_blocks)) print("after match keyword, found count:", len(matched_blocks))
else: else:
print("not found area form-check") if show_debug_message:
print("area_list_count is empty.")
pass pass
else: else:
print("area form-check is None") if show_debug_message:
print("area_list_count is None.")
pass pass
target_area = None target_area = None
@ -3740,6 +3730,7 @@ def cityline_date_auto_select(driver, auto_select_mode, date_keyword, auto_reloa
matched_blocks.append(row) matched_blocks.append(row)
if show_debug_message: if show_debug_message:
if not matched_blocks is None:
print("after match keyword, found count:", len(matched_blocks)) print("after match keyword, found count:", len(matched_blocks))
else: else:
print("not found date-time-position") print("not found date-time-position")
@ -3901,14 +3892,16 @@ def cityline_area_auto_select(driver, area_auto_select_mode, area_keyword_1, are
if is_match_area: if is_match_area:
matched_blocks.append(row) matched_blocks.append(row)
if show_debug_message: if show_debug_message:
if not matched_blocks is None:
print("after match keyword, found count:", len(matched_blocks)) print("after match keyword, found count:", len(matched_blocks))
else: else:
print("not found area form-check") if show_debug_message:
print("area_list_count is empty.")
pass pass
else: else:
print("area form-check is None") if show_debug_message:
print("area_list_count is None.")
pass pass
target_area = None target_area = None
@ -4114,15 +4107,14 @@ def cityline_performance(driver, config_dict):
if show_debug_message: if show_debug_message:
print("area_keyword_1:", area_keyword_1) print("area_keyword_1:", area_keyword_1)
#print("area_keyword_1_and:", area_keyword_1_and) #print("area_keyword_1_and:", area_keyword_1_and)
print("area_keyword_2:", area_keyword_2)
#print("area_keyword_2_and:", area_keyword_2_and)
# PS: cityline price default value is selected at the first option. # PS: cityline price default value is selected at the first option.
is_price_assign_by_bot = cityline_area_auto_select(driver, area_auto_select_mode, area_keyword_1, area_keyword_1_and) is_price_assign_by_bot = cityline_area_auto_select(driver, area_auto_select_mode, area_keyword_1, area_keyword_1_and)
if not is_price_assign_by_bot: if not is_price_assign_by_bot:
# try keyword_2 # try keyword_2
if show_debug_message:
print("area_keyword_2:", area_keyword_2)
#print("area_keyword_2_and:", area_keyword_2_and)
if len(area_keyword_2) > 0: if len(area_keyword_2) > 0:
is_price_assign_by_bot = cityline_area_auto_select(driver, area_auto_select_mode, area_keyword_2, area_keyword_2_and) is_price_assign_by_bot = cityline_area_auto_select(driver, area_auto_select_mode, area_keyword_2, area_keyword_2_and)
@ -4261,6 +4253,7 @@ def ibon_date_auto_select(driver, auto_select_mode, date_keyword, auto_reload_co
matched_blocks.append(row) matched_blocks.append(row)
if show_debug_message: if show_debug_message:
if not matched_blocks is None:
print("after match keyword, found count:", len(matched_blocks)) print("after match keyword, found count:", len(matched_blocks))
else: else:
print("not found date-time-position") print("not found date-time-position")
@ -4322,7 +4315,7 @@ def ibon_date_auto_select(driver, auto_select_mode, date_keyword, auto_reload_co
def ibon_activity_info(driver, config_dict): def ibon_activity_info(driver, config_dict):
show_debug_message = True # debug. show_debug_message = True # debug.
#show_debug_message = False # online show_debug_message = False # online
date_auto_select_mode = config_dict["tixcraft"]["date_auto_select"]["mode"] date_auto_select_mode = config_dict["tixcraft"]["date_auto_select"]["mode"]
date_keyword = config_dict["tixcraft"]["date_auto_select"]["date_keyword"].strip() date_keyword = config_dict["tixcraft"]["date_auto_select"]["date_keyword"].strip()
@ -4355,7 +4348,6 @@ def ibon_area_auto_select(driver, area_auto_select_mode, area_keyword_1, area_ke
print("find #ticket-price-tbl date list fail") print("find #ticket-price-tbl date list fail")
print(exc) print(exc)
formated_area_list = None formated_area_list = None
if area_list is not None: if area_list is not None:
area_list_count = len(area_list) area_list_count = len(area_list)
@ -4443,12 +4435,15 @@ def ibon_area_auto_select(driver, area_auto_select_mode, area_keyword_1, area_ke
matched_blocks.append(row) matched_blocks.append(row)
if show_debug_message: if show_debug_message:
if not matched_blocks is None:
print("after match keyword, found count:", len(matched_blocks)) print("after match keyword, found count:", len(matched_blocks))
else: else:
print("not found area form-check") if show_debug_message:
print("area_list_count is empty.")
pass pass
else: else:
print("area form-check is None") if show_debug_message:
print("area_list_count is None.")
pass pass
target_area = None target_area = None
@ -4492,7 +4487,7 @@ def ibon_area_auto_select(driver, area_auto_select_mode, area_keyword_1, area_ke
def ibon_performance(driver, config_dict): def ibon_performance(driver, config_dict):
show_debug_message = True # debug. show_debug_message = True # debug.
#show_debug_message = False # online show_debug_message = False # online
is_price_assign_by_bot = False is_price_assign_by_bot = False
@ -4805,6 +4800,15 @@ def kktix_main(driver, url, config_dict, answer_index, kktix_register_status_las
return answer_index, kktix_register_status_last return answer_index, kktix_register_status_last
def famiticket_main(driver, url, config_dict): def famiticket_main(driver, url, config_dict):
try:
window_handles_count = len(driver.window_handles)
if window_handles_count > 1:
driver.switch_to.window(driver.window_handles[0])
driver.close()
driver.switch_to.window(driver.window_handles[0])
except Exception as excSwithFail:
pass
if '/Home/Activity/Info/' in url: if '/Home/Activity/Info/' in url:
fami_activity(driver) fami_activity(driver)
if '/Sales/Home/Index/' in url: if '/Sales/Home/Index/' in url:
@ -4847,11 +4851,40 @@ def urbtix_main(driver, url, config_dict):
urbtix_purchase_ticket(driver, config_dict) urbtix_purchase_ticket(driver, config_dict)
# https://www.urbtix.hk/performance-detail/?eventId=00000&performanceId=00000 # https://www.urbtix.hk/performance-detail/?eventId=00000&performanceId=00000
is_performace_page = False
if '/performance-detail/?eventId=' in url: if '/performance-detail/?eventId=' in url:
is_performace_page = True
if 'performance-detail?eventId' in url:
is_performace_page = True
if is_performace_page:
area_auto_select_enable = config_dict["tixcraft"]["area_auto_select"]["enable"] area_auto_select_enable = config_dict["tixcraft"]["area_auto_select"]["enable"]
if area_auto_select_enable: if area_auto_select_enable:
urbtix_performance(driver, config_dict) urbtix_performance(driver, config_dict)
def check_modal_dialog_popup(driver):
ret = False
el_div = None
try:
el_div = driver.find_element(By.CSS_SELECTOR, 'div.modal-dialog > div.modal-content')
except Exception as exc:
#print("find modal-dialog fail")
#print(exc)
pass
if el_div is not None:
#print("bingo, found modal-dialog")
try:
if el_div.is_enabled():
if el_div.is_displayed():
ret = True
except Exception as exc:
pass
return ret
def cityline_main(driver, url, config_dict): def cityline_main(driver, url, config_dict):
# https://www.cityline.com/Login.html?targetUrl=https%3A%2F%2F # https://www.cityline.com/Login.html?targetUrl=https%3A%2F%2F
# ignore url redirect # ignore url redirect
@ -4868,11 +4901,19 @@ def cityline_main(driver, url, config_dict):
pass pass
if '/eventDetail?' in url: if '/eventDetail?' in url:
is_modal_dialog_popup = check_modal_dialog_popup(driver)
if is_modal_dialog_popup:
print("is_modal_dialog_popup! skip...")
else:
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:
cityline_purchase_button_press(driver, config_dict) cityline_purchase_button_press(driver, config_dict)
if '/performance?' in url: if '/performance?' in url:
is_modal_dialog_popup = check_modal_dialog_popup(driver)
if is_modal_dialog_popup:
print("is_modal_dialog_popup! skip...")
else:
area_auto_select_enable = config_dict["tixcraft"]["area_auto_select"]["enable"] area_auto_select_enable = config_dict["tixcraft"]["area_auto_select"]["enable"]
if area_auto_select_enable: if area_auto_select_enable:
cityline_performance(driver, config_dict) cityline_performance(driver, config_dict)

View File

@ -19,7 +19,7 @@ import json
import webbrowser import webbrowser
import pyperclip import pyperclip
CONST_APP_VERSION = u"MaxBot (2023.01.03)" CONST_APP_VERSION = u"MaxBot (2023.01.04)"
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"