2023-03-13, update for kham,cityline

master
CHUN YU YAO 2023-03-15 23:40:05 +08:00
parent 08d4846b35
commit 8ca95ea1e0
3 changed files with 71 additions and 207 deletions

View File

@ -53,7 +53,7 @@ import argparse
import ssl import ssl
ssl._create_default_https_context = ssl._create_unverified_context ssl._create_default_https_context = ssl._create_unverified_context
CONST_APP_VERSION = u"MaxBot (2023.03.12)" CONST_APP_VERSION = u"MaxBot (2023.03.13)"
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"
@ -360,10 +360,6 @@ def load_chromdriver_uc(webdriver_path, adblock_plus_enable, headless):
caps["unhandledPromptBehavior"] = u"accept" caps["unhandledPromptBehavior"] = u"accept"
driver = None driver = None
if os.path.exists(chromedriver_path):
print("Use user driver path:", chromedriver_path)
#driver = uc.Chrome(service=chrome_service, options=options, suppress_welcome=False)
is_local_chrome_browser_lower = False
try: try:
driver = uc.Chrome(executable_path=chromedriver_path, options=options, desired_capabilities=caps, suppress_welcome=False) driver = uc.Chrome(executable_path=chromedriver_path, options=options, desired_capabilities=caps, suppress_welcome=False)
except Exception as exc: except Exception as exc:
@ -376,14 +372,7 @@ def load_chromdriver_uc(webdriver_path, adblock_plus_enable, headless):
if "This version of ChromeDriver only supports Chrome version" in error_message: if "This version of ChromeDriver only supports Chrome version" in error_message:
print(CONST_CHROME_VERSION_NOT_MATCH_EN) print(CONST_CHROME_VERSION_NOT_MATCH_EN)
print(CONST_CHROME_VERSION_NOT_MATCH_TW) print(CONST_CHROME_VERSION_NOT_MATCH_TW)
is_local_chrome_browser_lower = True
pass
if is_local_chrome_browser_lower:
print("Unable to use undetected_chromedriver, ")
print("try to use local chromedriver to launch chrome browser.")
driver_type = "selenium"
driver = load_chromdriver_normal(webdriver_path, driver_type, adblock_plus_enable, headless)
else: else:
print("Oops! web driver not on path:",chromedriver_path ) print("Oops! web driver not on path:",chromedriver_path )
print('let uc automatically download chromedriver.') print('let uc automatically download chromedriver.')
@ -402,16 +391,13 @@ def load_chromdriver_uc(webdriver_path, adblock_plus_enable, headless):
pass pass
if driver is None: if driver is None:
print("create web drive object fail!") print("create web drive object by undetected_chromedriver fail!")
else:
download_dir_path="." if os.path.exists(chromedriver_path):
params = { print("Unable to use undetected_chromedriver, ")
"behavior": "allow", print("try to use local chromedriver to launch chrome browser.")
"downloadPath": os.path.realpath(download_dir_path) driver_type = "selenium"
} driver = load_chromdriver_normal(webdriver_path, driver_type, adblock_plus_enable, headless)
#print("assign setDownloadBehavior.")
driver.execute_cdp_cmd("Page.setDownloadBehavior", params)
#print("driver capabilities", driver.capabilities)
return driver return driver
@ -1209,7 +1195,7 @@ def force_press_button(driver, select_by, select_query, force_by_js=True):
next_step_button.click() next_step_button.click()
ret = True ret = True
except Exception as exc: except Exception as exc:
print("find %s clickable Exception:" % (select_query)) #print("find %s clickable Exception:" % (select_query))
#print(exc) #print(exc)
pass pass
@ -5649,7 +5635,7 @@ def kham_login(driver, account, password):
ret = False ret = False
el_email = None el_email = None
try: try:
my_css_selector = 'table#blockLogin > tbody > tr > td > input[type="text"]' my_css_selector = '#ACCOUNT'
el_email = driver.find_element(By.CSS_SELECTOR, my_css_selector) el_email = driver.find_element(By.CSS_SELECTOR, my_css_selector)
except Exception as exc: except Exception as exc:
pass pass
@ -5679,7 +5665,7 @@ def kham_login(driver, account, password):
el_pass = None el_pass = None
if is_email_sent: if is_email_sent:
try: try:
my_css_selector = 'table#blockLogin > tbody > tr > td > input[type="password"]' my_css_selector = 'table.login > tbody > tr > td > input[type="password"]'
el_pass = driver.find_element(By.CSS_SELECTOR, my_css_selector) el_pass = driver.find_element(By.CSS_SELECTOR, my_css_selector)
except Exception as exc: except Exception as exc:
pass pass
@ -5699,14 +5685,8 @@ def kham_login(driver, account, password):
except Exception as exc: except Exception as exc:
pass pass
el_btn = None
if is_password_sent: if is_password_sent:
try: is_button_clicked = force_press_button(driver, By.CSS_SELECTOR,'div.memberContent > p > a > button.red')
el_btn = driver.find_element(By.CSS_SELECTOR, '#ctl00_ContentPlaceHolder1_LOGIN_BTN')
if not el_btn is None:
el_btn.click()
except Exception as exc:
pass
ret = is_password_sent ret = is_password_sent
@ -6134,33 +6114,7 @@ def cityline_home_close_window(driver):
close_styles_list = ['.anticon-close', '.cookieWrapper_closeBtn'] close_styles_list = ['.anticon-close', '.cookieWrapper_closeBtn']
for close_styles in close_styles_list: for close_styles in close_styles_list:
close_all_alert_btns = None is_button_clicked = force_press_button(driver, By.CSS_SELECTOR, close_styles)
try:
close_all_alert_btns = driver.find_elements(By.CSS_SELECTOR, close_styles)
except Exception as exc:
print("find close button fail")
if close_all_alert_btns is not None:
if show_debug_message:
print('all close button count:', len(close_all_alert_btns))
for alert_btn in close_all_alert_btns:
is_visible = False
try:
if alert_btn.is_enabled() and alert_btn.is_displayed():
is_visible = True
except Exception as exc:
pass
if is_visible:
try:
alert_btn.click()
except Exception as exc:
print("try to click close button fail, force click by js.")
try:
driver.execute_script("arguments[0].click();", alert_btn)
except Exception as exc:
pass
def cityline_main(driver, url, config_dict): def cityline_main(driver, url, config_dict):
#https://www.cityline.com/Events.html #https://www.cityline.com/Events.html
@ -7398,32 +7352,18 @@ def hkticketing_main(driver, url, config_dict, hkticketing_dict):
return hkticketing_dict return hkticketing_dict
def khan_go_buy_redirect(driver): def khan_go_buy_redirect(driver):
ret = False is_button_clicked = force_press_button(driver, By.CSS_SELECTOR, 'p > a > button.red')
return is_button_clicked
el_btn = None def hkam_date_auto_select(driver, config_dict, date_keyword, auto_reload_coming_soon_page_enable):
try:
el_btn = driver.find_element(By.CSS_SELECTOR, 'div.btn_go > input[type="image"]')
except Exception as exc:
#print("find next button fail...")
#print(exc)
pass
if el_btn is not 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 hkam_date_auto_select(driver, auto_select_mode, date_keyword, auto_reload_coming_soon_page_enable):
show_debug_message = True # debug. show_debug_message = True # debug.
show_debug_message = False # online show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
auto_select_mode = config_dict["tixcraft"]["date_auto_select"]["mode"]
ret = False ret = False
matched_blocks = None matched_blocks = None
@ -7436,7 +7376,7 @@ def hkam_date_auto_select(driver, auto_select_mode, date_keyword, auto_reload_co
if not is_date_assigned: if not is_date_assigned:
area_list = None area_list = None
try: try:
my_css_selector = "td.contentCenterBg > table > tbody > tr > td > table > tbody > tr > td > table > tbody > tr > td > div > table > tbody > tr" my_css_selector = "table.eventTABLE > tbody > tr"
area_list = driver.find_elements(By.CSS_SELECTOR, my_css_selector) area_list = driver.find_elements(By.CSS_SELECTOR, my_css_selector)
except Exception as exc: except Exception as exc:
print("find #date-time tr list fail") print("find #date-time tr list fail")
@ -7460,7 +7400,7 @@ def hkam_date_auto_select(driver, auto_select_mode, date_keyword, auto_reload_co
try: try:
row_text = row.text row_text = row.text
if '立即訂購' in row_text: if '立即訂購' in row_text:
my_css_selector = "a.showoder" my_css_selector = "a > button"
el_btn = row.find_element(By.CSS_SELECTOR, my_css_selector) el_btn = row.find_element(By.CSS_SELECTOR, my_css_selector)
if el_btn is not None: if el_btn is not None:
if el_btn.is_enabled(): if el_btn.is_enabled():
@ -7563,7 +7503,7 @@ def hkam_date_auto_select(driver, auto_select_mode, date_keyword, auto_reload_co
if target_area is not None: if target_area is not None:
el_btn = None el_btn = None
try: try:
my_css_selector = "a.showoder" my_css_selector = "a > button"
el_btn = target_area.find_element(By.CSS_SELECTOR, my_css_selector) el_btn = target_area.find_element(By.CSS_SELECTOR, my_css_selector)
except Exception as exc: except Exception as exc:
pass pass
@ -7601,6 +7541,9 @@ def kham_product(driver, config_dict):
show_debug_message = True # debug. show_debug_message = True # debug.
show_debug_message = False # online show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
date_auto_select_mode = config_dict["tixcraft"]["date_auto_select"]["mode"] date_auto_select_mode = config_dict["tixcraft"]["date_auto_select"]["mode"]
date_keyword = config_dict["tixcraft"]["date_auto_select"]["date_keyword"].strip() date_keyword = config_dict["tixcraft"]["date_auto_select"]["date_keyword"].strip()
auto_reload_coming_soon_page_enable = config_dict["tixcraft"]["auto_reload_coming_soon_page"] auto_reload_coming_soon_page_enable = config_dict["tixcraft"]["auto_reload_coming_soon_page"]
@ -7608,14 +7551,24 @@ def kham_product(driver, config_dict):
if show_debug_message: if show_debug_message:
print("date_keyword:", date_keyword) print("date_keyword:", date_keyword)
print("auto_reload_coming_soon_page_enable:", auto_reload_coming_soon_page_enable) print("auto_reload_coming_soon_page_enable:", auto_reload_coming_soon_page_enable)
is_date_assign_by_bot = hkam_date_auto_select(driver, date_auto_select_mode, date_keyword, auto_reload_coming_soon_page_enable) is_date_assign_by_bot = hkam_date_auto_select(driver, config_dict, date_keyword, auto_reload_coming_soon_page_enable)
if not is_date_assign_by_bot:
# click not on sale now.
is_button_clicked = force_press_button(driver, By.CSS_SELECTOR,'div.ui-dialog-buttonset > button.ui-button')
pass
return is_date_assign_by_bot return is_date_assign_by_bot
def kham_area_auto_select(driver, area_auto_select_mode, area_keyword_1, area_keyword_1_and, ticket_number): def kham_area_auto_select(driver, config_dict, area_keyword_1, area_keyword_1_and, ticket_number):
show_debug_message = True # debug. show_debug_message = True # debug.
show_debug_message = False # online show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
area_auto_select_mode = config_dict["tixcraft"]["area_auto_select"]["mode"]
is_price_assign_by_bot = False is_price_assign_by_bot = False
is_need_refresh = False is_need_refresh = False
@ -7627,7 +7580,7 @@ def kham_area_auto_select(driver, area_auto_select_mode, area_keyword_1, area_ke
area_list = None area_list = None
try: try:
my_css_selector = "table.salesTable > tbody > tr > td > table > tbody > tr" my_css_selector = "table#salesTable > tbody > tr"
area_list = driver.find_elements(By.CSS_SELECTOR, my_css_selector) area_list = driver.find_elements(By.CSS_SELECTOR, my_css_selector)
except Exception as exc: except Exception as exc:
print("find #ticket-price-tbl date list fail") print("find #ticket-price-tbl date list fail")
@ -7641,22 +7594,9 @@ def kham_area_auto_select(driver, area_auto_select_mode, area_keyword_1, area_ke
readme_table_mode = True readme_table_mode = True
if readme_table_mode: if readme_table_mode:
if show_debug_message: if show_debug_message:
print("for without table.salesTable") print("for without table#salesTable")
try: # TODO://
my_css_selector = "#readmeTable" # ...
readme_table = driver.find_element(By.CSS_SELECTOR, my_css_selector)
if not readme_table is None:
if show_debug_message:
print("found readme_table")
target_table = readme_table.find_element(By.XPATH, '../..')
if not target_table is None:
if show_debug_message:
print("found target_table")
my_css_selector = "td > table > tbody > tr"
area_list = target_table.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 formated_area_list = None
@ -7688,16 +7628,7 @@ def kham_area_auto_select(driver, area_auto_select_mode, area_keyword_1, area_ke
tr_id_string = str(row.get_attribute('id')) tr_id_string = str(row.get_attribute('id'))
if len(tr_id_string) > 1: if len(tr_id_string) > 1:
is_row_with_id = True is_row_with_id = True
if is_row_with_id: if is_row_with_id:
my_css_selector = "span.textPrice"
el_remaining = row.find_element(By.CSS_SELECTOR, my_css_selector)
if el_remaining is not None:
remaining_value = str(el_remaining.text).strip()
if remaining_value.isnumeric():
if int(remaining_value) >= ticket_number:
row_is_enabled=True
else:
row_is_enabled=True row_is_enabled=True
except Exception as exc: except Exception as exc:
pass pass
@ -7877,13 +7808,15 @@ def kham_performance(driver, config_dict, ocr, Captcha_Browser, model_name):
show_debug_message = True # debug. show_debug_message = True # debug.
show_debug_message = False # online show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
is_price_assign_by_bot = False is_price_assign_by_bot = False
is_need_refresh = False is_need_refresh = False
auto_fill_ticket_number = True auto_fill_ticket_number = True
if auto_fill_ticket_number: if auto_fill_ticket_number:
# click price row. # click price row.
area_auto_select_mode = config_dict["tixcraft"]["area_auto_select"]["mode"]
area_keyword_1 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_1"].strip() area_keyword_1 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_1"].strip()
area_keyword_2 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_2"].strip() area_keyword_2 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_2"].strip()
area_keyword_3 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_3"].strip() area_keyword_3 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_3"].strip()
@ -7902,22 +7835,22 @@ def kham_performance(driver, config_dict, ocr, Captcha_Browser, model_name):
is_need_refresh = False is_need_refresh = False
if not is_price_assign_by_bot: if not is_price_assign_by_bot:
is_need_refresh, is_price_assign_by_bot = kham_area_auto_select(driver, area_auto_select_mode, area_keyword_1, area_keyword_1_and, ticket_number) is_need_refresh, is_price_assign_by_bot = kham_area_auto_select(driver, config_dict, area_keyword_1, area_keyword_1_and, ticket_number)
if not is_need_refresh: if not is_need_refresh:
if not is_price_assign_by_bot: if not is_price_assign_by_bot:
# try keyword_2 # try keyword_2
if len(area_keyword_2) > 0: if len(area_keyword_2) > 0:
is_need_refresh, is_price_assign_by_bot = kham_area_auto_select(driver, area_auto_select_mode, area_keyword_2, area_keyword_2_and, ticket_number) is_need_refresh, is_price_assign_by_bot = kham_area_auto_select(driver, config_dict, area_keyword_2, area_keyword_2_and, ticket_number)
if not is_need_refresh: if not is_need_refresh:
if not is_price_assign_by_bot: if not is_price_assign_by_bot:
if len(area_keyword_3) > 0: if len(area_keyword_3) > 0:
is_need_refresh, is_price_assign_by_bot = kham_area_auto_select(driver, area_auto_select_mode, area_keyword_3, "", ticket_number) is_need_refresh, is_price_assign_by_bot = kham_area_auto_select(driver, config_dict, area_keyword_3, "", ticket_number)
if not is_need_refresh: if not is_need_refresh:
if not is_price_assign_by_bot: if not is_price_assign_by_bot:
if len(area_keyword_4) > 0: if len(area_keyword_4) > 0:
is_need_refresh, is_price_assign_by_bot = kham_area_auto_select(driver, area_auto_select_mode, area_keyword_4, "", ticket_number) is_need_refresh, is_price_assign_by_bot = kham_area_auto_select(driver, config_dict, area_keyword_4, "", ticket_number)
if is_need_refresh: if is_need_refresh:
if show_debug_message: if show_debug_message:
@ -7945,45 +7878,6 @@ def kham_performance(driver, config_dict, ocr, Captcha_Browser, model_name):
return is_price_assign_by_bot return is_price_assign_by_bot
def kham_performance_confirm_dialog_popup(driver):
ret = False
el_div = None
try:
el_div = driver.find_element(By.CSS_SELECTOR, 'div.ui-dialog-buttonset > button.ui-button')
except Exception as exc:
#print("find modal-dialog fail")
#print(exc)
pass
if el_div is not None:
#print("bingo, found ui-dialog-buttonset 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
return ret
def kham_keyin_captcha_code(driver, answer = "", auto_submit = False): def kham_keyin_captcha_code(driver, answer = "", auto_submit = False):
is_verifyCode_editing = False is_verifyCode_editing = False
is_form_sumbited = False is_form_sumbited = False
@ -8189,35 +8083,7 @@ def kham_captcha(driver, config_dict, ocr, Captcha_Browser, model_name):
return is_cpatcha_sent return is_cpatcha_sent
def kham_home_close_window(driver): def kham_home_close_window(driver):
show_debug_message = True # debug. is_button_clicked = force_press_button(driver, By.CSS_SELECTOR,'.closeBTN')
show_debug_message = False # online
close_all_alert_btns = None
try:
close_all_alert_btns = driver.find_elements(By.ID, 'Close')
except Exception as exc:
print("find close_all_alert_btns fail")
if close_all_alert_btns is not None:
if show_debug_message:
print('all alert count:', len(close_all_alert_btns))
for alert_btn in close_all_alert_btns:
is_visible = False
try:
if alert_btn.is_enabled() and alert_btn.is_displayed():
is_visible = True
except Exception as exc:
pass
if is_visible:
try:
alert_btn.click()
except Exception as exc:
print("try to click alert_btn fail, force click by js.")
try:
driver.execute_script("arguments[0].click();", alert_btn)
except Exception as exc:
pass
def kham_main(driver, url, config_dict, ocr, Captcha_Browser): def kham_main(driver, url, config_dict, ocr, Captcha_Browser):
home_url_list = ['https://kham.com.tw/' home_url_list = ['https://kham.com.tw/'
@ -8281,17 +8147,13 @@ def kham_main(driver, url, config_dict, ocr, Captcha_Browser):
if not Captcha_Browser is None: if not Captcha_Browser is None:
Captcha_Browser.Set_Domain(domain_name, captcha_url=captcha_url) Captcha_Browser.Set_Domain(domain_name, captcha_url=captcha_url)
is_confirm_dialog_popup = kham_performance_confirm_dialog_popup(driver) is_button_clicked = force_press_button(driver, By.CSS_SELECTOR,'div.ui-dialog-buttonset > button.ui-button')
if is_confirm_dialog_popup:
print("is_confirm_dialog_popup! auto press confirm...")
kham_performance(driver, config_dict, ocr, Captcha_Browser, model_name) kham_performance(driver, config_dict, ocr, Captcha_Browser, model_name)
#https://kham.com.tw/application/UTK02/UTK0205_.aspx?PERFORMANCE_ID=XXX&GROUP_ID=30&PERFORMANCE_PRICE_AREA_ID=XXX #https://kham.com.tw/application/UTK02/UTK0205_.aspx?PERFORMANCE_ID=XXX&GROUP_ID=30&PERFORMANCE_PRICE_AREA_ID=XXX
if '.aspx?performance_id=' in url.lower() and 'performance_price_area_id=' in url.lower(): if '.aspx?performance_id=' in url.lower() and 'performance_price_area_id=' in url.lower():
is_confirm_dialog_popup = kham_performance_confirm_dialog_popup(driver) is_button_clicked = force_press_button(driver, By.CSS_SELECTOR,'div.ui-dialog-buttonset > button.ui-button')
if is_confirm_dialog_popup:
print("is_confirm_dialog_popup! auto press confirm...")
if config_dict["ocr_captcha"]["enable"]: if config_dict["ocr_captcha"]["enable"]:
domain_name = url.split('/')[2] domain_name = url.split('/')[2]
model_name = url.split('/')[5] model_name = url.split('/')[5]

View File

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

View File

@ -24,7 +24,7 @@ import time
import threading import threading
import subprocess import subprocess
CONST_APP_VERSION = u"MaxBot (2023.03.12)" CONST_APP_VERSION = u"MaxBot (2023.03.13)"
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"
@ -2340,6 +2340,8 @@ def update_maxbot_runtime_status():
global lbl_maxbot_last_url_data global lbl_maxbot_last_url_data
last_url = read_last_url_from_file() last_url = read_last_url_from_file()
if len(last_url) > 60:
last_url=last_url[:60]+"..."
lbl_maxbot_last_url_data.config(text=last_url) lbl_maxbot_last_url_data.config(text=last_url)
except Exception as exc: except Exception as exc:
pass pass