Update for udn

master
Max 2023-12-11 17:00:23 +08:00 committed by GitHub
parent 652b93192b
commit c0f23d37f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 118 additions and 40 deletions

View File

@ -55,7 +55,7 @@ import webbrowser
import chromedriver_autoinstaller import chromedriver_autoinstaller
CONST_APP_VERSION = "MaxBot (2023.12.03)" CONST_APP_VERSION = "MaxBot (2023.12.04)"
CONST_MAXBOT_CONFIG_FILE = "settings.json" CONST_MAXBOT_CONFIG_FILE = "settings.json"
CONST_MAXBOT_LAST_URL_FILE = "MAXBOT_LAST_URL.txt" CONST_MAXBOT_LAST_URL_FILE = "MAXBOT_LAST_URL.txt"
@ -837,6 +837,7 @@ def get_driver_by_config(config_dict):
,'*youtube.com/*' ,'*youtube.com/*'
,'*player.youku.*' ,'*player.youku.*'
,'*h.clarity.ms/*' ,'*h.clarity.ms/*'
,'*img.uniicreative.com/*'
,'*e2elog.fetnet.net*'] ,'*e2elog.fetnet.net*']
if config_dict["advanced"]["hide_some_image"]: if config_dict["advanced"]["hide_some_image"]:
@ -9728,7 +9729,11 @@ def khan_go_buy_redirect(driver, domain_name):
if 'ticket.com' in domain_name: 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') is_button_clicked = force_press_button(driver, By.CSS_SELECTOR, 'div.row > div > a.btn.btn-order.btn-block')
if 'udnfunlife.com' in domain_name: if 'udnfunlife.com' in domain_name:
is_button_clicked = force_press_button(driver, By.CSS_SELECTOR, '#buttonBuy') # udn 快速訂購
my_css_selector = 'button[name="fastBuy"]'
is_button_clicked = force_press_button(driver, By.CSS_SELECTOR, my_css_selector)
if not is_button_clicked:
is_button_clicked = force_press_button(driver, By.CSS_SELECTOR, '#buttonBuy')
return is_button_clicked return is_button_clicked
def hkam_date_auto_select(driver, domain_name, config_dict): def hkam_date_auto_select(driver, domain_name, config_dict):
@ -9946,9 +9951,14 @@ def kham_area_auto_select(driver, domain_name, config_dict, area_keyword_item):
try: try:
# for kham.com # for kham.com
my_css_selector = "table#salesTable > tbody > tr[class='status_tr']" my_css_selector = "table#salesTable > tbody > tr[class='status_tr']"
if "ticket.com.tw" in domain_name: if "ticket.com.tw" in domain_name:
my_css_selector = "li.main" my_css_selector = "li.main"
print("my_css_selector:",my_css_selector) #print("my_css_selector:",my_css_selector)
if "udnfunlife" in domain_name:
my_css_selector = "table.yd_ticketsTable > tbody > tr.main"
area_list = driver.find_elements(By.CSS_SELECTOR, my_css_selector) area_list = driver.find_elements(By.CSS_SELECTOR, my_css_selector)
except Exception as exc: except Exception as exc:
print("find #ticket-price-tbl date list fail") print("find #ticket-price-tbl date list fail")
@ -10012,27 +10022,34 @@ def kham_area_auto_select(driver, domain_name, config_dict, area_keyword_item):
if ' Soldout' in row_html: if ' Soldout' in row_html:
row_text = "" row_text = ""
# for udn
if ' style="color:gray;border:solid 1px gray;cursor:default"' in row_html:
#row_text = ""
pass
if len(row_text) > 0: if len(row_text) > 0:
if reset_row_text_if_match_keyword_exclude(config_dict, row_text): if reset_row_text_if_match_keyword_exclude(config_dict, row_text):
row_text = "" row_text = ""
# check ticket_number and available count. # check ticket_number and available count.
if len(row_text) > 0: if len(row_text) > 0:
if config_dict["ticket_number"] > 1: # remaining number not appear in udn.
maybe_ticket_count = row_text[-1:] if not("udnfunlife" in domain_name):
if maybe_ticket_count.isdigit(): if config_dict["ticket_number"] > 1:
if "<td" in row_html: maybe_ticket_count = row_text[-1:]
td_array = row_html.split("<td") if maybe_ticket_count.isdigit():
if len(td_array) > 0: if "<td" in row_html:
td_target = "<td" + td_array[len(td_array)-1] td_array = row_html.split("<td")
ticket_count_text = remove_html_tags(td_target) if len(td_array) > 0:
print("ticket_count_text:", ticket_count_text) td_target = "<td" + td_array[len(td_array)-1]
if ticket_count_text.isdigit(): ticket_count_text = remove_html_tags(td_target)
if int(ticket_count_text) < config_dict["ticket_number"]: #print("ticket_count_text:", ticket_count_text)
if show_debug_message: if ticket_count_text.isdigit():
print("skip this row, because ticket_count available only:", ticket_count_text) if int(ticket_count_text) < config_dict["ticket_number"]:
# skip this row. if show_debug_message:
row_text = "" print("skip this row, because ticket_count available only:", ticket_count_text)
# skip this row.
row_text = ""
if len(row_text) > 0: if len(row_text) > 0:
row_text = format_keyword_string(row_text) row_text = format_keyword_string(row_text)
@ -10071,19 +10088,63 @@ def kham_area_auto_select(driver, domain_name, config_dict, area_keyword_item):
target_area = get_target_item_from_matched_list(matched_blocks, auto_select_mode) target_area = get_target_item_from_matched_list(matched_blocks, auto_select_mode)
if not target_area is None: if not target_area is None:
try: try:
if target_area.is_enabled(): if not("udnfunlife" in domain_name):
target_area.click() if target_area.is_enabled():
is_price_assign_by_bot = True target_area.click()
is_price_assign_by_bot = True
else:
# manually click.
"""
my_css_selector = 'div.yd_btn--link'
target_button = target_area.find_element(By.CSS_SELECTOR, my_css_selector)
if not target_button is None:
target_button.click()
is_price_assign_by_bot = True
"""
FAST_PRICE_TYPE_ID = ""
target_area_html = target_area.get_attribute('innerHTML')
if 'fastcode="' in target_area_html:
temp_string = target_area_html.split('fastcode="')[1]
FAST_PRICE_TYPE_ID = temp_string.split('"')[0]
if len(FAST_PRICE_TYPE_ID) > 0:
js = """fetch("https://tickets.udnfunlife.com/Application/UTK01/UTK0101_009.aspx/AUTOSEAT_BTN_Click", {
"headers": {
"accept": "*/*",
"accept-language": "en-US,en;q=0.9,zh;q=0.8,zh-TW;q=0.7",
"content-type": "application/json; charset=UTF-8",
"sec-ch-ua-mobile": "?0",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"x-requested-with": "XMLHttpRequest"
},
"referrerPolicy": "strict-origin-when-cross-origin",
"body": JSON.stringify({"FAST_PRICE_TYPE_ID":"%s","QRY":"%s","CHK":"null"}),
"method": "POST",
"mode": "cors",
"credentials": "include"
}).then(function (response) { return response.json();
}).then(function (data) { if(data.d.ReturnData.script.indexOf('top.location.href')>-1){eval(script);};
if(data.d.ReturnData.script.indexOf('上限')>-1){top.location.href="https://tickets.udnfunlife.com/application/UTK02/UTK0206_.aspx";};
if(data.d.ReturnData.script.indexOf('該場次目前無法購買。 ')>-1){location.reload();};
}).catch(function (err) { console.log(err);
});""" % (FAST_PRICE_TYPE_ID, str(config_dict["ticket_number"]));
#print("javascript:", js)
driver.execute_script(js)
is_price_assign_by_bot = True
except Exception as exc: except Exception as exc:
print("click target_area link fail") print("click target_area link fail")
print(exc) print(exc)
# use plan B # use plan B
try: if not("udnfunlife" in domain_name):
print("force to click by js.") try:
driver.execute_script("arguments[0].click();", target_area) print("force to click by js.")
is_price_assign_by_bot = True driver.execute_script("arguments[0].click();", target_area)
except Exception as exc: is_price_assign_by_bot = True
pass except Exception as exc:
pass
else: else:
if show_debug_message: if show_debug_message:
print("target_area is None, no target to click.") print("target_area is None, no target to click.")
@ -10238,7 +10299,9 @@ def kham_performance(driver, config_dict, ocr, Captcha_Browser, domain_name, mod
except Exception as exc: except Exception as exc:
pass pass
is_captcha_sent = kham_captcha(driver, config_dict, ocr, Captcha_Browser, model_name) # udn use reCaptcha.
if not('udnfunlife' in domain_name):
is_captcha_sent = kham_captcha(driver, config_dict, ocr, Captcha_Browser, model_name)
return is_price_assign_by_bot, is_captcha_sent return is_price_assign_by_bot, is_captcha_sent
@ -10539,8 +10602,7 @@ def kham_main(driver, url, config_dict, ocr, Captcha_Browser):
is_event_page = True is_event_page = True
if is_event_page: if is_event_page:
date_auto_select_enable = config_dict["tixcraft"]["date_auto_select"]["enable"] if config_dict["tixcraft"]["date_auto_select"]["enable"]:
if date_auto_select_enable:
kham_product(driver, domain_name, config_dict) kham_product(driver, domain_name, config_dict)
if '/application/utk01/utk0101_.aspx' in url.lower(): if '/application/utk01/utk0101_.aspx' in url.lower():
@ -10550,15 +10612,20 @@ def kham_main(driver, url, config_dict, ocr, Captcha_Browser):
# for udn # for udn
if 'udnfunlife' in domain_name: if 'udnfunlife' in domain_name:
try: #auto_close_tab = False
window_handles_count = len(driver.window_handles) auto_close_tab = True
if window_handles_count > 1: if auto_close_tab:
driver.switch_to.window(driver.window_handles[0]) try:
driver.close() window_handles_count = len(driver.window_handles)
driver.switch_to.window(driver.window_handles[0]) if window_handles_count > 1:
time.sleep(0.2) #print("window_handles_count:", window_handles_count)
except Exception as excSwithFail: driver.switch_to.window(driver.window_handles[0])
pass driver.close()
driver.switch_to.window(driver.window_handles[0])
time.sleep(0.2)
except Exception as exc:
print(exc)
pass
# udn sign in. # udn sign in.
if 'https://tickets.udnfunlife.com/application/utk01/utk0101_.aspx' == url.lower(): if 'https://tickets.udnfunlife.com/application/utk01/utk0101_.aspx' == url.lower():
@ -10584,6 +10651,16 @@ def kham_main(driver, url, config_dict, ocr, Captcha_Browser):
if date_auto_select_enable: if date_auto_select_enable:
kham_product(driver, domain_name, config_dict) kham_product(driver, domain_name, config_dict)
if 'utk0222_02.aspx?product_id=' in url.lower():
model_name = url.split('/')[5]
if len(model_name) > 7:
model_name=model_name[:7]
is_price_assign_by_bot, is_captcha_sent = kham_performance(driver, config_dict, ocr, Captcha_Browser, domain_name, model_name)
is_ticket_number_sent = assign_text(driver, By.CSS_SELECTOR, 'input#QRY2', str(config_dict["ticket_number"]), overwrite_when="0")
if is_ticket_number_sent:
is_fastbuy_pressed = force_press_button(driver, By.CSS_SELECTOR,'input#f_btn')
else: else:
# kham / ticket. # kham / ticket.
@ -10604,7 +10681,8 @@ def kham_main(driver, url, config_dict, ocr, Captcha_Browser):
if is_reset_password_text: if is_reset_password_text:
is_captcha_sent = kham_captcha(driver, config_dict, ocr, Captcha_Browser, model_name) is_captcha_sent = kham_captcha(driver, config_dict, ocr, Captcha_Browser, model_name)
is_button_clicked = force_press_button(driver, By.CSS_SELECTOR,'div.ui-dialog-buttonset > button.ui-button') my_css_selector = 'div.ui-dialog-buttonset > button.ui-button'
is_button_clicked = force_press_button(driver, By.CSS_SELECTOR, my_css_selector)
if config_dict["area_auto_select"]["enable"]: if config_dict["area_auto_select"]["enable"]:
if "ticket.com.tw" in url: if "ticket.com.tw" in url:
is_switch_to_auto_seat = ticket_switch_to_auto_seat(driver) is_switch_to_auto_seat = ticket_switch_to_auto_seat(driver)