0:
#print("row_html:", row_html)
formated_area_list.append(row)
else:
if show_debug_message:
print("area_list_count is empty.")
pass
else:
if show_debug_message:
print("area_list_count is None.")
pass
if is_price_assign_by_bot:
formated_area_list = None
if not formated_area_list is None:
area_list_count = len(formated_area_list)
if show_debug_message:
print("formated_area_list count:", area_list_count)
if area_list_count > 0:
matched_blocks = []
if len(area_keyword_item) == 0:
matched_blocks = formated_area_list
else:
# match keyword.
for row in formated_area_list:
row_text = ""
row_html = ""
try:
#row_text = row.text
row_html = row.get_attribute('innerHTML')
row_text = remove_html_tags(row_html)
except Exception as exc:
if show_debug_message:
print(exc)
# error, exit loop
break
if len(row_text) > 0:
row_text = format_keyword_string(row_text)
if show_debug_message:
print("row_text:", row_text)
is_match_area = False
if len(area_keyword_item) > 0:
# must match keyword.
is_match_area = True
area_keyword_array = area_keyword_item.split(' ')
for area_keyword in area_keyword_array:
area_keyword = format_keyword_string(area_keyword)
if not area_keyword in row_text:
is_match_area = False
break
else:
# without keyword.
is_match_area = True
if is_match_area:
matched_blocks.append(row)
if auto_select_mode == CONST_FROM_TOP_TO_BOTTOM:
break
if show_debug_message:
print("after match keyword, found count:", len(matched_blocks))
if len(matched_blocks) == 0:
matched_blocks = None
is_need_refresh = True
target_area = get_target_item_from_matched_list(matched_blocks, auto_select_mode)
if not target_area is None:
try:
if target_area.is_enabled():
target_area.click()
is_price_assign_by_bot = True
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)
is_price_assign_by_bot = True
except Exception as exc:
pass
return is_need_refresh, is_price_assign_by_bot
def urbtix_ticket_number_auto_select(driver, config_dict):
show_debug_message = True # debug.
show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
is_ticket_number_assigned = False
ticket_number = config_dict["ticket_number"]
ticket_number_str = str(ticket_number)
# check ticket input textbox.
ticket_price_input = None
try:
ticket_price_input = driver.find_element(By.CSS_SELECTOR, "input.ticket-count")
except Exception as exc:
pass
if not ticket_price_input is None:
current_ticket_number = ""
try:
current_ticket_number = str(ticket_price_input.get_attribute('value')).strip()
except Exception as exc:
pass
if len(current_ticket_number) > 0:
if current_ticket_number == "0":
try:
print("asssign ticket number:%s" % ticket_number_str)
ticket_price_input.clear()
ticket_price_input.send_keys(ticket_number_str)
is_ticket_number_assigned = True
except Exception as exc:
print("asssign ticket number to ticket-count field Exception:")
print(exc)
try:
ticket_price_input.clear()
ticket_price_input.send_keys("1")
is_ticket_number_assigned = True
except Exception as exc2:
print("asssign ticket number to ticket-count still failed.")
pass
else:
# already assigned.
is_ticket_number_assigned = True
ticket_count = 0
if is_ticket_number_assigned:
el_ticket_count = None
try:
my_css_selector = "div.left-content > span.total-count"
el_ticket_count = driver.find_element(By.CSS_SELECTOR, my_css_selector)
if not el_ticket_count is None:
tmp_ticket_count = el_ticket_count.text
if len(tmp_ticket_count) > 0:
if tmp_ticket_count.isdigit():
ticket_count = int(tmp_ticket_count)
except Exception as exc:
pass
if is_ticket_number_assigned and ticket_count==0:
el_btn = None
try:
# this is "confirm"(確認) button.
my_css_selector = "div.footer > div > div"
el_btn = driver.find_element(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
pass
if not el_btn is None:
try:
if el_btn.is_enabled():
el_btn.click()
print("varify site icon pressed.")
time.sleep(0.3)
except Exception as exc:
# use plan B
if show_debug_message:
print("varify site icon pressed fail:", exc)
'''
try:
print("force to click by js.")
driver.execute_script("arguments[0].click();", el_btn)
ret = True
except Exception as exc:
pass
'''
pass
else:
if show_debug_message:
print("varify site icon is None.")
if is_ticket_number_assigned and ticket_count>0:
el_btn = None
try:
# this is "add to cart"(加入購物籃)
my_css_selector = "div.button-inner > div > div.button-text"
el_btn = driver.find_element(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
pass
if not el_btn is None:
try:
if el_btn.is_enabled():
el_btn.click()
time.sleep(0.3)
ret = True
print("shopping-cart icon pressed.")
except Exception as exc:
# use plan B
if show_debug_message:
print("click on button fail:", exc)
pass
'''
try:
print("force to click by js.")
driver.execute_script("arguments[0].click();", el_btn)
ret = True
except Exception as exc:
pass
'''
else:
if show_debug_message:
print("shopping-cart site icon is None.")
return is_ticket_number_assigned
def urbtix_uncheck_adjacent_seat(driver, config_dict):
show_debug_message = True # debug.
show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
el_checkbox_icon = None
is_checkbox_checked = False
try:
my_css_selector = "div.quantity-inner > div.header > div.right > div.checkbox-wrapper > div.checkbox-icon"
el_checkbox_icon = driver.find_element(By.CSS_SELECTOR, my_css_selector)
if not el_checkbox_icon is None:
div_class_string = str(el_checkbox_icon.get_attribute('class'))
if not div_class_string is None:
if len(div_class_string) > 1:
if 'checked' in div_class_string:
is_checkbox_checked = True
except Exception as exc:
if show_debug_message:
print(exc)
pass
try:
if is_checkbox_checked:
el_checkbox_icon.click()
except Exception as exc:
if show_debug_message:
print(exc)
# force to click when exception.
try:
driver.execute_script("arguments[0].click();", el_checkbox_icon)
except Exception as exc2:
pass
pass
def urbtix_performance(driver, config_dict):
show_debug_message = True # debug.
show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
ret = False
is_price_assign_by_bot = False
is_need_refresh = False
# click price row.
area_keyword = config_dict["area_auto_select"]["area_keyword"].strip()
if show_debug_message:
print("area_keyword:", area_keyword)
if len(area_keyword) > 0:
area_keyword_array = []
try:
area_keyword_array = json.loads("["+ area_keyword +"]")
except Exception as exc:
area_keyword_array = []
for area_keyword_item in area_keyword_array:
if show_debug_message:
print("area_keyword_item for keyword:", area_keyword_item)
is_need_refresh, is_price_assign_by_bot = urbtix_area_auto_select(driver, config_dict, area_keyword_item)
if not is_price_assign_by_bot:
break
else:
# empty keyword, match all.
is_need_refresh, is_price_assign_by_bot = urbtix_area_auto_select(driver, config_dict, "")
if show_debug_message:
print("is_price_assign_by_bot:", is_price_assign_by_bot)
# un-tested. disable refresh for now.
is_need_refresh = False
if is_need_refresh:
try:
driver.refresh()
except Exception as exc:
pass
else:
# now, alway not refresh.
if config_dict["advanced"]["disable_adjacent_seat"]:
urbtix_uncheck_adjacent_seat(driver, config_dict)
# choose ticket.
is_ticket_number_assigned = urbtix_ticket_number_auto_select(driver, config_dict)
if show_debug_message:
print("is_ticket_number_assigned:", is_ticket_number_assigned)
return ret
# purpose: date auto select
def cityline_date_auto_select(driver, auto_select_mode, date_keyword, auto_reload_coming_soon_page_enable):
show_debug_message = True # debug.
show_debug_message = False # online
ret = False
matched_blocks = None
area_list = None
try:
#print("try to find cityline area block")
my_css_selector = "button.date-time-position"
area_list = driver.find_elements(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
print("find #date-time-position date list fail")
print(exc)
formated_area_list = None
if not area_list is None:
area_list_count = len(area_list)
if show_debug_message:
print("date_list_count:", area_list_count)
if area_list_count > 0:
formated_area_list = []
for row in area_list:
row_is_enabled=True
try:
if not row.is_enabled():
row_is_enabled=False
except Exception as exc:
if show_debug_message:
print(exc)
pass
if row_is_enabled:
formated_area_list.append(row)
if show_debug_message:
print("formated_area_list count:", len(formated_area_list))
if len(date_keyword) == 0:
matched_blocks = formated_area_list
else:
# match keyword.
if show_debug_message:
print("start to match keyword:", date_keyword)
matched_blocks = []
for row in formated_area_list:
row_text = ""
row_html = ""
try:
#row_text = row.text
row_html = row.get_attribute('innerHTML')
row_text = remove_html_tags(row_html)
except Exception as exc:
if show_debug_message:
print(exc)
# error, exit loop
break
if len(row_text) > 0:
if show_debug_message:
print("row_text:", row_text)
is_match_area = is_row_match_keyword(date_keyword, row_text)
if is_match_area:
matched_blocks.append(row)
if auto_select_mode == CONST_FROM_TOP_TO_BOTTOM:
break
if show_debug_message:
if not matched_blocks is None:
print("after match keyword, found count:", len(matched_blocks))
else:
print("not found date-time-position")
pass
else:
print("date date-time-position is None")
pass
target_area = get_target_item_from_matched_list(matched_blocks, auto_select_mode)
if not target_area is None:
try:
if target_area.is_enabled():
target_area.click()
ret = True
except Exception as exc:
# use plan B
try:
print("force to click by js.")
driver.execute_script("arguments[0].click();", target_area)
ret = True
except Exception as exc:
pass
else:
# no target.
if auto_reload_coming_soon_page_enable:
# auto refresh for date list page.
if not formated_area_list is None:
if len(formated_area_list) == 0:
try:
driver.refresh()
time.sleep(0.3)
except Exception as exc:
pass
return ret
# purpose: area auto select
# return:
# True: area block appear.
# False: area block not appear.
# ps: return is successfully click on the price radio.
def cityline_area_auto_select(driver, config_dict, area_keyword_item):
show_debug_message = True # debug.
show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
auto_select_mode = config_dict["area_auto_select"]["mode"]
is_price_assign_by_bot = False
is_need_refresh = False
matched_blocks = None
area_list = None
try:
#print("try to find cityline area block")
my_css_selector = "div.form-check"
area_list = driver.find_elements(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
print("find #ticket-price-tbl date list fail")
print(exc)
formated_area_list = None
if not area_list is None:
area_list_count = len(area_list)
if show_debug_message:
print("area_list_count:", area_list_count)
if area_list_count > 0:
formated_area_list = []
# filter list.
for row in area_list:
row_is_enabled=True
try:
my_css_selector = "span.price-limited > span"
span_price_limited = row.find_element(By.CSS_SELECTOR, my_css_selector)
if not span_price_limited is None:
span_i18n_string = str(span_price_limited.get_attribute('data-i18n'))
if len(span_i18n_string) > 1:
if 'soldout' in span_i18n_string:
row_is_enabled=False
except Exception as exc:
pass
if row_is_enabled:
formated_area_list.append(row)
else:
if show_debug_message:
print("area_list_count is empty.")
pass
else:
if show_debug_message:
print("area_list_count is None.")
pass
if not formated_area_list is None:
area_list_count = len(formated_area_list)
if show_debug_message:
print("formated_area_list count:", area_list_count)
if area_list_count > 0:
matched_blocks = []
if len(area_keyword_item) == 0:
matched_blocks = formated_area_list
else:
# match keyword.
for row in formated_area_list:
row_text = ""
row_html = ""
try:
#row_text = row.text
row_html = row.get_attribute('innerHTML')
row_text = remove_html_tags(row_html)
except Exception as exc:
if show_debug_message:
print(exc)
# error, exit loop
break
if len(row_text) > 0:
if reset_row_text_if_match_keyword_exclude(config_dict, row_text):
row_text = ""
if len(row_text) > 0:
row_text = format_keyword_string(row_text)
if show_debug_message:
print("row_text:", row_text)
is_match_area = False
if len(area_keyword_item) > 0:
# must match keyword.
is_match_area = True
area_keyword_array = area_keyword_item.split(' ')
for area_keyword in area_keyword_array:
area_keyword = format_keyword_string(area_keyword)
if not area_keyword in row_text:
is_match_area = False
break
else:
# without keyword.
is_match_area = True
if is_match_area:
matched_blocks.append(row)
if auto_select_mode == CONST_FROM_TOP_TO_BOTTOM:
break
if show_debug_message:
print("after match keyword, found count:", len(matched_blocks))
if len(matched_blocks) == 0:
matched_blocks = None
is_need_refresh = True
target_area = get_target_item_from_matched_list(matched_blocks, auto_select_mode)
if not target_area is None:
el_btn = None
try:
#print("target_area text", target_area.text)
my_css_selector = "input[type=radio]"
el_btn = target_area.find_element(By.CSS_SELECTOR, my_css_selector)
if not el_btn is None:
if el_btn.is_enabled():
if not el_btn.is_selected():
el_btn.click()
is_price_assign_by_bot = True
else:
is_price_assign_by_bot = True
#print("bingo, click target_area radio")
except Exception as exc:
print("click target_area radio a link fail")
print(exc)
pass
return is_need_refresh, is_price_assign_by_bot
#[TODO]:
# double check selected radio matched by keyword/keyword_and.
def cityline_area_selected_text(driver):
ret = False
return ret
def cityline_ticket_number_auto_select(driver, config_dict):
selector_string = 'select.select-num'
by_method = By.CSS_SELECTOR
return assign_ticket_number_by_select(driver, config_dict, by_method, selector_string)
def ibon_ticket_number_appear(driver, config_dict):
show_debug_message = True # debug.
show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
selector_string = 'table.table > tbody > tr > td > select'
by_method = By.CSS_SELECTOR
form_select = None
try:
form_select = driver.find_element(by_method, selector_string)
except Exception as exc:
if show_debug_message:
print("find ticket_number select fail:")
print(exc)
pass
is_visible = False
if not form_select is None:
try:
is_visible = form_select.is_enabled()
except Exception as exc:
pass
return is_visible
def ibon_ticket_number_auto_select(driver, config_dict):
selector_string = 'table.table > tbody > tr > td > select'
by_method = By.CSS_SELECTOR
return assign_ticket_number_by_select(driver, config_dict, by_method, selector_string)
def assign_ticket_number_by_select(driver, config_dict, by_method, selector_string):
show_debug_message = True # debug.
show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
ticket_number = str(config_dict["ticket_number"])
form_select = None
try:
form_select = driver.find_element(by_method, selector_string)
except Exception as exc:
if show_debug_message:
print("find ticket_number select fail")
print(exc)
pass
select_obj = None
if not form_select is None:
is_visible = False
try:
is_visible = form_select.is_enabled()
except Exception as exc:
pass
if is_visible:
try:
select_obj = Select(form_select)
except Exception as exc:
pass
is_ticket_number_assigned = False
if not select_obj is None:
row_text = None
try:
row_text = select_obj.first_selected_option.text
except Exception as exc:
pass
if not row_text is None:
if len(row_text) > 0:
if row_text != "0":
# ticket assign.
is_ticket_number_assigned = True
if not is_ticket_number_assigned:
is_ticket_number_assigned = tixcraft_ticket_number_auto_fill(driver, select_obj, ticket_number)
else:
if show_debug_message:
print("ticket_number assigned by previous action.")
return is_ticket_number_assigned
def cityline_purchase_button_press(driver, config_dict):
show_debug_message = True # debug.
show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
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)
is_date_assign_by_bot = cityline_date_auto_select(driver, date_auto_select_mode, date_keyword, auto_reload_coming_soon_page_enable)
is_button_clicked = False
if is_date_assign_by_bot:
is_button_clicked = force_press_button(driver, By.CSS_SELECTOR, 'button.purchase-btn')
return is_button_clicked
def cityline_next_button_press(driver):
ret = False
el_nav = None
el_btn = None
try:
el_nav = driver.find_element(By.CSS_SELECTOR, '.puchase-bottom')
el_btn = driver.find_element(By.CSS_SELECTOR, '#expressPurchaseBtn')
except Exception as exc:
print("find next button fail...")
print(exc)
if not el_btn is None and not el_nav is None:
print("bingo, found next button, start to press")
try:
if el_btn.is_enabled():
#el_btn.click()
builder = ActionChains(driver)
builder.move_to_element(el_nav)
builder.click(el_btn)
builder.perform()
ret = True
except Exception as exc:
print("click next button fail...")
print(exc)
# use plan B
try:
print("force to click by js.")
driver.execute_script("arguments[0].click();", el_btn)
ret = True
except Exception as exc:
pass
return ret
def cityline_performance(driver, config_dict):
show_debug_message = True # debug.
show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
is_price_assign_by_bot = False
is_need_refresh = False
auto_fill_ticket_number = True
if auto_fill_ticket_number:
# click price row.
area_keyword = config_dict["area_auto_select"]["area_keyword"].strip()
if show_debug_message:
print("area_keyword:", area_keyword)
if len(area_keyword) > 0:
area_keyword_array = []
try:
area_keyword_array = json.loads("["+ area_keyword +"]")
except Exception as exc:
area_keyword_array = []
for area_keyword_item in area_keyword_array:
is_need_refresh, is_price_assign_by_bot = cityline_area_auto_select(driver, config_dict, area_keyword_item)
if not is_need_refresh:
break
else:
print("is_need_refresh for keyword:", area_keyword_item)
else:
# empty keyword, match all.
# PS: cityline price default value is selected at the first option.
is_need_refresh, is_price_assign_by_bot = cityline_area_auto_select(driver, config_dict, "")
# un-tested. disable refresh for now.
is_need_refresh = False
if is_need_refresh:
try:
driver.refresh()
except Exception as exc:
pass
# choose ticket.
is_ticket_number_assigned = cityline_ticket_number_auto_select(driver, config_dict)
if show_debug_message:
print("ticket_number:", config_dict["ticket_number"])
print("is_ticket_number_assigned:", is_ticket_number_assigned)
if is_ticket_number_assigned:
auto_press_next_step_button = True
if auto_press_next_step_button:
if not is_price_assign_by_bot:
#[TODO]:
# double check selected radio matched by keyword/keyword_and.
# cityline_area_selected_text(driver)
pass
if is_price_assign_by_bot:
for i in range(2):
click_ret = cityline_next_button_press(driver)
if click_ret:
break
def ibon_date_auto_select(driver, config_dict):
show_debug_message = True # debug.
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)
matched_blocks = None
area_list = None
try:
my_css_selector = "div.single-content > div > div.row > div > div.tr"
area_list = driver.find_elements(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
print("find date-time rows fail")
print(exc)
#PS: some blocks are generate by ajax, not appear at first time.
formated_area_list = None
if not area_list is None:
area_list_count = len(area_list)
if show_debug_message:
print("date_list_count:", area_list_count)
if area_list_count > 0:
formated_area_list = []
# filter list.
for row in area_list:
# default is enabled.
row_is_enabled=True
el_btn = None
try:
my_css_selector = "button"
el_btn = row.find_element(By.TAG_NAME, my_css_selector)
if not el_btn is None:
if not el_btn.is_enabled():
#print("row's button disabled!")
row_is_enabled=False
except Exception as exc:
if show_debug_message:
print(exc)
pass
if row_is_enabled:
formated_area_list.append(row)
if not formated_area_list is None:
area_list_count = len(formated_area_list)
if show_debug_message:
print("formated_area_list count:", area_list_count)
if area_list_count > 0:
if len(date_keyword) == 0:
matched_blocks = formated_area_list
else:
# match keyword.
if show_debug_message:
print("start to match keyword:", date_keyword)
matched_blocks = get_matched_blocks_by_keyword(config_dict, auto_select_mode, date_keyword, formated_area_list)
if show_debug_message:
if not matched_blocks is None:
print("after match keyword, found count:", len(matched_blocks))
else:
print("not found date-time-position")
pass
else:
print("date date-time-position is None")
pass
target_area = get_target_item_from_matched_list(matched_blocks, auto_select_mode)
is_date_assign_by_bot = False
if not target_area is None:
is_button_clicked = False
for i in range(3):
el_btn = None
try:
my_css_selector = "button.btn"
el_btn = target_area.find_element(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
pass
if not el_btn is None:
try:
if el_btn.is_enabled():
el_btn.click()
print("buy icon pressed.")
is_button_clicked = True
except Exception as exc:
pass
# use plan B
'''
try:
print("force to click by js.")
driver.execute_script("arguments[0].click();", el_btn)
ret = True
except Exception as exc:
pass
'''
if is_button_clicked:
break
is_date_assign_by_bot = is_button_clicked
else:
# no target to click.
if auto_reload_coming_soon_page_enable:
# auto refresh for date list page.
if not formated_area_list is None:
if len(formated_area_list) == 0:
try:
driver.refresh()
time.sleep(0.3)
except Exception as exc:
pass
if config_dict["advanced"]["auto_reload_random_delay"]:
time.sleep(random.randint(0,CONST_AUTO_RELOAD_RANDOM_DELAY_MAX_SECOND))
return is_date_assign_by_bot
def ibon_area_auto_select(driver, config_dict, area_keyword_item):
show_debug_message = True # debug.
show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
auto_select_mode = config_dict["area_auto_select"]["mode"]
# when avaiable seat under this count, check seat text content.
CONST_DETECT_SEAT_ATTRIBUTE_UNDER_ROW_COUNT = 20
is_price_assign_by_bot = False
is_need_refresh = False
area_list = None
try:
#print("try to find cityline area block")
#my_css_selector = "div.col-md-5 > table > tbody > tr[onclick=\"onTicketArea(this.id)\"]"
my_css_selector = "div.col-md-5 > table > tbody > tr:not(.disabled)"
area_list = driver.find_elements(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
print("find #ticket-price-tbl date list fail")
print(exc)
formated_area_list = None
if not area_list is None:
area_list_count = len(area_list)
if show_debug_message:
print("area_list_count:", area_list_count)
print("area_keyword_item:", area_keyword_item)
if area_list_count > 0:
formated_area_list = []
# filter list.
for row in area_list:
row_text = ""
row_html = ""
try:
#row_text = row.text
row_html = row.get_attribute('innerHTML')
row_text = remove_html_tags(row_html)
except Exception as exc:
if show_debug_message:
print(exc)
# error, exit loop
break
if len(row_text) > 0:
if '已售完' in row_text:
row_text = ""
if 'disabled' in row_html:
row_text = ""
if 'sold-out' in row_html:
row_text = ""
# clean the buttom description row.
if len(row_text) > 0:
if row_text == "座位已被選擇":
row_text=""
if row_text == "座位已售出":
row_text=""
if row_text == "舞台區域":
row_text=""
if len(row_text) > 0:
if reset_row_text_if_match_keyword_exclude(config_dict, row_text):
row_text = ""
# check ticket count when amount is few, because of it spent a lot of time at parsing element.
if len(row_text) > 0:
is_seat_remaining_checking = False
# PS: when user query with keyword, but when selected row is too many, not every row to check remaing.
# may cause the matched keyword row ticket seat under user target ticket number.
if auto_select_mode == CONST_FROM_TOP_TO_BOTTOM:
if len(formated_area_list)==0:
is_seat_remaining_checking = True
if area_list_count <= CONST_DETECT_SEAT_ATTRIBUTE_UNDER_ROW_COUNT:
is_seat_remaining_checking = True
if is_seat_remaining_checking:
try:
area_seat_el = row.find_element(By.CSS_SELECTOR, 'td.action')
if not area_seat_el is None:
seat_text = area_seat_el.text
if seat_text is None:
seat_text = ""
if seat_text.isdigit():
seat_int = int(seat_text)
if seat_int < config_dict["ticket_number"]:
# skip this row.
if show_debug_message:
print("skip not enought ticket number area at row_text:", row_text)
row_text = ""
except Exception as exc:
if show_debug_message:
print(exc)
pass
if len(row_text) > 0:
formated_area_list.append(row)
else:
if show_debug_message:
print("area_list_count is empty.")
pass
else:
if show_debug_message:
print("area_list_count is None.")
pass
if is_price_assign_by_bot:
formated_area_list = None
matched_blocks = []
if not formated_area_list is None:
area_list_count = len(formated_area_list)
if show_debug_message:
print("formated_area_list count:", area_list_count)
if area_list_count > 0:
if len(area_keyword_item) == 0:
matched_blocks = formated_area_list
else:
for row in formated_area_list:
row_text = ""
row_html = ""
try:
#row_text = row.text
row_html = row.get_attribute('innerHTML')
row_text = remove_html_tags(row_html)
except Exception as exc:
if show_debug_message:
print(exc)
# error, exit loop
break
if len(row_text) > 0:
row_text = format_keyword_string(row_text)
if show_debug_message:
print("row_text:", row_text)
is_match_area = False
if len(area_keyword_item) > 0:
# must match keyword.
is_match_area = True
area_keyword_array = area_keyword_item.split(' ')
for area_keyword in area_keyword_array:
area_keyword = format_keyword_string(area_keyword)
if not area_keyword in row_text:
is_match_area = False
break
else:
# without keyword.
is_match_area = True
if is_match_area:
matched_blocks.append(row)
if auto_select_mode == CONST_FROM_TOP_TO_BOTTOM:
break
if show_debug_message:
print("after match keyword, found count:", len(matched_blocks))
target_area = get_target_item_from_matched_list(matched_blocks, auto_select_mode)
if not matched_blocks is None:
if len(matched_blocks) == 0:
is_need_refresh = True
if show_debug_message:
print("matched_blocks is empty, is_need_refresh")
if not target_area is None:
try:
if target_area.is_enabled():
target_area.click()
is_price_assign_by_bot = True
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)
is_price_assign_by_bot = True
except Exception as exc:
pass
return is_need_refresh, is_price_assign_by_bot
def ibon_allow_not_adjacent_seat(driver, config_dict):
show_debug_message = True # debug.
show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
agree_checkbox = None
try:
my_css_selector = 'div.not-consecutive > div.custom-control > span > input[type="checkbox"]'
agree_checkbox = driver.find_element(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
print("find ibon seat checkbox Exception")
if show_debug_message:
print(exc)
pass
is_finish_checkbox_click = force_check_checkbox(driver, agree_checkbox)
return is_finish_checkbox_click
def ibon_performance(driver, config_dict):
show_debug_message = True # debug.
show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
is_price_assign_by_bot = False
is_need_refresh = False
# click price row.
area_keyword = config_dict["area_auto_select"]["area_keyword"].strip()
if show_debug_message:
print("area_keyword:", area_keyword)
is_need_refresh = False
if len(area_keyword) > 0:
area_keyword_array = []
try:
area_keyword_array = json.loads("["+ area_keyword +"]")
except Exception as exc:
area_keyword_array = []
for area_keyword_item in area_keyword_array:
is_need_refresh, is_price_assign_by_bot = ibon_area_auto_select(driver, config_dict, area_keyword_item)
if not is_need_refresh:
break
else:
print("is_need_refresh for keyword:", area_keyword_item)
else:
# empty keyword, match all.
is_need_refresh, is_price_assign_by_bot = ibon_area_auto_select(driver, config_dict, area_keyword)
if show_debug_message:
print("is_need_refresh:", is_need_refresh)
if is_need_refresh:
try:
driver.refresh()
except Exception as exc:
pass
if config_dict["advanced"]["auto_reload_random_delay"]:
time.sleep(random.randint(0,CONST_AUTO_RELOAD_RANDOM_DELAY_MAX_SECOND))
return is_price_assign_by_bot
def ibon_purchase_button_press(driver):
is_button_clicked = force_press_button(driver, By.CSS_SELECTOR, '#ticket-wrap > a.btn')
return is_button_clicked
def assign_text(driver, by, query, val, overwrite = False, submit=False):
show_debug_message = True # debug.
show_debug_message = False # online
if val is None:
val = ""
is_visible = False
if len(val) > 0:
el_text = None
try:
el_text = driver.find_element(by, query)
except Exception as exc:
if show_debug_message:
print(exc)
pass
if not el_text is None:
try:
if el_text.is_enabled() and el_text.is_displayed():
is_visible = True
except Exception as exc:
if show_debug_message:
print(exc)
pass
is_text_sent = False
if is_visible:
try:
inputed_text = el_text.get_attribute('value')
if not inputed_text is None:
is_do_keyin = False
if len(inputed_text) == 0:
is_do_keyin = True
else:
if inputed_text == val:
is_text_sent = True
else:
if overwrite:
el_text.clear()
is_do_keyin = True
if is_do_keyin:
el_text.click()
el_text.send_keys(val)
if submit:
el_text.send_keys(Keys.ENTER)
is_text_sent = True
except Exception as exc:
if show_debug_message:
print(exc)
pass
return is_text_sent
def facebook_login(driver, account, password):
is_email_sent = assign_text(driver, By.CSS_SELECTOR, '#email', account)
is_password_sent = False
if is_email_sent:
is_password_sent = assign_text(driver, By.CSS_SELECTOR, '#pass', password, submit=True)
return is_password_sent
def kktix_login(driver, account, password):
ret = False
el_email = None
try:
el_email = driver.find_element(By.CSS_SELECTOR, '#user_login')
except Exception as exc:
pass
is_visible = False
if not el_email is None:
try:
if el_email.is_enabled():
is_visible = True
except Exception as exc:
pass
is_email_sent = False
if is_visible:
try:
inputed_text = el_email.get_attribute('value')
if not inputed_text is None:
if len(inputed_text) == 0:
el_email.send_keys(account)
is_email_sent = True
else:
if inputed_text == account:
is_email_sent = True
except Exception as exc:
pass
el_pass = None
if is_email_sent:
try:
el_pass = driver.find_element(By.CSS_SELECTOR, '#user_password')
except Exception as exc:
pass
is_password_sent = False
if not el_pass is None:
try:
if el_pass.is_enabled():
inputed_text = el_pass.get_attribute('value')
if not inputed_text is None:
if len(inputed_text) == 0:
el_pass.click()
if(len(password)>0):
el_pass.send_keys(password)
el_pass.send_keys(Keys.ENTER)
is_password_sent = True
time.sleep(0.1)
except Exception as exc:
pass
ret = is_password_sent
return ret
def cityline_login(driver, account, password):
is_email_sent = assign_text(driver, By.CSS_SELECTOR, 'input[type="text"]', account, submit=True)
# press "click here" use password to login.
if is_email_sent:
is_click_here_pressed = force_press_button(driver, By.CSS_SELECTOR,'.otp-box > ul > li:nth-child(3) > a')
is_password_sent = False
if is_email_sent:
is_password_sent = assign_text(driver, By.CSS_SELECTOR, 'div > input[type="password"]', password, submit=True)
return is_password_sent
def urbtix_login(driver, account, password):
ret = False
el_email = None
try:
el_email = driver.find_element(By.CSS_SELECTOR, 'input[name="loginId"]')
except Exception as exc:
#print("find #email fail")
#print(exc)
pass
is_visible = False
if not el_email is None:
try:
if el_email.is_enabled():
is_visible = True
except Exception as exc:
pass
is_email_sent = False
if is_visible:
try:
inputed_text = el_email.get_attribute('value')
if not inputed_text is None:
if len(inputed_text) == 0:
el_email.send_keys(account)
is_email_sent = True
else:
if inputed_text == account:
is_email_sent = True
except Exception as exc:
pass
el_pass = None
if is_email_sent:
try:
el_pass = driver.find_element(By.CSS_SELECTOR, 'input[name="password"]')
except Exception as exc:
pass
is_password_sent = False
if not el_pass is None:
try:
if el_pass.is_enabled():
inputed_text = el_pass.get_attribute('value')
if not inputed_text is None:
if len(inputed_text) == 0:
el_pass.click()
if(len(password)>0):
el_pass.send_keys(password)
is_password_sent = True
except Exception as exc:
pass
el_btn = None
if is_password_sent:
try:
el_btn = driver.find_element(By.CSS_SELECTOR, '.login-button')
if not el_btn is None:
el_btn.click()
except Exception as exc:
pass
return ret
def kham_login(driver, account, password):
ret = False
el_email = None
try:
my_css_selector = '#ACCOUNT'
el_email = driver.find_element(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
pass
is_visible = False
if not el_email is None:
try:
if el_email.is_enabled():
is_visible = True
except Exception as exc:
pass
is_email_sent = False
if is_visible:
try:
inputed_text = el_email.get_attribute('value')
if not inputed_text is None:
if len(inputed_text) == 0:
el_email.send_keys(account)
is_email_sent = True
else:
if inputed_text == account:
is_email_sent = True
except Exception as exc:
pass
el_pass = None
if is_email_sent:
try:
my_css_selector = 'table.login > tbody > tr > td > input[type="password"]'
el_pass = driver.find_element(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
pass
is_password_sent = False
if not el_pass is None:
try:
if el_pass.is_enabled():
inputed_text = el_pass.get_attribute('value')
if not inputed_text is None:
if len(inputed_text) == 0:
el_pass.click()
if(len(password)>0):
el_pass.send_keys(password)
is_password_sent = True
time.sleep(0.1)
except Exception as exc:
pass
if is_password_sent:
is_button_clicked = force_press_button(driver, By.CSS_SELECTOR,'div.memberContent > p > a > button.red')
ret = is_password_sent
return ret
def ticket_login(driver, account, password):
ret = False
el_email = None
try:
my_css_selector = 'input[cname="帳號"]'
el_email = driver.find_element(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
pass
is_visible = False
if not el_email is None:
try:
if el_email.is_enabled():
is_visible = True
except Exception as exc:
pass
is_email_sent = False
if is_visible:
try:
inputed_text = el_email.get_attribute('value')
if not inputed_text is None:
if len(inputed_text) == 0:
el_email.send_keys(account)
is_email_sent = True
else:
if inputed_text == account:
is_email_sent = True
except Exception as exc:
pass
el_pass = None
if is_email_sent:
try:
my_css_selector = 'input[cname="密碼"]'
el_pass = driver.find_element(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
pass
is_password_sent = False
if not el_pass is None:
try:
if el_pass.is_enabled():
inputed_text = el_pass.get_attribute('value')
if not inputed_text is None:
if len(inputed_text) == 0:
el_pass.click()
if(len(password)>0):
el_pass.send_keys(password)
is_password_sent = True
time.sleep(0.1)
except Exception as exc:
pass
if is_password_sent:
is_button_clicked = force_press_button(driver, By.CSS_SELECTOR,'input[value="登入"]')
ret = is_password_sent
return ret
def hkticketing_login(driver, account, password):
ret = False
el_email = None
try:
my_css_selector = 'div#myTick2Col > div.formMod2Col > div.formModule > div.loginContentContainer > input.borInput'
el_email = driver.find_element(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
#print("find_element exception")
#print(exc)
pass
is_visible = False
if not el_email is None:
try:
if el_email.is_enabled():
is_visible = True
else:
el_email.click()
except Exception as exc:
pass
else:
#print("account field is None.")
pass
is_email_sent = False
if is_visible:
try:
# PS: this is special case...
el_email.click()
inputed_text = el_email.get_attribute('value')
if not inputed_text is None:
if len(inputed_text) == 0:
#print("send account text:", account)
el_email.send_keys(account)
is_email_sent = True
else:
if inputed_text == account:
is_email_sent = True
except Exception as exc:
pass
el_pass = None
if is_email_sent:
try:
my_css_selector = 'div.loginContentContainer > input[type="password"]'
el_pass = driver.find_element(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
pass
is_password_sent = False
if not el_pass is None:
try:
if el_pass.is_enabled():
el_pass.click()
inputed_text = el_pass.get_attribute('value')
if not inputed_text is None:
if len(inputed_text) == 0:
el_pass.click()
if(len(password)>0):
#print("send password text:", password)
el_pass.send_keys(password)
el_pass.send_keys(Keys.ENTER)
is_password_sent = True
time.sleep(0.1)
else:
el_pass.click()
except Exception as exc:
pass
ret = is_password_sent
return ret
def play_sound_while_ordering(config_dict):
if config_dict["advanced"]["play_captcha_sound"]["enable"]:
app_root = get_app_root()
captcha_sound_filename = os.path.join(app_root, config_dict["advanced"]["play_captcha_sound"]["filename"].strip())
play_mp3_async(captcha_sound_filename)
def play_mp3_async(sound_filename):
import threading
threading.Thread(target=play_mp3, args=(sound_filename,), daemon=True).start()
def play_mp3(sound_filename):
try:
from playsound import playsound
playsound(sound_filename)
except Exception as exc:
msg=str(exc)
#print("play sound exeption:", msg)
if platform.system() == 'Windows':
import winsound
try:
winsound.PlaySound(sound_filename, winsound.SND_FILENAME)
except Exception as exc2:
pass
# purpose: check alert poped.
# PS: current version not enable...
def check_pop_alert(driver):
is_alert_popup = False
# https://stackoverflow.com/questions/57481723/is-there-a-change-in-the-handling-of-unhandled-alert-in-chromedriver-and-chrome
default_close_alert_text = [""]
if len(default_close_alert_text) > 0:
try:
alert = None
if not driver is None:
#alert = driver.switch_to.alert
alert = WebDriverWait(driver, 0.2).until(EC.alert_is_present())
if not alert is None:
alert_text = str(alert.text)
if not alert_text is None:
is_match_auto_close_text = False
for txt in default_close_alert_text:
if len(txt) > 0:
if txt in alert.text:
is_match_auto_close_text = True
else:
is_match_auto_close_text = True
#print("is_match_auto_close_text:", is_match_auto_close_text)
#print("alert3 text:", alert.text)
if is_match_auto_close_text:
alert.accept()
print("alert3 accepted")
is_alert_popup = True
else:
print("alert3 not detected")
except NoAlertPresentException as exc1:
#logger.error('NoAlertPresentException for alert')
pass
except NoSuchWindowException:
pass
except Exception as exc:
#logger.error('Exception2 for alert')
#logger.error(exc, exc_info=True)
pass
return is_alert_popup
def list_all_cookies(driver):
cookies_dict = {}
if not driver is None:
all_cookies=driver.get_cookies();
for cookie in all_cookies:
cookies_dict[cookie['name']] = cookie['value']
print(cookies_dict)
def set_non_browser_cookies(driver, url, Captcha_Browser):
if not driver is None:
domain_name = url.split('/')[2]
#PS: need set cookies once, if user change domain.
if not Captcha_Browser is None:
Captcha_Browser.Set_cookies(driver.get_cookies())
Captcha_Browser.Set_Domain(domain_name)
def ticketmaster_parse_zone_info(driver, config_dict):
show_debug_message = True # debug.
show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
mapSelectArea = None
try:
my_css_selector = '#mapSelectArea'
mapSelectArea = driver.find_element(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
if show_debug_message:
print('fail to find my_css_selector:', my_css_selector)
#print("find table#ticketPriceList fail", exc)
if not mapSelectArea is None:
mapSelectArea_html = ""
try:
mapSelectArea_html = mapSelectArea.get_attribute('innerHTML')
except Exception as exc:
mapSelectArea_html = ""
if show_debug_message:
print(exc)
zone_string = ""
tag_start = "var zone ="
tag_end = "fieldImageType"
if tag_start in mapSelectArea_html and tag_end in mapSelectArea_html:
if show_debug_message:
print('found zone info!')
zone_string = mapSelectArea_html.split(tag_start)[1]
zone_string = zone_string.split(tag_end)[0]
zone_string = zone_string.strip()
if zone_string[-1:] == "\n":
zone_string=zone_string[:-1]
zone_string = zone_string.strip()
if zone_string[-1:] == ",":
zone_string=zone_string[:-1]
if show_debug_message:
#print('found zone info string:', zone_string)
pass
if len(zone_string) > 0:
zone_info = {}
try:
zone_info = json.loads(zone_string)
if show_debug_message:
#print("zone_info", zone_info)
pass
if not zone_info is None:
ticketmaster_area_auto_select(driver, config_dict, zone_info)
except Exception as exc:
if show_debug_message:
print(exc)
def ticketmaster_get_ticketPriceList(driver, config_dict):
show_debug_message = True # debug.
show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
div_mapContainer = None
try:
my_css_selector = '#mapContainer'
div_mapContainer = driver.find_element(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
if show_debug_message:
print('fail to find my_css_selector:', my_css_selector)
#print("find table#ticketPriceList fail", exc)
table_select = None
if not div_mapContainer is None:
is_loading = False
# check is loading.
div_loadingmap = None
try:
my_css_selector = '#loadingmap'
div_loadingmap = driver.find_element(By.CSS_SELECTOR, my_css_selector)
if not div_loadingmap is None:
is_loading = True
except Exception as exc:
if show_debug_message:
print('fail to find my_css_selector:', my_css_selector)
#print("find table#ticketPriceList fail", exc)
if not is_loading:
try:
my_css_selector = '#ticketPriceList'
table_select = driver.find_element(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
if show_debug_message:
print('fail to find my_css_selector:', my_css_selector)
#print("find table#ticketPriceList fail", exc)
if table_select is None:
ticketmaster_parse_zone_info(driver, config_dict)
return table_select
def ticketmaster_assign_ticket_number(driver, config_dict):
show_debug_message = True # debug.
show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
table_select = ticketmaster_get_ticketPriceList(driver, config_dict)
select_obj = None
if not table_select is None:
form_select = None
if show_debug_message:
print('found table#ticketPriceList, start find select')
try:
my_css_selector = 'select'
form_select = table_select.find_element(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
if show_debug_message:
print('my_css_selector:', my_css_selector)
print("find form-select fail", exc)
pass
if not form_select is None:
if show_debug_message:
print('found ticket number select.')
is_visible = False
try:
if form_select.is_enabled():
is_visible = True
except Exception as exc:
pass
if is_visible:
try:
select_obj = Select(form_select)
except Exception as exc:
pass
is_ticket_number_assigned = False
if not select_obj is None:
row_text = None
try:
row_text = select_obj.first_selected_option.text
except Exception as exc:
pass
if not row_text is None:
if show_debug_message:
print('row_text:', row_text)
if len(row_text) > 0:
if row_text != "0":
if row_text.isnumeric():
# ticket assign.
is_ticket_number_assigned = True
if show_debug_message:
print('is_ticket_number_assigned:', is_ticket_number_assigned)
# must wait select object ready to assign ticket number.
if not is_ticket_number_assigned:
ticket_number = str(config_dict["ticket_number"])
is_ticket_number_assigned = tixcraft_ticket_number_auto_fill(driver, select_obj, ticket_number)
# must wait ticket number assign to focus captcha.
if is_ticket_number_assigned:
is_button_clicked = force_press_button(driver, By.CSS_SELECTOR,'#autoMode')
def ticketmaster_captcha(driver, config_dict, ocr, Captcha_Browser, domain_name):
show_debug_message = True # debug.
show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
away_from_keyboard_enable = config_dict["ocr_captcha"]["force_submit"]
if not config_dict["ocr_captcha"]["enable"]:
away_from_keyboard_enable = False
ocr_captcha_image_source = config_dict["ocr_captcha"]["image_source"]
if config_dict["auto_check_agree"]:
for i in range(3):
is_finish_checkbox_click = tixcraft_ticket_agree(driver, config_dict)
if is_finish_checkbox_click:
break
if not config_dict["ocr_captcha"]["enable"]:
tixcraft_keyin_captcha_code(driver)
else:
previous_answer = None
last_url, is_quit_bot = get_current_url(driver)
for redo_ocr in range(999):
is_need_redo_ocr, previous_answer, is_form_sumbited = tixcraft_auto_ocr(driver, ocr, away_from_keyboard_enable, previous_answer, Captcha_Browser, ocr_captcha_image_source, domain_name)
if is_form_sumbited:
# start next loop.
break
if not away_from_keyboard_enable:
break
if not is_need_redo_ocr:
break
current_url, is_quit_bot = get_current_url(driver)
if current_url != last_url:
break
def tixcraft_ad_footer(driver, config_dict):
ad_div = None
try:
ad_div = driver.find_element(By.CSS_SELECTOR, '#ad-footer')
if not ad_div is None:
driver.execute_script("arguments[0].innerHTML='';", ad_div)
except Exception as exc:
#print(exc)
pass
try:
ad_div = driver.find_element(By.CSS_SELECTOR, 'footer.footer')
if not ad_div is None:
driver.execute_script("arguments[0].innerHTML='';", ad_div)
except Exception as exc:
#print(exc)
pass
def tixcraft_main(driver, url, config_dict, tixcraft_dict, ocr, Captcha_Browser):
tixcraft_ad_footer(driver, config_dict)
tixcraft_home_close_window(driver, config_dict)
home_url_list = ['https://tixcraft.com/'
,'https://www.tixcraft.com/'
,'https://indievox.com/'
,'https://www.indievox.com/'
,'https://teamear.tixcraft.com/activity'
,'https://www.ticketmaster.sg/'
,'https://www.ticketmaster.com/'
]
for each_url in home_url_list:
if each_url == url:
if config_dict["ocr_captcha"]["enable"]:
set_non_browser_cookies(driver, url, Captcha_Browser)
pass
break
if "/activity/detail/" in url:
is_redirected = tixcraft_redirect(driver, url)
is_date_selected = False
if "/activity/game/" in url:
date_auto_select_enable = config_dict["tixcraft"]["date_auto_select"]["enable"]
if date_auto_select_enable:
domain_name = url.split('/')[2]
is_date_selected = tixcraft_date_auto_select(driver, url, config_dict, domain_name)
if '/artist/' in url and 'ticketmaster.com' in url:
is_event_page = False
if len(url.split('/'))==6:
is_event_page = True
if is_event_page:
date_auto_select_enable = config_dict["tixcraft"]["date_auto_select"]["enable"]
if date_auto_select_enable:
domain_name = url.split('/')[2]
is_date_selected = ticketmaster_date_auto_select(driver, url, config_dict, domain_name)
# choose area
if '/ticket/area/' in url:
domain_name = url.split('/')[2]
if config_dict["area_auto_select"]["enable"]:
if not 'ticketmaster' in domain_name:
# for tixcraft
tixcraft_area_auto_select(driver, url, config_dict)
else:
# area auto select is too difficult, skip in this version.
tixcraft_dict["fail_promo_list"] = ticketmaster_promo(driver, config_dict, tixcraft_dict["fail_promo_list"])
ticketmaster_assign_ticket_number(driver, config_dict)
else:
tixcraft_dict["fail_promo_list"] = []
# https://ticketmaster.sg/ticket/check-captcha/23_blackpink/954/5/75
if '/ticket/check-captcha/' in url:
domain_name = url.split('/')[2]
ticketmaster_captcha(driver, config_dict, ocr, Captcha_Browser, domain_name)
if '/ticket/verify/' in url:
tixcraft_dict["fail_list"] = tixcraft_verify(driver, config_dict, tixcraft_dict["fail_list"])
else:
tixcraft_dict["fail_list"] = []
# main app, to select ticket number.
if '/ticket/ticket/' in url:
domain_name = url.split('/')[2]
tixcraft_ticket_main(driver, config_dict, ocr, Captcha_Browser, domain_name)
return tixcraft_dict
def kktix_paused_main(driver, url, config_dict, kktix_dict):
if '/registrations/new' in url:
# part 1: check recaptch div.
recaptcha_div = None
try:
recaptcha_div = driver.find_element(By.CSS_SELECTOR, '.event-captcha-info')
except Exception as exc:
pass
if not recaptcha_div is None:
select_query = '.ng-hide'
class_name = 'ng-hide'
remove_class_tag_by_selector(driver, select_query, class_name)
select_query = '.btn-disabled-alt'
class_name = 'btn-disabled-alt'
remove_class_tag_by_selector(driver, select_query, class_name)
select_query = 'button[disabled="disabled"]'
class_name = 'disabled'
remove_attribute_tag_by_selector(driver, select_query, class_name)
return kktix_dict
def kktix_main(driver, url, config_dict, kktix_dict):
kktix_account = config_dict["advanced"]["kktix_account"]
is_url_contain_sign_in = False
# fix https://kktix.com/users/sign_in?back_to=https://kktix.com/events/xxxx and registerStatus: SOLD_OUT cause page refresh.
if '/users/sign_in?' in url:
if len(kktix_account) > 4:
kktix_login(driver, kktix_account, decryptMe(config_dict["advanced"]["kktix_password"]))
is_url_contain_sign_in = True
if not is_url_contain_sign_in:
if '/registrations/new' in url:
is_need_refresh = False
is_finish_checkbox_click = False
is_need_refresh, is_finish_checkbox_click = kktix_reg_auto_reload(driver, url, config_dict, kktix_dict["kktix_register_status_last"])
if is_need_refresh:
# reset answer fail list.
kktix_dict["fail_list"] = []
kktix_dict["captcha_sound_played"] = False
kktix_dict["kktix_register_status_last"] = None
else:
# check is able to buy.
if config_dict["kktix"]["auto_fill_ticket_number"]:
kktix_dict["fail_list"], kktix_dict["captcha_sound_played"] = kktix_reg_new_main(driver, config_dict, kktix_dict["fail_list"], kktix_dict["captcha_sound_played"], is_finish_checkbox_click)
else:
is_event_page = False
if '/events/' in url:
# ex: https://xxx.kktix.cc/events/xxx-copy-1
if len(url.split('/'))<=5:
is_event_page = True
if is_event_page:
if config_dict["kktix"]["auto_press_next_step_button"]:
# pass switch check.
#print("should press next here.")
kktix_events_press_next_button(driver)
# reset answer fail list.
kktix_dict["fail_list"] = []
kktix_dict["captcha_sound_played"] = False
kktix_dict["kktix_register_status_last"] = None
return kktix_dict
def fami_login(driver, account, password):
is_email_sent = assign_text(driver, By.CSS_SELECTOR, '#usr_act', account)
is_password_sent = False
if is_email_sent:
is_password_sent = assign_text(driver, By.CSS_SELECTOR, '#usr_pwd', password, submit=True)
return is_password_sent
def famiticket_main(driver, url, config_dict, fami_dict):
if '/Home/User/SignIn' in url:
fami_account = config_dict["advanced"]["fami_account"]
if len(fami_account) > 4:
fami_login(driver, fami_account, decryptMe(config_dict["advanced"]["fami_password"]))
if '/Home/Activity/Info/' in url:
fami_dict["last_activity"] = url
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 config_dict["tixcraft"]["date_auto_select"]["enable"]:
is_date_assign_by_bot = fami_home_auto_select(driver, config_dict, fami_dict["last_activity"])
return fami_dict
def urbtix_performance_confirm_dialog_popup(driver):
ret = False
el_div = None
try:
el_div = driver.find_element(By.CSS_SELECTOR, 'div.notification-confirm-btn > div.button-text')
except Exception as exc:
#print("find modal-dialog fail")
#print(exc)
pass
if not el_div is None:
print("bingo, found notification-confirm-btn")
is_visible = False
try:
if el_div.is_enabled():
if el_div.is_displayed():
is_visible = True
except Exception as exc:
pass
if is_visible:
try:
el_div.click()
ret = True
except Exception as exc:
# use plan B
'''
try:
print("force to click by js.")
driver.execute_script("arguments[0].click();", el_div)
ret = True
except Exception as exc:
pass
'''
pass
if ret:
time.sleep(0.4)
return ret
def get_urbtix_survey_answer_by_question(question_text):
show_debug_message = True # debug.
show_debug_message = False # online
question_text = question_text.replace(' ',' ')
question_text = full2half(question_text)
seq = 0
if '第' in question_text and '個' in question_text:
temp_string = question_text.split('第')[1]
seq_string = temp_string.split('個')[0]
if len(seq_string) > 0:
if seq_string.isdigit():
seq = int(seq_string)
else:
tmp_seq = normalize_chinese_numeric(seq_string)
if not tmp_seq is None:
seq = tmp_seq
if show_debug_message:
print("seq:", seq)
direction = "left"
if '右起' in question_text:
direction = "right"
if '由右' in question_text:
direction = "right"
if '從右' in question_text:
direction = "right"
if '自右' in question_text:
direction = "right"
if '右算' in question_text:
direction = "right"
if '右邊' in question_text:
direction = "right"
if ' from the RIGHT' in question_text:
direction = "right"
if '有多少個' in question_text:
direction = "count"
if '有幾個' in question_text:
direction = "count"
if 'How many ' in question_text:
direction = "count"
if show_debug_message:
print("direction:", direction)
question_text_formated = question_text
question_text_formated = question_text_formated.replace('「','')
question_text_formated = question_text_formated.replace('」','')
question_text_formated = question_text_formated.replace(' ','')
question_text_formated = question_text_formated.replace('-','')
question_text_formated = question_text_formated.replace('_','')
# format question.
question_text_formated = question_text_formated.replace(';','')
question_text_formated = question_text_formated.replace('.','')
question_text_formated = question_text_formated.replace(':','')
question_text_formated = question_text_formated.replace(',','')
question_answer_char = ""
option_text_string = find_continuous_text(question_text_formated)
if show_debug_message:
print("option_text_string:", option_text_string)
if direction in ['left','right']:
if seq > 0:
if len(option_text_string) > 1:
if seq <= len(option_text_string):
if direction == "left":
question_answer_char = option_text_string[seq-1:seq]
if direction == "right":
question_answer_char = option_text_string[len(option_text_string)-seq:len(option_text_string)-seq+1]
if direction == "count":
if '個' in question_text_formated:
count_target = None
count_answer = 0
tmp_seq = question_text_formated.split('個')[1]
if len(tmp_seq) > 0:
count_target_string = tmp_seq[:1]
if len(count_target_string) > 0:
if count_target_string.isdigit():
count_target = int(count_target_string)
else:
count_target = normalize_chinese_numeric(count_target_string)
if not count_target is None:
for char in option_text_string:
if char == str(count_target):
count_answer += 1
question_answer_char = str(count_answer)
if show_debug_message:
print("count_target:", count_target)
print("count_answer:", count_answer)
if show_debug_message:
print("question_answer_char text:", question_answer_char)
return question_answer_char, direction
# PS: due to open-ended question, disable this feature now.
def urbtix_auto_survey(driver, config_dict):
show_debug_message = True # debug.
show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
questions_div = None
try:
questions_div = driver.find_elements(By.CSS_SELECTOR, 'div.modal-content > div.content > div.questions > div.question-item')
except Exception as exc:
#print("find modal-dialog fail")
#print(exc)
pass
is_radio_clicked = False
fill_question_count = 0
if not questions_div is None:
quetions_count = len(questions_div)
if show_debug_message:
print("quetions_count:", quetions_count)
try:
for each_question_div in questions_div:
each_question_ask_div = each_question_div.find_element(By.CSS_SELECTOR, 'div.titles > div')
if not each_question_ask_div is None:
question_text = each_question_ask_div.text
if question_text is None:
question_text = ""
if show_debug_message:
print("questions_div text:", question_text)
question_answer_char, question_direction = get_urbtix_survey_answer_by_question(question_text)
each_option_items_div = each_question_div.find_elements(By.CSS_SELECTOR, 'div.options > div.option-item')
if not each_option_items_div is None:
question_answered = False
for each_option_div in each_option_items_div:
option_content_div = each_option_div.find_element(By.CSS_SELECTOR, 'div.content-list')
if not option_content_div is None:
option_content_div_text = option_content_div.text
if option_content_div is None:
option_content_div=""
option_content_div_text = option_content_div_text.strip()
option_content_div_text = full2half(option_content_div_text)
if question_direction in ['left','right']:
for answer_item in synonyms(question_answer_char):
if answer_item in option_content_div_text:
is_radio_clicked = force_press_button(each_option_div, By.CSS_SELECTOR, 'div.radio-wrapper')
if is_radio_clicked:
if show_debug_message:
print("fill answer:", answer_item)
question_answered = True
break
if question_direction == "count":
for answer_item in synonyms(question_answer_char):
if answer_item in option_content_div_text:
is_radio_clicked = force_press_button(each_option_div, By.CSS_SELECTOR, 'div.radio-wrapper')
if is_radio_clicked:
if show_debug_message:
print("fill answer:", answer_item)
question_answered = True
break
if question_answer_char == '0':
is_match_none = False
if '沒有' in option_content_div_text:
is_match_none = True
if 'LESS THEN ONE' in option_content_div_text.upper():
is_match_none = True
if is_match_none:
is_radio_clicked = force_press_button(each_option_div, By.CSS_SELECTOR, 'div.radio-wrapper')
if is_radio_clicked:
if show_debug_message:
print("fill answer:", '沒有')
question_answered = True
break
int_answer_char = int(question_answer_char)
if int_answer_char > 1:
for i in range(int_answer_char-1):
for answer_item in synonyms(str(i+1)):
is_match_more_then = False
if answer_item + '個或以上' in option_content_div_text:
is_match_more_then = True
if answer_item + '個以上' in option_content_div_text:
is_match_more_then = True
if '多於' in option_content_div_text and answer_item + '個' in option_content_div_text:
is_match_more_then = True
if '更多' in option_content_div_text and answer_item + '個' in option_content_div_text:
is_match_more_then = True
if 'MORE THEN' in option_content_div_text.upper() and answer_item + '個' in option_content_div_text:
is_match_more_then = True
if is_match_more_then:
is_radio_clicked = force_press_button(each_option_div, By.CSS_SELECTOR, 'div.radio-wrapper')
if is_radio_clicked:
if show_debug_message:
print("fill answer:", answer_item + '個或以上')
question_answered = True
break
if question_answered:
break
if question_answered:
fill_question_count += 1
break
except Exception as exc:
if show_debug_message:
print(exc)
pass
if show_debug_message:
print("fill_question_count:", fill_question_count)
#if is_radio_clicked and fill_question_count>=3:
if is_radio_clicked and fill_question_count>=2:
questions_remain_div = None
questions_remain_text = ""
try:
questions_remain_div = driver.find_element(By.CSS_SELECTOR, 'div.surplus-questions-number')
if not questions_remain_div is None:
questions_remain_text = questions_remain_div.text
questions_remain_text = questions_remain_text.strip()
except Exception as exc:
if show_debug_message:
print(exc)
pass
if show_debug_message:
#print("questions_remain_text:", questions_remain_text)
pass
if questions_remain_text == "0" or questions_remain_text == "":
is_button_clicked = False
#is_button_clicked = force_press_button(driver, By.CSS_SELECTOR, 'div.button-wrapper > div.button-text-multi-lines > div')
# Message: Element
is not clickable at point (351,566) because another element
obscures it
btn_submit = None
try:
my_css_selector = 'div.landing-question > div.modal-inner > div.modal-content > div.content > div.button-container > div.button-and-number > div.button-wrapper > div.button-text-multi-lines > div.text-tc'
btn_submit = driver.find_element(By.CSS_SELECTOR, my_css_selector)
if not btn_submit.is_enabled():
btn_submit = None
except Exception as exc:
if show_debug_message:
print(exc)
pass
if not btn_submit is None:
try:
if show_debug_message:
print("start to click btn.")
btn_submit.click()
is_button_clicked = True
time.sleep(1.0)
except Exception as exc:
if show_debug_message:
print(exc)
pass
def urbtix_main(driver, url, config_dict):
# http://msg.urbtix.hk
waiting_for_access_url = ['/session/landing-timer/','msg.urbtix.hk','busy.urbtix.hk']
for waiting_url in waiting_for_access_url:
if waiting_url in url:
try:
driver.get('https://www.urbtix.hk/')
except Exception as exec1:
pass
pass
# 刷太快, 會被封IP?
time.sleep(config_dict["advanced"]["auto_reload_page_interval"])
if '/logout?' in url:
try:
driver.get('https://www.urbtix.hk/')
except Exception as exec1:
pass
pass
# for new survey.
if 'https://www.urbtix.hk/session/landing' == url:
if config_dict["advanced"]["auto_guess_options"]:
#urbtix_auto_survey(driver, config_dict)
pass
if '.hk/member-login' in url:
urbtix_account = config_dict["advanced"]["urbtix_account"]
if len(urbtix_account) > 2:
urbtix_login(driver, urbtix_account, decryptMe(config_dict["advanced"]["urbtix_password"]))
is_ready_to_buy_from_queue = False
# Q: How to know ready to buy ticket from queue?
if is_ready_to_buy_from_queue:
# play sound when ready to buy ticket.
play_sound_while_ordering(config_dict)
# https://www.urbtix.hk/event-detail/00000/
if '/event-detail/' in url:
if config_dict["tixcraft"]["date_auto_select"]["enable"]:
is_event_page = False
if len(url.split('/'))<=6:
is_event_page = True
urbtix_purchase_ticket(driver, config_dict)
# https://www.urbtix.hk/performance-detail/?eventId=00000&performanceId=00000
is_performace_page = False
if '/performance-detail/?eventId=' in url:
is_performace_page = True
if 'performance-detail?eventId' in url:
is_performace_page = True
if is_performace_page:
if config_dict["area_auto_select"]["enable"]:
is_confirm_dialog_popup = urbtix_performance_confirm_dialog_popup(driver)
if is_confirm_dialog_popup:
print("is_confirm_dialog_popup! auto press confirm...")
else:
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 not el_div is 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_shows_goto_cta(driver):
ret = False
el_btn = None
try:
el_btn = driver.find_element(By.CSS_SELECTOR, '.btn_cta')
except Exception as exc:
#print("find next button fail...")
#print(exc)
pass
if not el_btn is None:
#print("bingo, found next button, start to press")
try:
if el_btn.is_enabled() and el_btn.is_displayed():
el_btn.click()
ret = True
except Exception as exc:
print("click next button fail...")
print(exc)
return ret
def cityline_cookie_accept(driver):
is_btn_click = force_press_button(driver, By.CSS_SELECTOR,'.cookieWrapper_closeBtn')
def cityline_auto_retry_access(driver, config_dict):
btn_retry = None
try:
btn_retry = driver.find_element(By.CSS_SELECTOR, 'button')
if not btn_retry is None:
js = btn_retry.get_attribute('onclick')
driver.set_script_timeout(1)
driver.execute_script(js)
except Exception as exc:
pass
# 刷太快, 會被封IP?
time.sleep(config_dict["advanced"]["auto_reload_page_interval"])
def cityline_go_venue(driver, url):
url_https = url.replace("http://","https://")
url_https_array = url_https.split("/")
is_match_venue_url = False
if url[-1:] == "/":
if len(url_https_array)==4:
domain_array = url_https_array[2].split(".")
if len(domain_array)==3:
is_match_venue_url = True
if is_match_venue_url:
try:
btn_next = driver.find_element(By.CSS_SELECTOR, 'div#eventDetail > div#btnDiv > a')
if not btn_next is None:
driver.set_script_timeout(1)
driver.execute_script("go_venue('TW');")
except Exception as exc:
pass
def cityline_clean_ads(driver):
ad_query_list = [
'ats-overlay-bottom-wrapper-rendered',
'.insert_ads',
]
try:
for ad_query in ad_query_list:
ad_div = driver.find_element(By.CSS_SELECTOR, ad_query)
if not ad_div is None:
driver.set_script_timeout(1)
driver.execute_script("arguments[0].outerHTML='';", ad_div);
except Exception as exc:
pass
def cityline_main(driver, url, config_dict):
# https://msg.cityline.com/ https://event.cityline.com/
if 'msg.cityline.com' in url or 'event.cityline.com' in url:
cityline_auto_retry_access(driver, 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])
time.sleep(0.2)
except Exception as excSwithFail:
pass
if '.cityline.com/Events.html' in url:
cityline_cookie_accept(driver)
cityline_go_venue(driver, url)
cityline_clean_ads(driver)
if 'cityline.com/queue?' in url:
# show HTTP ERROR 400
pass
# https://www.cityline.com/Login.html?targetUrl=https%3A%2F%2F
# ignore url redirect
if '/Login.html' in url:
cityline_account = config_dict["advanced"]["cityline_account"]
if len(cityline_account) > 2:
cityline_login(driver, cityline_account, decryptMe(config_dict["advanced"]["cityline_password"]))
return
is_ready_to_buy_from_queue = False
# Q: How to know ready to buy ticket from queue?
if is_ready_to_buy_from_queue:
# play sound when ready to buy ticket.
play_sound_while_ordering(config_dict)
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:
if config_dict["tixcraft"]["date_auto_select"]["enable"]:
cityline_purchase_button_press(driver, config_dict)
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:
if config_dict["area_auto_select"]["enable"]:
cityline_performance(driver, config_dict)
if '.htm' in url:
if not '/slim_end.htm' in url:
if len(url.split('/'))>=5:
cityline_shows_goto_cta(driver)
def get_ibon_question_text(driver):
form_select = None
try:
form_select = driver.find_element(By.CSS_SELECTOR, 'div.editor-box > div > div.form-group > label')
except Exception as exc:
print("find verify textbox fail")
pass
question_text = ""
if not form_select is None:
try:
question_text = form_select.text
except Exception as exc:
print("get text fail")
if question_text is None:
question_text = ""
return question_text
def ibon_verification_question(driver, fail_list, config_dict):
show_debug_message = True # debug.
show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
answer_list = []
question_text = get_ibon_question_text(driver)
if len(question_text) > 0:
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 = get_answer_list_from_question_string(None, question_text)
inferred_answer_string = ""
if len(answer_list) > 0:
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)
print("fail_list:", fail_list)
# PS: auto-focus() when empty inferred_answer_string with empty inputed text value.
input_text_css = 'div.editor-box > div > div.form-group > input'
next_step_button_css = 'div.editor-box > div > a.btn'
submit_by_enter = False
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 ibon_ticket_agree(driver):
# check agree
form_checkbox = None
try:
form_checkbox = driver.find_element(By.CSS_SELECTOR, '#agreen')
except Exception as exc:
#print("find #agreen fail")
pass
is_finish_checkbox_click = False
if not form_checkbox is None:
try:
if form_checkbox.is_enabled():
if not form_checkbox.is_selected():
form_checkbox.click()
is_finish_checkbox_click = True
except Exception as exc:
print("click #agreen fail, try plan_b click label.")
is_finish_checkbox_click = force_press_button(driver, By.CSS_SELECTOR,'label[for="agreen"]')
return is_finish_checkbox_click
def ibon_check_sold_out(driver):
is_sold_out = False
div_ticket_info = None
try:
div_ticket_info = driver.find_element(By.CSS_SELECTOR, '#ticket-info')
except Exception as exc:
print("find #ticket-info fail")
if not div_ticket_info is None:
try:
div_ticket_info_text = div_ticket_info.text
if not div_ticket_info_text is None:
if '已售完' in div_ticket_info_text:
is_sold_out = True
except Exception as exc:
pass
return is_sold_out
def ibon_auto_signup(driver):
is_button_clicked = force_press_button(driver, By.CSS_SELECTOR, '.btn.btn-signup')
return is_button_clicked
def ibon_keyin_captcha_code(driver, answer = "", auto_submit = False):
is_verifyCode_editing = False
form_verifyCode = None
try:
my_css_selector = 'input[value="驗證碼"]'
form_verifyCode = driver.find_element(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
print("find blockLogin input fail")
try:
my_css_selector = 'input[placeholder="驗證碼"]'
form_verifyCode = driver.find_element(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
pass
if not form_verifyCode is None:
inputed_value = None
try:
inputed_value = form_verifyCode.get_attribute('value')
except Exception as exc:
print("find verify code fail")
pass
if inputed_value is None:
inputed_value = ""
if inputed_value == "驗證碼":
try:
form_verifyCode.clear()
except Exception as exc:
print("clear verify code fail")
pass
else:
if len(inputed_value) > 0:
print("captcha text inputed.")
form_verifyCode = None
is_verifyCode_editing = True
if not form_verifyCode is None:
if len(answer) > 0:
#answer=answer.upper()
is_visible = False
try:
if form_verifyCode.is_enabled():
is_visible = True
except Exception as exc:
pass
if is_visible:
try:
form_verifyCode.click()
is_verifyCode_editing = True
except Exception as exc:
pass
#print("start to fill answer.")
try:
form_verifyCode.clear()
form_verifyCode.send_keys(answer)
except Exception as exc:
print("send_keys ocr answer fail.")
return is_verifyCode_editing
def ibon_auto_ocr(driver, config_dict, ocr, away_from_keyboard_enable, previous_answer, Captcha_Browser, ocr_captcha_image_source, model_name):
show_debug_message = True # debug.
show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
print("start to ddddocr")
is_need_redo_ocr = False
is_form_sumbited = False
ocr_answer = None
if not ocr is None:
if show_debug_message:
print("away_from_keyboard_enable:", away_from_keyboard_enable)
print("previous_answer:", previous_answer)
print("ocr_captcha_image_source:", ocr_captcha_image_source)
ocr_start_time = time.time()
img_base64 = None
if ocr_captcha_image_source == CONST_OCR_CAPTCH_IMAGE_SOURCE_NON_BROWSER:
if not Captcha_Browser is None:
img_base64 = base64.b64decode(Captcha_Browser.Request_Captcha())
if ocr_captcha_image_source == CONST_OCR_CAPTCH_IMAGE_SOURCE_CANVAS:
image_id = 'chk_pic'
image_element = None
try:
my_css_selector = "#" + image_id
image_element = driver.find_elements(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
pass
if not image_element is None:
try:
driver.set_script_timeout(1)
form_verifyCode_base64 = driver.execute_async_script("""
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
var img = document.getElementById('%s');
if(img!=null) {
canvas.height = img.naturalHeight;
canvas.width = img.naturalWidth;
context.drawImage(img, 0, 0);
callback = arguments[arguments.length - 1];
callback(canvas.toDataURL()); }
""" % (image_id))
if not form_verifyCode_base64 is None:
img_base64 = base64.b64decode(form_verifyCode_base64.split(',')[1])
except Exception as exc:
if show_debug_message:
print("canvas exception:", str(exc))
pass
if not img_base64 is None:
try:
ocr_answer = ocr.classification(img_base64)
except Exception as exc:
pass
ocr_done_time = time.time()
ocr_elapsed_time = ocr_done_time - ocr_start_time
print("ocr elapsed time:", "{:.3f}".format(ocr_elapsed_time))
else:
print("ddddocr is None")
if not ocr_answer is None:
ocr_answer = ocr_answer.strip()
print("ocr_answer:", ocr_answer)
if len(ocr_answer)==4:
who_care_var = ibon_keyin_captcha_code(driver, answer = ocr_answer, auto_submit = away_from_keyboard_enable)
else:
if not away_from_keyboard_enable:
ibon_keyin_captcha_code(driver)
else:
is_need_redo_ocr = True
if previous_answer != ocr_answer:
previous_answer = ocr_answer
print("click captcha again")
if True:
# selenium solution.
jquery_string = '$("#chk_pic").attr("src", "/pic.aspx?TYPE=%s&ts=" + new Date().getTime());' % (model_name)
driver.execute_script(jquery_string)
if ocr_captcha_image_source == CONST_OCR_CAPTCH_IMAGE_SOURCE_CANVAS:
time.sleep(0.3)
else:
# Non_Browser solution.
if not Captcha_Browser is None:
new_captcha_url = Captcha_Browser.Request_Refresh_Captcha() #取得新的CAPTCHA
if new_captcha_url != "":
#PS:[TODO]
#tixcraft_change_captcha(driver, new_captcha_url) #更改CAPTCHA圖
pass
else:
print("ocr_answer is None")
print("previous_answer:", previous_answer)
if previous_answer is None:
ibon_keyin_captcha_code(driver)
else:
# page is not ready, retry again.
# PS: usually occur in async script get captcha image.
is_need_redo_ocr = True
return is_need_redo_ocr, previous_answer, is_form_sumbited
def ibon_captcha(driver, config_dict, ocr, Captcha_Browser, model_name):
away_from_keyboard_enable = config_dict["ocr_captcha"]["force_submit"]
if not config_dict["ocr_captcha"]["enable"]:
away_from_keyboard_enable = False
ocr_captcha_image_source = config_dict["ocr_captcha"]["image_source"]
#PS: need a 'auto assign seat' feature to enable away_from_keyboard feature.
away_from_keyboard_enable = False
is_captcha_sent = False
previous_answer = None
last_url, is_quit_bot = get_current_url(driver)
for redo_ocr in range(999):
is_need_redo_ocr, previous_answer, is_form_sumbited = ibon_auto_ocr(driver, config_dict, ocr, away_from_keyboard_enable, previous_answer, Captcha_Browser, ocr_captcha_image_source, model_name)
# TODO: must ensure the answer is corrent...
if not is_need_redo_ocr:
is_captcha_sent = True
if is_form_sumbited:
break
if not away_from_keyboard_enable:
break
if not is_need_redo_ocr:
break
current_url, is_quit_bot = get_current_url(driver)
if current_url != last_url:
break
return is_captcha_sent
def ibon_main(driver, url, config_dict, ibon_dict, ocr, Captcha_Browser):
home_url_list = ['https://ticket.ibon.com.tw/'
,'https://ticket.ibon.com.tw/index/entertainment'
]
for each_url in home_url_list:
if each_url == url.lower():
if config_dict["ocr_captcha"]["enable"]:
set_non_browser_cookies(driver, url, Captcha_Browser)
break
# https://tour.ibon.com.tw/event/e23010000300mxu
if 'tour' in url.lower() and '/event/' in url.lower():
is_event_page = False
if len(url.split('/'))==5:
is_event_page = True
if is_event_page:
ibon_auto_signup(driver)
is_match_target_feature = False
#PS: ibon some utk is upper case, some is lower.
if not is_match_target_feature:
#https://ticket.ibon.com.tw/ActivityInfo/Details/0000?pattern=entertainment
if '/activityinfo/details/' in url.lower():
is_event_page = False
if len(url.split('/'))==6:
is_event_page = True
if is_event_page:
if config_dict["tixcraft"]["date_auto_select"]["enable"]:
is_match_target_feature = True
is_date_assign_by_bot = ibon_date_auto_select(driver, config_dict)
if 'ibon.com.tw/error.html?' in url.lower():
try:
driver.back()
except Exception as exc:
pass
is_enter_verify_mode = False
if not is_match_target_feature:
# validation question url:
# https://orders.ibon.com.tw/application/UTK02/UTK0201_0.aspx?rn=1180872370&PERFORMANCE_ID=B04M7XZT&PRODUCT_ID=B04KS88E&SHOW_PLACE_MAP=True
is_event_page = False
if '/UTK02/UTK0201_0.' in url.upper():
if '.aspx?' in url.lower():
if 'rn=' in url.lower():
if 'PERFORMANCE_ID=' in url.upper():
if "PRODUCT_ID=" in url.upper():
is_event_page = True
if is_event_page:
is_enter_verify_mode = True
ibon_dict["fail_list"] = ibon_verification_question(driver, ibon_dict["fail_list"], config_dict)
is_match_target_feature = True
if not is_enter_verify_mode:
ibon_dict["fail_list"] = []
if not is_match_target_feature:
# https://orders.ibon.com.tw/application/UTK02/UTK0201_000.aspx?PERFORMANCE_ID=0000
# https://orders.ibon.com.tw/application/UTK02/UTK0201_000.aspx?rn=1111&PERFORMANCE_ID=2222&PRODUCT_ID=BBBB
# https://orders.ibon.com.tw/application/UTK02/UTK0201_001.aspx?PERFORMANCE_ID=2222&GROUP_ID=4&PERFORMANCE_PRICE_AREA_ID=3333
is_event_page = False
if '/UTK02/UTK0201_' in url.upper():
if '.aspx?' in url.lower():
if 'PERFORMANCE_ID=' in url.upper():
if len(url.split('/'))==6:
is_event_page = True
if '/UTK02/UTK0202_' in url.upper():
if '.aspx?' in url.lower():
if 'PERFORMANCE_ID=' in url.upper():
if len(url.split('/'))==6:
is_event_page = True
if is_event_page:
if config_dict["area_auto_select"]["enable"]:
select_query = "tr.disbled"
clean_tag_by_selector(driver,select_query)
select_query = "tr.sold-out"
clean_tag_by_selector(driver,select_query)
is_do_ibon_performance_with_ticket_number = False
if 'PRODUCT_ID=' in url.upper():
# step 1: select area.
is_match_target_feature = True
is_price_assign_by_bot = ibon_performance(driver, config_dict)
#print("is_price_assign_by_bot:", is_price_assign_by_bot)
if not is_price_assign_by_bot:
# this case show captcha and ticket-number in this page.
if ibon_ticket_number_appear(driver, config_dict):
is_do_ibon_performance_with_ticket_number = True
if 'PERFORMANCE_PRICE_AREA_ID=' in url.upper():
is_do_ibon_performance_with_ticket_number = True
if is_do_ibon_performance_with_ticket_number:
if config_dict["advanced"]["disable_adjacent_seat"]:
is_finish_checkbox_click = ibon_allow_not_adjacent_seat(driver, config_dict)
# captcha
is_captcha_sent = False
if config_dict["ocr_captcha"]["enable"]:
domain_name = url.split('/')[2]
model_name = url.split('/')[5]
if len(model_name) > 7:
model_name=model_name[:7]
captcha_url = '/pic.aspx?TYPE=%s' % (model_name)
#PS: need set cookies once, if user change domain.
if not Captcha_Browser is None:
Captcha_Browser.Set_Domain(domain_name, captcha_url=captcha_url)
is_captcha_sent = ibon_captcha(driver, config_dict, ocr, Captcha_Browser, model_name)
# assign ticket number.
is_match_target_feature = True
is_ticket_number_assigned = ibon_ticket_number_auto_select(driver, config_dict)
#print("is_ticket_number_assigned:", is_ticket_number_assigned)
if is_ticket_number_assigned:
if is_captcha_sent:
click_ret = ibon_purchase_button_press(driver)
# only this case: "ticket number CHANGED by bot" and "cpatcha sent" to play sound!
if click_ret:
play_sound_while_ordering(config_dict)
else:
is_sold_out = ibon_check_sold_out(driver)
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')
# plan-B, easy and better than plan-A
try:
driver.back()
driver.refresh()
except Exception as exc:
pass
if not is_match_target_feature:
#https://orders.ibon.com.tw/application/UTK02/UTK0206_.aspx
is_event_page = False
if '/UTK02/UTK020' in url.upper():
if '.aspx' in url.lower():
if len(url.split('/'))==6:
is_event_page = True
# ignore "pay money" step.
if '/UTK02/UTK0207_.ASPX' in url.upper():
is_event_page = False
if is_event_page:
is_finish_checkbox_click = False
if is_event_page:
auto_check_agree = config_dict["auto_check_agree"]
if auto_check_agree:
for i in range(3):
is_finish_checkbox_click = ibon_ticket_agree(driver)
if is_finish_checkbox_click:
break
if is_finish_checkbox_click:
is_name_based = False
try:
my_css_selector = "body"
html_body = driver.find_element(By.CSS_SELECTOR, my_css_selector)
if not html_body is None:
if '實名制' in html_body.text:
is_name_based = True
is_match_target_feature = True
except Exception as exc:
pass
if not is_name_based:
is_button_clicked = force_press_button(driver, By.CSS_SELECTOR, 'a.btn.btn-pink.continue')
return ibon_dict
def hkticketing_home(driver):
show_debug_message = True # debug.
show_debug_message = False # online
# OMG, I forgot why I wrote this code.
'''
body_iframe = None
body_iframe_list = None
try:
body_iframe_list = driver.find_elements(By.CSS_SELECTOR, 'body > iframe')
except Exception as exc:
if show_debug_message:
print("find body_iframe fail")
pass
hotshow_btn = None
if not body_iframe_list is None:
if show_debug_message:
print("iframe count:", len(body_iframe_list))
for each_iframe in body_iframe_list:
try:
driver.switch_to.frame(each_iframe)
hotshow_btn = driver.find_element(By.CSS_SELECTOR, 'div.hotshow > a.btn')
if not hotshow_btn is None:
if hotshow_btn.is_enabled() and hotshow_btn.is_displayed():
hotshow_btn.click()
except Exception as exc:
pass
if show_debug_message:
print("find hotshow btn fail:", exc)
driver.switch_to.default_content()
'''
def hkticketing_accept_cookie(driver):
show_debug_message = True # debug.
show_debug_message = False # online
accept_all_cookies_btn = None
try:
accept_all_cookies_btn = driver.find_element(By.CSS_SELECTOR, '#closepolicy_new')
except Exception as exc:
if show_debug_message:
print("find closepolicy_new fail")
pass
if not accept_all_cookies_btn is None:
is_visible = False
try:
if accept_all_cookies_btn.is_enabled() and accept_all_cookies_btn.is_displayed():
is_visible = True
except Exception as exc:
pass
if is_visible:
if show_debug_message:
print("closepolicy_new visible. start to press.")
try:
accept_all_cookies_btn.click()
except Exception as exc:
pass
'''
print("try to click closepolicy_new fail")
try:
driver.execute_script("arguments[0].click();", accept_all_cookies_btn)
except Exception as exc:
pass
'''
else:
if show_debug_message:
print("closepolicy_new invisible.")
def hkticketing_date_buy_button_press(driver):
is_date_submiting = False
el_btn = None
try:
my_css_selector = "#buyButton > input"
el_btn = driver.find_element(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
pass
if not el_btn is None:
try:
if el_btn.is_enabled() and el_btn.is_displayed():
el_btn.click()
print("buy button pressed.")
is_date_submiting = True
else:
if not el_btn.is_enabled():
print("force to press disabled buy button.")
try:
driver.execute_script("arguments[0].click();", el_btn)
ret = True
except Exception as exc:
pass
except Exception as exc:
pass
# use plan B
'''
try:
print("force to click by js.")
driver.execute_script("arguments[0].click();", el_btn)
ret = True
except Exception as exc:
pass
'''
return is_date_submiting
def hkticketing_date_assign(driver, config_dict):
show_debug_message = True # debug.
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()
if show_debug_message:
print("date_keyword:", date_keyword)
matched_blocks = None
# clean stop word.
date_keyword = format_keyword_string(date_keyword)
date_keyword_and = ""
form_select = None
try:
form_select = driver.find_element(By.CSS_SELECTOR, '#p')
except Exception as exc:
print("find select#p fail")
pass
select_obj = None
if not form_select is None:
is_visible = False
try:
if form_select.is_enabled():
is_visible = True
except Exception as exc:
pass
if is_visible:
try:
select_obj = Select(form_select)
except Exception as exc:
pass
is_date_assigned = False
if not select_obj is None:
row_text = None
try:
row_text = select_obj.first_selected_option.text
except Exception as exc:
pass
if not row_text is None:
if len(row_text) > 8:
if '20' in row_text:
# ticket assign.
is_date_assigned = True
if show_debug_message:
print("is_date_assigned:", is_date_assigned)
#PS: some blocks are generate by ajax, not appear at first time.
formated_area_list = None
is_page_ready = True
if not is_date_assigned:
area_list = None
try:
my_css_selector = "#p > option"
area_list = driver.find_elements(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
print("find #p options date list fail")
print(exc)
if not area_list is None:
area_list_count = len(area_list)
if show_debug_message:
print("date_list_count:", area_list_count)
if area_list_count == 0:
is_page_ready = False
else:
formated_area_list = []
# filter list.
for row in area_list:
row_text = ""
row_html = ""
try:
#row_text = row.text
row_html = row.get_attribute('innerHTML')
row_text = remove_html_tags(row_html)
except Exception as exc:
if show_debug_message:
print(exc)
# error, exit loop
break
if len(row_text) > 0:
if '20' in row_text:
row_text = ""
if ' Exhausted' in row_text:
row_text = ""
if '配售完畢' in row_text:
row_text = ""
if '配售完毕' in row_text:
row_text = ""
if 'No Longer On Sale' in row_text:
row_text = ""
if '已停止發售' in row_text:
row_text = ""
if '已停止发售' in row_text:
row_text = ""
if len(row_text) > 0:
formated_area_list.append(row)
if not formated_area_list is None:
area_list_count = len(formated_area_list)
if show_debug_message:
print("formated_area_list count:", area_list_count)
if area_list_count > 0:
if len(date_keyword) == 0:
matched_blocks = formated_area_list
else:
# match keyword.
if show_debug_message:
print("start to match keyword:", date_keyword)
matched_blocks = get_matched_blocks_by_keyword(config_dict, auto_select_mode, date_keyword, formated_area_list)
if show_debug_message:
if not matched_blocks is None:
print("after match keyword, found count:", len(matched_blocks))
else:
print("not found date-time-position")
pass
else:
print("date date-time-position is None")
pass
target_area = get_target_item_from_matched_list(matched_blocks, auto_select_mode)
if not target_area is None:
try:
if target_area.is_enabled():
target_area.click()
is_date_assigned = True
except Exception as exc:
print("click target_area link fail")
print(exc)
return is_date_assigned, is_page_ready, formated_area_list
def hkticketing_date_password_input(driver, config_dict, fail_list):
show_debug_message = True # debug.
show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
is_password_appear = False
el_password_input = None
try:
my_css_selector = "#entitlementPassword > div > div > div > div > input[type='password']"
el_password_input = driver.find_element(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
pass
inputed_value = ""
if not el_password_input is None:
try:
inputed_value = el_password_input.get_attribute('value')
except Exception as exc:
print("get_attribute value fail")
pass
if not inputed_value is None:
is_password_appear = True
if inputed_value == "":
# only this case to auto-fill local dictional value.
local_array = []
user_guess_string = config_dict["advanced"]["user_guess_string"]
if len(user_guess_string) > 0:
user_guess_string = format_config_keyword_for_json(user_guess_string)
try:
local_array = json.loads("["+ user_guess_string +"]")
except Exception as exc:
local_array = []
answer_list = local_array
inferred_answer_string = ""
for answer_item in answer_list:
if not answer_item in fail_list:
inferred_answer_string = answer_item
break
if len(inferred_answer_string) > 0:
try:
el_password_input.click()
el_password_input.send_keys(inferred_answer_string)
el_password_input.send_keys(Keys.ENTER)
print("input dictionary answer:", inferred_answer_string)
fail_list.append(inferred_answer_string)
except Exception as exc:
print("set_attribute value fail")
pass
return is_password_appear, fail_list
def hkticketing_date_auto_select(driver, config_dict, fail_list):
show_debug_message = True # debug.
show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
#PS: some blocks are generate by ajax, not appear at first time.
formated_area_list = None
is_page_ready = True
is_date_assigned, is_page_ready, formated_area_list = hkticketing_date_assign(driver, config_dict)
# NOT alway, auto submit
is_date_submiting = False
is_auto_submit = True
is_password_sent = False
is_password_appear, fail_list = hkticketing_date_password_input(driver, config_dict, fail_list)
if is_password_appear:
is_auto_submit = False
if show_debug_message:
print("is_auto_submit:", is_auto_submit)
el_btn = None
if is_auto_submit:
is_button_clicked = force_press_button(driver, By.CSS_SELECTOR, '#buyButton > input')
if show_debug_message:
print("is_button_clicked:", is_button_clicked)
auto_reload_coming_soon_page_enable = config_dict["tixcraft"]["auto_reload_coming_soon_page"]
if show_debug_message:
print("is_password_appear:", is_password_appear)
print("is_date_assigned:", is_date_assigned)
print("is_page_ready:", is_page_ready)
print("formated_area_list:", formated_area_list)
print("auto_reload_coming_soon_page_enable:", auto_reload_coming_soon_page_enable)
if auto_reload_coming_soon_page_enable:
# auto refresh for date list page.
is_need_refresh = True
if is_need_refresh:
if is_password_appear:
is_need_refresh = False
if is_need_refresh:
if is_date_assigned:
# if select box assign.
is_need_refresh = False
else:
if not formated_area_list is None:
if len(formated_area_list) > 0:
# option waiting to assign at next loop.
is_need_refresh = False
# due to select option not generated by server side.
if is_need_refresh:
if not is_page_ready:
is_need_refresh = False
# check next button exist.
if is_need_refresh:
el_btn = None
try:
my_css_selector = "#buyButton > input"
el_btn = driver.find_element(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
pass
if not el_btn is None:
if show_debug_message:
print("next button appear.")
is_need_refresh = False
# finally...
if is_need_refresh:
try:
print("is_need_refresh...")
driver.refresh()
time.sleep(0.2)
except Exception as exc:
pass
return is_date_submiting, fail_list
def hkticketing_area_auto_select(driver, config_dict, area_keyword_item):
show_debug_message = True # debug.
show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
auto_select_mode = config_dict["area_auto_select"]["mode"]
is_price_assign_by_bot = False
is_need_refresh = False
matched_blocks = None
area_list = None
try:
my_css_selector = "#ticketSelectorContainer > ul > li"
area_list = driver.find_elements(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
print("find #ticket-price-tbl date list fail")
print(exc)
formated_area_list = None
if not area_list is None:
area_list_count = len(area_list)
if show_debug_message:
print("area_list_count:", area_list_count)
if area_list_count > 0:
formated_area_list = []
# filter list.
for row in area_list:
row_is_enabled=True
try:
button_class_string = str(row.get_attribute('class'))
if len(button_class_string) > 1:
if 'disabled' in button_class_string:
row_is_enabled=False
if 'unavailable' in button_class_string:
row_is_enabled=False
if 'selected' in button_class_string:
# someone is selected. skip this process.
is_price_assign_by_bot = True
break
except Exception as exc:
pass
if row_is_enabled:
formated_area_list.append(row)
else:
if show_debug_message:
print("area_list_count is empty.")
pass
else:
if show_debug_message:
print("area_list_count is None.")
pass
if is_price_assign_by_bot:
formated_area_list = None
if not formated_area_list is None:
area_list_count = len(formated_area_list)
if show_debug_message:
print("formated_area_list count:", area_list_count)
if area_list_count > 0:
matched_blocks = []
if len(area_keyword_item) == 0:
matched_blocks = formated_area_list
else:
# match keyword.
for row in formated_area_list:
row_text = ""
row_html = ""
try:
#row_text = row.text
row_html = row.get_attribute('innerHTML')
row_text = remove_html_tags(row_html)
except Exception as exc:
if show_debug_message:
print(exc)
# error, exit loop
break
if len(row_text) > 0:
if reset_row_text_if_match_keyword_exclude(config_dict, row_text):
row_text = ""
if len(row_text) > 0:
row_text = format_keyword_string(row_text)
if show_debug_message:
print("row_text:", row_text)
is_match_area = False
if len(area_keyword_item) > 0:
# must match keyword.
is_match_area = True
area_keyword_array = area_keyword_item.split(' ')
for area_keyword in area_keyword_array:
area_keyword = format_keyword_string(area_keyword)
if not area_keyword in row_text:
is_match_area = False
break
else:
# without keyword.
is_match_area = True
if is_match_area:
matched_blocks.append(row)
if auto_select_mode == CONST_FROM_TOP_TO_BOTTOM:
break
if show_debug_message:
print("after match keyword, found count:", len(matched_blocks))
if len(matched_blocks) == 0:
matched_blocks = None
is_need_refresh = True
target_area = get_target_item_from_matched_list(matched_blocks, auto_select_mode)
if not target_area is None:
try:
if target_area.is_enabled():
target_area.click()
is_price_assign_by_bot = True
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)
is_price_assign_by_bot = True
except Exception as exc:
pass
return is_need_refresh, is_price_assign_by_bot
def hkticketing_ticket_number_auto_select(driver, config_dict):
selector_string = 'select.shortSelect'
by_method = By.CSS_SELECTOR
return assign_ticket_number_by_select(driver, config_dict, by_method, selector_string)
def hkticketing_nav_to_footer(driver):
try:
el_nav = None
el_nav = driver.find_element(By.CSS_SELECTOR, '#wrapFooter')
if not el_nav is None:
builder = ActionChains(driver)
builder.move_to_element(el_nav)
builder.click(el_nav)
builder.perform()
except Exception as exc:
pass
def hkticketing_next_button_press(driver):
ret = False
el_btn = None
try:
el_btn = driver.find_element(By.CSS_SELECTOR, '#continueBar > div.chooseTicketsOfferDiv > button')
except Exception as exc:
print("find next button fail...")
print(exc)
if not el_btn is None:
print("bingo, found next button, start to press")
hkticketing_nav_to_footer(driver)
try:
if el_btn.is_enabled() and el_btn.is_displayed():
el_btn.click()
ret = True
except Exception as exc:
print("click next button fail...")
print(exc)
return ret
def hkticketing_go_to_payment(driver):
ret = False
el_btn = None
try:
el_btn = driver.find_element(By.CSS_SELECTOR, '#goToPaymentButton')
except Exception as exc:
print("find next button fail...")
print(exc)
if not el_btn is None:
print("bingo, found next button, start to press")
try:
if el_btn.is_enabled() and el_btn.is_displayed():
el_btn.click()
ret = True
except Exception as exc:
print("click next button fail...")
print(exc)
return ret
def hkticketing_ticket_delivery_option(driver):
show_debug_message = True # debug.
show_debug_message = False # online
is_delivery_option_assigned = False
form_select = None
try:
selector_string = '#selectDeliveryType'
form_select = driver.find_element(By.CSS_SELECTOR, selector_string)
except Exception as exc:
if show_debug_message:
print("find selectDeliveryType select fail")
print(exc)
pass
select_obj = None
if not form_select is None:
is_visible = False
try:
is_visible = form_select.is_enabled()
except Exception as exc:
pass
if is_visible:
try:
select_obj = Select(form_select)
except Exception as exc:
pass
if not select_obj is None:
try:
select_obj.select_by_value("1")
is_delivery_option_assigned = True
except Exception as exc:
print("delivery_option fail")
print(exc)
return is_delivery_option_assigned
def hkticketing_hide_tickets_blocks(driver):
show_debug_message = True # debug.
show_debug_message = False # online
actionBlock_divs = None
try:
selector_string = 'div.actionBlock.note'
actionBlock_divs = driver.find_elements(By.CSS_SELECTOR, selector_string)
for each_div in actionBlock_divs:
driver.execute_script("arguments[0].innerHTML='';", each_div);
except Exception as exc:
if show_debug_message:
print("find selectDeliveryType select fail")
print(exc)
pass
detailModuleCopy_divs = None
try:
selector_string = 'div.detailModuleCopy'
detailModuleCopy_divs = driver.find_elements(By.CSS_SELECTOR, selector_string)
if not detailModuleCopy_divs is None:
driver.execute_script("arguments[0].innerHTML='';", detailModuleCopy_divs);
except Exception as exc:
pass
mapWrapper_divs = None
try:
selector_string = 'div.mapWrapper'
mapWrapper_divs = driver.find_elements(By.CSS_SELECTOR, selector_string)
if not mapWrapper_divs is None:
driver.execute_script("arguments[0].innerHTML='';", mapWrapper_divs);
except Exception as exc:
pass
def hkticketing_performance(driver, config_dict, domain_name):
show_debug_message = True # debug.
show_debug_message = False # online
is_price_assign_by_bot = False
is_need_refresh = False
auto_fill_ticket_number = True
if auto_fill_ticket_number:
# click price row.
area_keyword = config_dict["area_auto_select"]["area_keyword"].strip()
if show_debug_message:
print("area_keyword:", area_keyword)
if len(area_keyword) > 0:
area_keyword_array = []
try:
area_keyword_array = json.loads("["+ area_keyword +"]")
except Exception as exc:
area_keyword_array = []
for area_keyword_item in area_keyword_array:
is_need_refresh, is_price_assign_by_bot = hkticketing_area_auto_select(driver, config_dict, area_keyword_item)
if not is_need_refresh:
break
else:
print("is_need_refresh for keyword:", area_keyword_item)
else:
# empty keyword, match all.
is_need_refresh, is_price_assign_by_bot = hkticketing_area_auto_select(driver, config_dict, "")
if is_need_refresh:
if show_debug_message:
print("is_need_refresh:", is_need_refresh)
try:
driver.refresh()
except Exception as exc:
pass
# hide blocks.
#hkticketing_hide_tickets_blocks(driver)
# goto bottom.
hkticketing_nav_to_footer(driver)
# choose ticket.
is_ticket_number_assigned = hkticketing_ticket_number_auto_select(driver, config_dict)
if show_debug_message:
print("is_ticket_number_assigned:", is_ticket_number_assigned)
# Select a delivery option
is_delivery_option_assigned = True
if not 'galaxymacau.com' in domain_name:
# hkticketing
is_delivery_option_assigned = False
if is_ticket_number_assigned:
is_delivery_option_assigned = hkticketing_ticket_delivery_option(driver)
if show_debug_message:
print("is_delivery_option_assigned:", is_delivery_option_assigned)
if is_delivery_option_assigned:
auto_press_next_step_button = True
if auto_press_next_step_button:
if is_price_assign_by_bot:
for i in range(2):
click_ret = hkticketing_next_button_press(driver)
time.sleep(0.2)
if click_ret:
break
return is_price_assign_by_bot
def hkticketing_escape_robot_detection(driver, url):
ret = False
el_main_iframe = None
try:
el_main_iframe = driver.find_element(By.CSS_SELECTOR, '#main-iframe')
except Exception as exc:
#print("find el_main_iframe fail...")
#print(exc)
pass
if not el_main_iframe is None:
print("we have been detected..., found el_main_iframe")
#entry_url="https://queue.hkticketing.com/hotshow.html"
entry_url="https://premier.hkticketing.com/"
if 'galaxymacau.com' in url:
domain_name = url.split('/')[2]
entry_url = "https://%s/default.aspx" % (domain_name)
try:
#print("start to escape..")
#driver.get(entry_url)
pass
except Exception as exc:
print(exc)
return ret
def hkticketing_url_redirect(driver, url, config_dict):
is_redirected = False
redirect_url_list = [ 'queue.hkticketing.com/hotshow.html'
, '.com/detection.aspx?rt='
, '/busy_galaxy.'
]
for idx in range(20):
redirect_url_list.append('/hot%d.ticketek.com.au/' % (idx))
redirect_to_home_list = [ 'galaxymacau.com'
, 'ticketek.com'
]
for redirect_url in redirect_url_list:
if redirect_url in url:
# for hkticketing.
entry_url = 'http://entry-hotshow.hkticketing.com/'
# for macau
# for ticketek.com
for target_site in redirect_to_home_list:
if target_site in url:
domain_name = url.split('/')[2]
entry_url = "https://%s/default.aspx" % (domain_name)
break
try:
driver.get(entry_url)
is_redirected = True
except Exception as exc:
pass
# 刷太快, 會被封IP?
time.sleep(config_dict["advanced"]["auto_reload_page_interval"])
if is_redirected:
break
return is_redirected
def hkticketing_content_refresh(driver, url, config_dict):
is_redirected = False
is_check_access_deined = False
check_url_list = [".com/default.aspx"
, ".com/shows/show.aspx?sh="
, ".com/detection.aspx"
, "/entry-hotshow."
, ".com/_Incapsula_Resource?"
]
for current_url in check_url_list:
if current_url in url:
is_check_access_deined = True
break
check_full_url_list = [ "https://premier.hkticketing.com/"
, "https://www.ticketing.galaxymacau.com/"
, "https://ticketing.galaxymacau.com/"
, "https://ticketing.galaxymacau.com/default.aspx"
]
for current_url in check_full_url_list:
if current_url == url:
is_check_access_deined = True
content_retry_string_list = [ "Access Denied"
, "Service Unavailable"
, "The service is unavailable"
, "HTTP Error 500"
, "HTTP Error 503"
, "504 Gateway Time-out"
, "502 Bad Gateway"
, "An error occurred while processing your request"
, "The network path was not found"
, "Could not open a connection to SQL Server"
, "Hi fans, you’re in the queue to"
, "We will check for the next available purchase slot"
, "please stay on this page and do not refresh"
, "Please be patient and wait a few minutes before trying again"
, "Server Error in '/' Application"
, "The target principal name is incorrect"
, "Cannot generate SSPI context"
, "System.Data.SqlClient.Sql"
, "System.ComponentModel.Win32Exception"
, "Access Denied"
, "Your attempt to access the web site has been blocked by"
, "This requset was blocked by"
]
if is_check_access_deined:
domain_name = url.split('/')[2]
new_url = "https://%s/default.aspx" % (domain_name)
is_need_refresh = False
html_body = None
try:
html_body = driver.page_source
if not html_body is None:
for each_retry_string in content_retry_string_list:
if each_retry_string in html_body:
is_need_refresh = True
break
except Exception as exc:
#print(exc)
pass
if is_need_refresh:
print("Start to automatically refresh page.")
try:
driver.switch_to.default_content()
print("redirect to new url:", new_url)
driver.get(new_url)
is_redirected = True
except Exception as exc:
#print(exc)
pass
# 刷太快, 會被封IP?
time.sleep(config_dict["advanced"]["auto_reload_page_interval"])
return is_redirected
def hkticketing_travel_iframe(driver, config_dict):
is_redirected = False
iframes = None
try:
iframes = driver.find_elements(By.TAG_NAME, "iframe")
except Exception as exc:
pass
if iframes is None:
iframes = []
#print('start to travel iframes...')
idx_iframe=0
for iframe in iframes:
iframe_url = ""
try:
iframe_url = str(iframe.get_attribute('src'))
#print("url:", iframe_url)
except Exception as exc:
print("get iframe url fail.")
#print(exc)
pass
idx_iframe += 1
try:
#print("switch to #", idx_iframe, ":", iframe_url)
driver.switch_to.frame(iframe)
is_redirected = hkticketing_content_refresh(driver, iframe_url, config_dict)
except Exception as exc:
pass
if not is_redirected:
try:
driver.switch_to.default_content()
except Exception as exc:
pass
return is_redirected
def softix_powerweb_main(driver, url, config_dict, hkticketing_dict):
home_url_list = ['https://premier.hkticketing.com/'
,'https://hotshow.hkticketing.com/'
,'https://premier.hkticketing.com/default.aspx'
,'https://hotshow.hkticketing.com/default.aspx'
,'https://premier.hkticketing.com/Membership/Login.aspx'
,'https://hotshow.hkticketing.com/Membership/Login.aspx'
,'https://premier.hkticketing.com/Secure/ShowLogin.aspx'
]
for each_url in home_url_list:
if each_url == url:
hkticketing_home(driver)
break
hkticketing_accept_cookie(driver)
is_redirected = hkticketing_url_redirect(driver, url, config_dict)
if not is_redirected:
is_redirected = hkticketing_content_refresh(driver, url, config_dict)
if not is_redirected:
is_redirected = hkticketing_travel_iframe(driver, config_dict)
# https://premier.hkticketing.com/Membership/UpdateAccount_Default.aspx
is_hkticketing_sign_in_page = False
if 'hkticketing.com/Secure/ShowLogin.aspx' in url:
is_hkticketing_sign_in_page = True
if 'hkticketing.com/Membership/Login.aspx' in url:
is_hkticketing_sign_in_page = True
if is_hkticketing_sign_in_page:
account = config_dict["advanced"]["hkticketing_account"].strip()
if len(account) > 4:
hkticketing_login(driver, account, decryptMe(config_dict["advanced"]["hkticketing_password"]))
is_ready_to_buy_from_queue = False
# TODO: play sound when ready to buy ticket.
# Q: How to know ready to buy ticket from queue?
if is_ready_to_buy_from_queue:
play_sound_while_ordering(config_dict)
#https://premier.hkticketing.com/shows/show.aspx?sh=XXXX
if 'shows/show.aspx?' in url:
is_modal_dialog_popup = check_modal_dialog_popup(driver)
if is_modal_dialog_popup:
print("is_modal_dialog_popup! skip...")
else:
is_event_page = False
if len(url.split('/'))==5:
is_event_page = True
if is_event_page:
if config_dict["tixcraft"]["date_auto_select"]["enable"]:
if not hkticketing_dict["is_date_submiting"]:
hkticketing_dict["is_date_submiting"], hkticketing_dict["fail_list"] = hkticketing_date_auto_select(driver, config_dict, hkticketing_dict["fail_list"])
pass
else:
#print('double check buy button status.')
hkticketing_date_buy_button_press(driver)
else:
hkticketing_dict["is_date_submiting"] = False
hkticketing_dict["fail_list"] = []
# https://premier.hkticketing.com/events/XXX/venues/KSH/performances/XXX/tickets
if '/events/' in url and '/performances/' in url:
robot_detection = hkticketing_escape_robot_detection(driver, url)
is_modal_dialog_popup = check_modal_dialog_popup(driver)
if is_modal_dialog_popup:
print("is_modal_dialog_popup! skip...")
else:
if '/tickets' in url:
domain_name = url.split('/')[2]
if config_dict["area_auto_select"]["enable"]:
hkticketing_performance(driver, config_dict, domain_name)
pass
if '/seatmap' in url:
# goto bottom.
hkticketing_nav_to_footer(driver)
hkticketing_go_to_payment(driver)
return hkticketing_dict
def khan_go_buy_redirect(driver, domain_name):
is_button_clicked = False
if 'kham.com' in domain_name:
is_button_clicked = force_press_button(driver, By.CSS_SELECTOR, 'p > a > button.red')
if 'ticket.com' in domain_name:
is_button_clicked = force_press_button(driver, By.CSS_SELECTOR, 'div.row > div > a.btn.btn-order.btn-block')
return is_button_clicked
def hkam_date_auto_select(driver, domain_name, config_dict):
show_debug_message = True # debug.
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)
matched_blocks = None
area_list = None
try:
# for kham.com
my_css_selector = "table.eventTABLE > tbody > tr"
if 'ticket.com' in domain_name:
my_css_selector = "div.description > table.table.table-striped.itable > tbody > tr"
area_list = driver.find_elements(By.CSS_SELECTOR, my_css_selector)
except Exception as exc:
print("find #date-time tr list fail")
print(exc)
#PS: some blocks are generate by ajax, not appear at first time.
formated_area_list = None
if not area_list is None:
area_list_count = len(area_list)
if show_debug_message:
print("date_list_count:", area_list_count)
if area_list_count > 0:
formated_area_list = []
# filter list.
for row in area_list:
row_text = ""
row_html = ""
try:
#row_text = row.text
row_html = row.get_attribute('innerHTML')
row_text = remove_html_tags(row_html)
except Exception as exc:
if show_debug_message:
print(exc)
# error, exit loop
break
if len(row_text) > 0:
if reset_row_text_if_match_keyword_exclude(config_dict, row_text):
row_text = ""
if len(row_text) > 0:
if "