From dc5b44dc8bee6603dff38adba96d7568f81963dc Mon Sep 17 00:00:00 2001 From: CHUN YU YAO Date: Sun, 29 Oct 2023 22:49:02 +0800 Subject: [PATCH] 2023-10-15, update fot ticketplus. --- chrome_tixcraft.py | 207 ++++++++++++++++++++++----------------------- config_launcher.py | 2 +- settings.py | 2 +- text_server.py | 2 +- 4 files changed, 106 insertions(+), 107 deletions(-) diff --git a/chrome_tixcraft.py b/chrome_tixcraft.py index 91afd42..2a7d06b 100644 --- a/chrome_tixcraft.py +++ b/chrome_tixcraft.py @@ -55,7 +55,7 @@ import webbrowser import chromedriver_autoinstaller -CONST_APP_VERSION = "MaxBot (2023.10.14)" +CONST_APP_VERSION = "MaxBot (2023.10.15)" CONST_MAXBOT_CONFIG_FILE = "settings.json" CONST_MAXBOT_LAST_URL_FILE = "MAXBOT_LAST_URL.txt" @@ -114,8 +114,11 @@ def format_config_keyword_for_json(user_input): return user_input def remove_html_tags(text): - clean = re.compile('<.*?>') - return re.sub(clean, '', text) + ret = "" + if not text is None: + clean = re.compile('<.*?>') + ret = re.sub(clean, '', text) + return ret def sx(s1): key=18 @@ -338,7 +341,7 @@ def is_all_alpha_or_numeric(text): def get_favoriate_extension_path(webdriver_path): print("webdriver_path:", webdriver_path) extension_list = [] - extension_list.append(os.path.join(webdriver_path,"Adblock_3.19.0.0.crx")) + extension_list.append(os.path.join(webdriver_path,"Adblock_3.20.0.0.crx")) return extension_list def get_chromedriver_path(webdriver_path): @@ -1750,12 +1753,12 @@ def tixcraft_date_auto_select(driver, url, config_dict, domain_name): row_is_enabled=True try: row_text = "" + row_html = "" # check buy button. if row_is_enabled: #row_text = row.text - row_text = remove_html_tags(row.get_attribute('innerHTML')) - if row_text is None: - row_text = "" + row_html = row.get_attribute('innerHTML') + row_text = remove_html_tags(row_html) if len(row_text) > 0: if reset_row_text_if_match_keyword_exclude(config_dict, row_text): @@ -1929,12 +1932,12 @@ def ticketmaster_date_auto_select(driver, url, config_dict, domain_name): row_is_enabled=False row_text = "" + row_html = "" # check buy button. if row_is_enabled: #row_text = row.text - row_text = remove_html_tags(row.get_attribute('innerHTML')) - if row_text is None: - row_text = "" + row_html = row.get_attribute('innerHTML') + row_text = remove_html_tags(row_html) row_is_enabled=False # must contains 'See Tickets' @@ -2039,13 +2042,14 @@ def get_matched_blocks_by_keyword_item_set(config_dict, auto_select_mode, keywor matched_blocks = [] for row in formated_area_list: row_text = "" + row_html = "" try: #row_text = row.text - row_text = remove_html_tags(row.get_attribute('innerHTML')) + row_html = row.get_attribute('innerHTML') + row_text = remove_html_tags(row_html) except Exception as exc: pass - if row_text is None: - row_text = "" + if len(row_text) > 0: if reset_row_text_if_match_keyword_exclude(config_dict, row_text): row_text = "" @@ -2170,17 +2174,15 @@ def get_tixcraft_target_area(el, config_dict, area_keyword_item): pass row_text = "" + row_html = "" if row_is_enabled: try: #row_text = row.text - row_text = remove_html_tags(row.get_attribute('innerHTML')) + row_html = row.get_attribute('innerHTML') + row_text = remove_html_tags(row_html) except Exception as exc: - print("get text fail") break - if row_text is None: - row_text = "" - if len(row_text) > 0: if reset_row_text_if_match_keyword_exclude(config_dict, row_text): row_text = "" @@ -3133,17 +3135,15 @@ def get_tixcraft_ticket_select_by_keyword(driver, config_dict, area_keyword_item pass row_text = "" + row_html = "" if row_is_enabled: try: #row_text = row.text - row_text = remove_html_tags(row.get_attribute('innerHTML')) + row_html = row.get_attribute('innerHTML') + row_text = remove_html_tags(row_html) except Exception as exc: - print("get text fail") break - if row_text is None: - row_text = "" - if len(row_text) > 0: if reset_row_text_if_match_keyword_exclude(config_dict, row_text): row_text = "" @@ -3377,7 +3377,7 @@ def kktix_confirm_order_button(driver): # : 2: /events/xxx/registrations/new # : This is ONLY for case-1, because case-2 lenght >5 def kktix_events_press_next_button(driver): - is_button_clicked = force_press_button(driver, By.CSS_SELECTOR,'div.tickets a.btn-point') + is_button_clicked = force_press_button(driver, By.CSS_SELECTOR,'.tickets > a.btn-point') return is_button_clicked # : This is for case-2 next button. @@ -3530,19 +3530,15 @@ def kktix_travel_price_list(driver, config_dict, kktix_area_keyword): row_index += 1 row_text = "" + row_html = "" try: #row_text = row.text - row_text = remove_html_tags(row.get_attribute('innerHTML')) - if show_debug_message: - print("get text:", row_text, ",at row:", row_index) + row_html = row.get_attribute('innerHTML') + row_text = remove_html_tags(row_html) except Exception as exc: - row_text = "" is_travel_interrupted = True print("get text fail.") - if row_text is None: - row_text = "" - if '已售完' in row_text: row_text = "" @@ -4645,6 +4641,7 @@ def get_fami_target_area(driver, config_dict, area_keyword_item): area_html_text = "" row_text = "" + row_html = "" try: my_css_selector = "td:nth-child(1)" td_date = row.find_element(By.CSS_SELECTOR, my_css_selector) @@ -4659,14 +4656,12 @@ def get_fami_target_area(driver, config_dict, area_keyword_item): area_html_text = format_keyword_string(td_area.text) #row_text = row.text - row_text = remove_html_tags(row.get_attribute('innerHTML')) + row_html = row.get_attribute('innerHTML') + row_text = remove_html_tags(row_html) except Exception as exc: print("get row text fail") break - if row_text is None: - row_text = "" - if len(row_text) > 0: if reset_row_text_if_match_keyword_exclude(config_dict, row_text): row_text = "" @@ -4985,16 +4980,15 @@ def urbtix_date_auto_select(driver, auto_select_mode, date_keyword, auto_reload_ row_is_enabled=True if row_is_enabled: row_text = "" + row_html = "" try: #row_text = row.text - row_text = remove_html_tags(row.get_attribute('innerHTML')) + row_html = row.get_attribute('innerHTML') + row_text = remove_html_tags(row_html) except Exception as exc: print("get text fail") break - if row_text is None: - row_text = "" - if len(row_text) > 0: if show_debug_message: print("row_text:", row_text) @@ -5132,16 +5126,15 @@ def urbtix_area_auto_select(driver, config_dict, area_keyword_item): row_is_enabled=True row_text = "" + row_html = "" if row_is_enabled: try: #row_text = row.text - row_text = remove_html_tags(row.get_attribute('innerHTML')) + row_html = row.get_attribute('innerHTML') + row_text = remove_html_tags(row_html) except Exception as exc: pass - if row_text is None: - row_text = "" - if len(row_text) > 0: if reset_row_text_if_match_keyword_exclude(config_dict, row_text): row_text = "" @@ -5200,16 +5193,15 @@ def urbtix_area_auto_select(driver, config_dict, area_keyword_item): row_is_enabled=True if row_is_enabled: row_text = "" + row_html = "" try: #row_text = row.text - row_text = remove_html_tags(row.get_attribute('innerHTML')) + row_html = row.get_attribute('innerHTML') + row_text = remove_html_tags(row_html) except Exception as exc: print("get text fail") break - if row_text is None: - row_text = "" - if len(row_text) > 0: row_text = format_keyword_string(row_text) if show_debug_message: @@ -5566,16 +5558,15 @@ def cityline_date_auto_select(driver, auto_select_mode, date_keyword, auto_reloa row_is_enabled=True if row_is_enabled: row_text = "" + row_html = "" try: #row_text = row.text - row_text = remove_html_tags(row.get_attribute('innerHTML')) + row_html = row.get_attribute('innerHTML') + row_text = remove_html_tags(row_html) except Exception as exc: print("get text fail") break - if row_text is None: - row_text = "" - if len(row_text) > 0: if show_debug_message: print("row_text:", row_text) @@ -5722,16 +5713,15 @@ def cityline_area_auto_select(driver, config_dict, area_keyword_item): row_is_enabled=True if row_is_enabled: row_text = "" + row_html = "" try: #row_text = row.text - row_text = remove_html_tags(row.get_attribute('innerHTML')) + row_html = row.get_attribute('innerHTML') + row_text = remove_html_tags(row_html) except Exception as exc: print("get text fail") break - if row_text is None: - row_text = "" - if len(row_text) > 0: if reset_row_text_if_match_keyword_exclude(config_dict, row_text): row_text = "" @@ -6217,16 +6207,15 @@ def ibon_area_auto_select(driver, config_dict, area_keyword_item): row_is_enabled=True row_text = "" + row_html = "" if row_is_enabled: try: #row_text = row.text - row_text = remove_html_tags(row.get_attribute('innerHTML')) + row_html = row.get_attribute('innerHTML') + row_text = remove_html_tags(row_html) except Exception as exc: pass - if row_text is None: - row_text = "" - if '已售完' in row_text: row_is_enabled=False @@ -6332,16 +6321,15 @@ def ibon_area_auto_select(driver, config_dict, area_keyword_item): row_is_enabled=True if row_is_enabled: row_text = "" + row_html = "" try: #row_text = row.text - row_text = remove_html_tags(row.get_attribute('innerHTML')) + row_html = row.get_attribute('innerHTML') + row_text = remove_html_tags(row_html) except Exception as exc: print("get text fail") break - if row_text is None: - row_text = "" - if len(row_text) > 0: row_text = format_keyword_string(row_text) if show_debug_message: @@ -8866,16 +8854,15 @@ def hkticketing_area_auto_select(driver, config_dict, area_keyword_item): row_is_enabled=True if row_is_enabled: row_text = "" + row_html = "" try: #row_text = row.text - row_text = remove_html_tags(row.get_attribute('innerHTML')) + row_html = row.get_attribute('innerHTML') + row_text = remove_html_tags(row_html) except Exception as exc: print("get text fail") break - if row_text is None: - row_text = "" - if len(row_text) > 0: if reset_row_text_if_match_keyword_exclude(config_dict, row_text): row_text = "" @@ -9483,17 +9470,14 @@ def hkam_date_auto_select(driver, domain_name, config_dict): row_is_enabled=False row_text = "" + row_html = "" try: #row_text = row.text - row_text = remove_html_tags(row.get_attribute('innerHTML')) + row_html = row.get_attribute('innerHTML') + row_text = remove_html_tags(row_html) except Exception as exc: - if show_debug_message: - print(exc) pass - if row_text is None: - row_text="" - if len(row_text) > 0: if reset_row_text_if_match_keyword_exclude(config_dict, row_text): row_text = "" @@ -9691,16 +9675,14 @@ def kham_area_auto_select(driver, domain_name, config_dict, area_keyword_item): row_is_enabled=True if row_is_enabled: row_text = "" + row_html = "" try: #row_text = row.text - row_text = remove_html_tags(row.get_attribute('innerHTML')) + row_html = row.get_attribute('innerHTML') + row_text = remove_html_tags(row_html) except Exception as exc: - print("get text fail") break - if row_text is None: - row_text = "" - if '售完' in row_text: row_text = "" @@ -10558,17 +10540,13 @@ def ticketplus_date_auto_select(driver, config_dict): ''' row_text = "" + row_html = "" # check buy button. if row_is_enabled: - # text is failed. + # .text is failed. @_@! #row_text = row.text - row_text = remove_html_tags(row.get_attribute('innerHTML')) - #print("row_text1:", row_text) - #print("innerHTML:", row.get_attribute('innerHTML')) - #print("innerTEXT:", remove_html_tags(row.get_attribute('innerHTML'))) - - if row_text is None: - row_text = "" + row_html = row.get_attribute('innerHTML') + row_text = remove_html_tags(row_html) if len(row_text) > 0: if reset_row_text_if_match_keyword_exclude(config_dict, row_text): @@ -10781,31 +10759,42 @@ def ticketplus_order_expansion_auto_select(driver, config_dict, area_keyword_ite formated_area_list = [] # filter list. row_index = 0 + soldout_count = 0 for row in area_list: row_index += 1 row_is_enabled=True if row_is_enabled: row_text = "" + row_html = "" try: #row_text = row.text - row_text = remove_html_tags(row.get_attribute('innerHTML')) + row_html = row.get_attribute('innerHTML') + row_text = remove_html_tags(row_html) except Exception as exc: pass - if row_text is None: - row_text = "" - # for style_2 - if '剩餘 0' in row_text: - row_text = "" + if len(row_text) > 0: + if '剩餘 0' in row_text: + soldout_count += 1 + row_text = "" - if '已售完' in row_text: - row_text = "" + if len(row_text) > 0: + if '已售完' in row_text: + soldout_count += 1 + row_text = "" # for style_1 - if '剩餘:0' in row_text: - row_text = "" + if len(row_text) > 0: + if '剩餘:0' in row_text: + soldout_count += 1 + row_text = "" + + if len(row_text) > 0: + if ' soldout"' in row_html: + soldout_count += 1 + row_text = "" if len(row_text) > 0: if reset_row_text_if_match_keyword_exclude(config_dict, row_text): @@ -10816,6 +10805,13 @@ def ticketplus_order_expansion_auto_select(driver, config_dict, area_keyword_ite if row_is_enabled: formated_area_list.append(row) + + if soldout_count > 0: + if show_debug_message: + print("soldout_count:", soldout_count) + if area_list_count == soldout_count: + formated_area_list = None + is_need_refresh = True else: if show_debug_message: print("area_list_count is empty.") @@ -10842,16 +10838,14 @@ def ticketplus_order_expansion_auto_select(driver, config_dict, area_keyword_ite row_is_enabled=True if row_is_enabled: row_text = "" + row_html = "" try: #row_text = row.text - row_text = remove_html_tags(row.get_attribute('innerHTML')) + row_html = row.get_attribute('innerHTML') + row_text = remove_html_tags(row_html) except Exception as exc: - print("get text fail") break - if row_text is None: - row_text = "" - if len(row_text) > 0: row_text = format_keyword_string(row_text) if show_debug_message: @@ -10912,16 +10906,21 @@ def ticketplus_order_expansion_auto_select(driver, config_dict, area_keyword_ite if current_layout_style==1: if not target_area is None: try: - if target_area.is_enabled(): - target_area.click() + target_area.click() 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) + js = """let titleBar = document.getElementById("titleBar"); + if(titleBar!=null) {titleBar.innerHTML="";} + arguments[0].scrollIntoView(); + arguments[0].firstChild.click(); + """ + driver.execute_script(js, target_area) except Exception as exc: + #print(exc) pass is_price_assign_by_bot = False diff --git a/config_launcher.py b/config_launcher.py index 4fd028d..8567566 100644 --- a/config_launcher.py +++ b/config_launcher.py @@ -22,7 +22,7 @@ import base64 import threading import subprocess -CONST_APP_VERSION = "MaxBot (2023.10.13)" +CONST_APP_VERSION = "MaxBot (2023.10.15)" CONST_MAXBOT_LAUNCHER_FILE = "config_launcher.json" CONST_MAXBOT_CONFIG_FILE = "settings.json" diff --git a/settings.py b/settings.py index 9aba81b..e6c5405 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.10.14)" +CONST_APP_VERSION = "MaxBot (2023.10.15)" 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 3ce9274..d026e8f 100644 --- a/text_server.py +++ b/text_server.py @@ -28,7 +28,7 @@ import asyncio import tornado from tornado.web import Application -CONST_APP_VERSION = "MaxBot (2023.10.13)" +CONST_APP_VERSION = "MaxBot (2023.10.15)" CONST_MAXBOT_QUESTION_FILE = "MAXBOT_QUESTION.txt"