From 013a4d01f3c4be2d0645e0793b2b13c1e6aec3e0 Mon Sep 17 00:00:00 2001 From: CHUN YU YAO Date: Fri, 5 Jan 2024 23:57:40 +0800 Subject: [PATCH] 2023-12-26, fix fot kktix. --- chrome_tixcraft.py | 92 ++++++++++--------- config_launcher.py | 2 +- settings.py | 2 +- text_server.py | 2 +- webdriver/Maxbot_1.0.0/data/settings.json | 2 +- .../js/kktix_registrations_reload.js | 62 ++++++++++--- webdriver/Maxbot_1.0.0/js/tixcraft_game.js | 3 +- 7 files changed, 102 insertions(+), 63 deletions(-) diff --git a/chrome_tixcraft.py b/chrome_tixcraft.py index 0fc6124..636a3bc 100644 --- a/chrome_tixcraft.py +++ b/chrome_tixcraft.py @@ -54,7 +54,7 @@ import webbrowser import chromedriver_autoinstaller -CONST_APP_VERSION = "MaxBot (2023.12.25)" +CONST_APP_VERSION = "MaxBot (2023.12.26)" CONST_MAXBOT_CONFIG_FILE = "settings.json" CONST_MAXBOT_LAST_URL_FILE = "MAXBOT_LAST_URL.txt" @@ -3595,19 +3595,19 @@ def kktix_travel_price_list(driver, config_dict, kktix_area_auto_select_mode, kk ticket_price_list = driver.find_elements(By.CSS_SELECTOR, 'div.display-table-row') except Exception as exc: ticket_price_list = None - print("find ticket-price span Exception:") + print("find ticket-price Exception:") print(exc) pass + is_dom_ready = True price_list_count = 0 if not ticket_price_list is None: price_list_count = len(ticket_price_list) if show_debug_message: print("found price count:", price_list_count) else: - print("find ticket-price span fail") - - is_travel_interrupted = False + is_dom_ready = False + print("find ticket-price fail") if price_list_count > 0: areas = [] @@ -3634,7 +3634,7 @@ def kktix_travel_price_list(driver, config_dict, kktix_area_auto_select_mode, kk row_html = row.get_attribute('innerHTML') row_text = remove_html_tags(row_html) except Exception as exc: - is_travel_interrupted = True + is_dom_ready = False if show_debug_message: print(exc) # error, exit loop @@ -3778,7 +3778,7 @@ def kktix_travel_price_list(driver, config_dict, kktix_area_auto_select_mode, kk break - if is_travel_interrupted: + if not is_dom_ready: # not sure to break or continue..., maybe break better. break else: @@ -3786,11 +3786,7 @@ def kktix_travel_price_list(driver, config_dict, kktix_area_auto_select_mode, kk print("no any price list found.") pass - # unknow issue... - if is_travel_interrupted: - pass - - return is_ticket_number_assigned, areas + return is_dom_ready, is_ticket_number_assigned, areas def kktix_assign_ticket_number(driver, config_dict, kktix_area_keyword): show_debug_message = True # debug. @@ -3804,18 +3800,20 @@ def kktix_assign_ticket_number(driver, config_dict, kktix_area_keyword): is_ticket_number_assigned = False matched_blocks = None - is_ticket_number_assigned, matched_blocks = kktix_travel_price_list(driver, config_dict, auto_select_mode, kktix_area_keyword) + is_dom_ready = True + is_dom_ready, is_ticket_number_assigned, matched_blocks = kktix_travel_price_list(driver, config_dict, auto_select_mode, kktix_area_keyword) target_area = None - if not is_ticket_number_assigned: - target_area = get_target_item_from_matched_list(matched_blocks, auto_select_mode) - is_need_refresh = False - 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 is_dom_ready: + if not is_ticket_number_assigned: + 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: current_ticket_number = "" @@ -3849,7 +3847,7 @@ def kktix_assign_ticket_number(driver, config_dict, kktix_area_keyword): # already assigned. is_ticket_number_assigned = True - return is_ticket_number_assigned, is_need_refresh + return is_dom_ready, is_ticket_number_assigned, is_need_refresh def kktix_get_web_datetime(registrationsNewApp_div): show_debug_message = True # debug. @@ -4548,6 +4546,7 @@ def kktix_reg_new_main(driver, config_dict, fail_list, captcha_sound_played, is_ # part 2: assign ticket number is_ticket_number_assigned = False if not registrationsNewApp_div is None: + is_dom_ready = True is_need_refresh = False if len(area_keyword) > 0: @@ -4561,7 +4560,11 @@ def kktix_reg_new_main(driver, config_dict, fail_list, captcha_sound_played, is_ is_need_refresh_final = True for area_keyword_item in area_keyword_array: - is_ticket_number_assigned, is_need_refresh_tmp = kktix_assign_ticket_number(driver, config_dict, area_keyword_item) + is_dom_ready, is_ticket_number_assigned, is_need_refresh_tmp = kktix_assign_ticket_number(driver, config_dict, area_keyword_item) + + if not is_dom_ready: + # page redirecting. + break # one of keywords not need to refresh, final is not refresh. if not is_need_refresh_tmp: @@ -4577,29 +4580,30 @@ def kktix_reg_new_main(driver, config_dict, fail_list, captcha_sound_played, is_ is_need_refresh = is_need_refresh_final else: # empty keyword, match all. - is_ticket_number_assigned, is_need_refresh = kktix_assign_ticket_number(driver, config_dict, "") + is_dom_ready, is_ticket_number_assigned, is_need_refresh = kktix_assign_ticket_number(driver, config_dict, "") - # part 3: captcha - if is_ticket_number_assigned: - fail_list, captcha_sound_played, is_question_popup = kktix_reg_captcha(driver, config_dict, fail_list, captcha_sound_played, is_finish_checkbox_click, registrationsNewApp_div) - if not is_question_popup: - # no captcha text popup, goto next page. - control_text = get_kktix_control_label_text(driver) - if show_debug_message: - print("control_text:", control_text) - if len(control_text) == 0: - click_ret = kktix_press_next_button(driver) - else: - if is_need_refresh: - try: - print("no match any price, start to refresh page...") - driver.refresh() - except Exception as exc: - #print("refresh fail") - pass + if is_dom_ready: + # part 3: captcha + if is_ticket_number_assigned: + fail_list, captcha_sound_played, is_question_popup = kktix_reg_captcha(driver, config_dict, fail_list, captcha_sound_played, is_finish_checkbox_click, registrationsNewApp_div) + if not is_question_popup: + # no captcha text popup, goto next page. + control_text = get_kktix_control_label_text(driver) + if show_debug_message: + print("control_text:", control_text) + if len(control_text) == 0: + click_ret = kktix_press_next_button(driver) + else: + if is_need_refresh: + try: + print("no match any price, start to refresh page...") + driver.refresh() + except Exception as exc: + #print("refresh fail") + pass - if config_dict["advanced"]["auto_reload_random_delay"]: - time.sleep(random.randint(0,CONST_AUTO_RELOAD_RANDOM_DELAY_MAX_SECOND)) + if config_dict["advanced"]["auto_reload_random_delay"]: + time.sleep(random.randint(0,CONST_AUTO_RELOAD_RANDOM_DELAY_MAX_SECOND)) return fail_list, captcha_sound_played diff --git a/config_launcher.py b/config_launcher.py index 03a1b24..372f564 100644 --- a/config_launcher.py +++ b/config_launcher.py @@ -22,7 +22,7 @@ import sys import threading import webbrowser -CONST_APP_VERSION = "MaxBot (2023.12.25)" +CONST_APP_VERSION = "MaxBot (2023.12.26)" CONST_MAXBOT_LAUNCHER_FILE = "config_launcher.json" CONST_MAXBOT_CONFIG_FILE = "settings.json" diff --git a/settings.py b/settings.py index 7937e9c..a657c7e 100644 --- a/settings.py +++ b/settings.py @@ -34,7 +34,7 @@ import ssl ssl._create_default_https_context = ssl._create_unverified_context -CONST_APP_VERSION = "MaxBot (2023.12.25)" +CONST_APP_VERSION = "MaxBot (2023.12.26)" CONST_MAXBOT_CONFIG_FILE = "settings.json" CONST_MAXBOT_LAST_URL_FILE = "MAXBOT_LAST_URL.txt" diff --git a/text_server.py b/text_server.py index eed9a33..544e68d 100644 --- a/text_server.py +++ b/text_server.py @@ -27,7 +27,7 @@ import pyperclip import tornado from tornado.web import Application -CONST_APP_VERSION = "MaxBot (2023.12.25)" +CONST_APP_VERSION = "MaxBot (2023.12.26)" CONST_MAXBOT_QUESTION_FILE = "MAXBOT_QUESTION.txt" diff --git a/webdriver/Maxbot_1.0.0/data/settings.json b/webdriver/Maxbot_1.0.0/data/settings.json index ad94138..cd01bb7 100644 --- a/webdriver/Maxbot_1.0.0/data/settings.json +++ b/webdriver/Maxbot_1.0.0/data/settings.json @@ -1 +1 @@ -{"homepage": "https://tixcraft.com", "browser": "chrome", "language": "\u7e41\u9ad4\u4e2d\u6587", "ticket_number": 2, "ocr_captcha": {"enable": true, "beta": true, "force_submit": true, "image_source": "canvas"}, "webdriver_type": "undetected_chromedriver", "kktix": {"auto_press_next_step_button": true, "auto_fill_ticket_number": true}, "tixcraft": {"date_auto_select": {"enable": true, "date_keyword": "", "mode": "random"}, "pass_date_is_sold_out": true, "auto_reload_coming_soon_page": true}, "area_auto_select": {"enable": true, "mode": "random", "area_keyword": ""}, "keyword_exclude": "\"\u8f2a\u6905\",\"\u8eab\u969c\",\"\u8eab\u5fc3 \u969c\u7919\",\"Restricted View\",\"\u71c8\u67f1\u906e\u853d\",\"\u8996\u7dda\u4e0d\u5b8c\u6574\"", "advanced": {"play_captcha_sound": {"enable": true, "filename": "ding-dong.wav"}, "tixcraft_sid": "", "ibonqware": "", "facebook_account": "", "kktix_account": "", "fami_account": "", "cityline_account": "", "urbtix_account": "", "hkticketing_account": "", "kham_account": "", "ticket_account": "", "udn_account": "", "ticketplus_account": "", "facebook_password": "", "kktix_password": "", "fami_password": "", "urbtix_password": "", "cityline_password": "", "hkticketing_password": "", "kham_password": "", "ticket_password": "", "udn_password": "", "ticketplus_password": "", "adblock_plus_enable": false, "disable_adjacent_seat": false, "hide_some_image": true, "block_facebook_network": false, "headless": false, "verbose": false, "auto_guess_options": true, "user_guess_string": "", "online_dictionary_url": "", "auto_reload_page_interval": 1.0, "auto_reload_random_delay": false, "proxy_server_port": ""}} \ No newline at end of file +{"homepage": "https://kktix.com", "browser": "chrome", "language": "\u7e41\u9ad4\u4e2d\u6587", "ticket_number": 2, "ocr_captcha": {"enable": true, "beta": true, "force_submit": true, "image_source": "canvas"}, "webdriver_type": "undetected_chromedriver", "kktix": {"auto_press_next_step_button": true, "auto_fill_ticket_number": true}, "tixcraft": {"date_auto_select": {"enable": true, "date_keyword": "", "mode": "random"}, "pass_date_is_sold_out": true, "auto_reload_coming_soon_page": true}, "area_auto_select": {"enable": true, "mode": "random", "area_keyword": ""}, "keyword_exclude": "\"\u8f2a\u6905\",\"\u8eab\u969c\",\"\u8eab\u5fc3 \u969c\u7919\",\"Restricted View\",\"\u71c8\u67f1\u906e\u853d\",\"\u8996\u7dda\u4e0d\u5b8c\u6574\"", "advanced": {"play_captcha_sound": {"enable": true, "filename": "ding-dong.wav"}, "tixcraft_sid": "", "ibonqware": "", "facebook_account": "", "kktix_account": "weng.32002@gmail.com", "fami_account": "", "cityline_account": "", "urbtix_account": "", "hkticketing_account": "", "kham_account": "", "ticket_account": "", "udn_account": "", "ticketplus_account": "", "facebook_password": "", "kktix_password": "eXlme2omX3Nq", "fami_password": "", "urbtix_password": "", "cityline_password": "", "hkticketing_password": "", "kham_password": "", "ticket_password": "", "udn_password": "", "ticketplus_password": "", "adblock_plus_enable": false, "disable_adjacent_seat": false, "hide_some_image": true, "block_facebook_network": false, "headless": false, "verbose": true, "auto_guess_options": true, "user_guess_string": "", "online_dictionary_url": "", "auto_reload_page_interval": 1.0, "auto_reload_random_delay": false, "proxy_server_port": ""}} \ No newline at end of file diff --git a/webdriver/Maxbot_1.0.0/js/kktix_registrations_reload.js b/webdriver/Maxbot_1.0.0/js/kktix_registrations_reload.js index 0d003eb..5ebc58c 100644 --- a/webdriver/Maxbot_1.0.0/js/kktix_registrations_reload.js +++ b/webdriver/Maxbot_1.0.0/js/kktix_registrations_reload.js @@ -1,12 +1,55 @@ const storage = chrome.storage.local; -$("footer").remove(); +var myInterval = null; -setTimeout(function () { - $("div.banner-wrapper").remove(); - $("div.ticket-img-wrapper").remove(); -}, 300); +function clean_sold_out_row(data) +{ + console.log("clean_sold_out_row"); + let match_target = false; + for (var key in data.inventory.ticketInventory) { + if(data.inventory.ticketInventory[key]) { + //console.log("key:"+key); + if($("#ticket_"+key).length) { + match_target = true; + break; + } + + } + } + //console.log("match_target:"+match_target); + if(match_target) { + $("footer").remove(); + $("div.banner-wrapper").remove(); + $("div.ticket-img-wrapper").remove(); + + $("span.ticket-quantity[ng-if=\"!purchasableAndSelectable\"]").each(function () + { + $(this).parent().parent().parent().remove(); + }); + clearInterval(myInterval); + } +} + +function kktix_ajax_done(data) +{ + let reload=false; + console.log(data.inventory.registerStatus); + // IN_STOCK + if(data.inventory.registerStatus=='OUT_OF_STOCK') {reload=true;} + if(data.inventory.registerStatus=='COMING_SOON') {reload=true;} + if(data.inventory.registerStatus=='SOLD_OUT') {reload=true;} + //console.log(reload); + if(reload) { + location.reload(); + } else { + $(function() { + myInterval = setInterval(() => { + clean_sold_out_row(data); + }, 200); + }); + } +} function kktix_event_status_check() { @@ -21,14 +64,7 @@ function kktix_event_status_check() }) .done(function(data) { //alert( "second success" ); - let reload=false; - console.log(data.inventory.registerStatus); - // IN_STOCK - if(data.inventory.registerStatus=='OUT_OF_STOCK') {reload=true;} - if(data.inventory.registerStatus=='COMING_SOON') {reload=true;} - if(data.inventory.registerStatus=='SOLD_OUT') {reload=true;} - //console.log(reload); - if(reload) {location.reload();} + kktix_ajax_done(data); }) .fail(function() { //alert( "error" ); diff --git a/webdriver/Maxbot_1.0.0/js/tixcraft_game.js b/webdriver/Maxbot_1.0.0/js/tixcraft_game.js index 21cede1..d0a45fa 100644 --- a/webdriver/Maxbot_1.0.0/js/tixcraft_game.js +++ b/webdriver/Maxbot_1.0.0/js/tixcraft_game.js @@ -20,8 +20,7 @@ function date_clean() $("#gameList td:contains('"+ remove_list[i] +"')").each(function () { $(this).parent().remove(); - } - ); + }); } }