diff --git a/chrome_tixcraft.py b/chrome_tixcraft.py index a8bce26..7b020f0 100644 --- a/chrome_tixcraft.py +++ b/chrome_tixcraft.py @@ -425,13 +425,21 @@ def get_chrome_options(webdriver_path, config_dict): chrome_options.add_argument('--headless=new') chrome_options.add_argument("--user-agent=%s" % (USER_AGENT)) + chrome_options.add_argument("--disable-animations") + chrome_options.add_argument("--disable-blink-features=AutomationControlled") + chrome_options.add_argument("--disable-infobars") + chrome_options.add_argument("--disable-notifications") + chrome_options.add_argument("--disable-popup-blocking") + chrome_options.add_argument("--disable-print-preview") + chrome_options.add_argument("--disable-setuid-sandbox") + chrome_options.add_argument("--disable-site-isolation-trials") + chrome_options.add_argument("--disable-smooth-scrolling") + chrome_options.add_argument("--disable-sync") + chrome_options.add_argument("--no-sandbox"); chrome_options.add_argument('--disable-features=TranslateUI') chrome_options.add_argument('--disable-translate') - chrome_options.add_argument('--lang=zh-TW') chrome_options.add_argument('--disable-web-security') - chrome_options.add_argument("--no-sandbox"); - chrome_options.add_argument("--disable-popup-blocking") - chrome_options.add_argument("--disable-notifications") + chrome_options.add_argument('--lang=zh-TW') # for navigator.webdriver chrome_options.add_experimental_option("excludeSwitches", ['enable-automation']) @@ -659,13 +667,21 @@ def get_uc_options(uc, config_dict, webdriver_path): options.add_argument('--headless=new') options.add_argument("--user-agent=%s" % (USER_AGENT)) + options.add_argument("--disable-animations") + options.add_argument("--disable-blink-features=AutomationControlled") + options.add_argument("--disable-infobars") + options.add_argument("--disable-notifications") + options.add_argument("--disable-popup-blocking") + options.add_argument("--disable-print-preview") + options.add_argument("--disable-setuid-sandbox") + options.add_argument("--disable-site-isolation-trials") + options.add_argument("--disable-smooth-scrolling") + options.add_argument("--disable-sync") + options.add_argument("--no-sandbox"); options.add_argument('--disable-features=TranslateUI') options.add_argument('--disable-translate') - options.add_argument('--lang=zh-TW') options.add_argument('--disable-web-security') - options.add_argument("--no-sandbox"); - options.add_argument("--disable-popup-blocking") - options.add_argument("--disable-notifications") + options.add_argument('--lang=zh-TW') options.add_argument("--password-store=basic") options.add_experimental_option("prefs", {"credentials_enable_service": False, "profile.password_manager_enabled": False, "translate":{"enabled": False}}) @@ -11087,12 +11103,17 @@ def ticketplus_date_auto_select(driver, config_dict): if not is_date_clicked: if not formated_area_list is None: if len(formated_area_list) == 0: + # in fact, no need reload on /activity/ page, should reload in /order/ page. try: driver.refresh() time.sleep(0.3) except Exception as exc: pass + if config_dict["advanced"]["auto_reload_page_interval"] > 0: + time.sleep(config_dict["advanced"]["auto_reload_page_interval"]) + + return is_date_clicked def ticketplus_assign_ticket_number(target_area, config_dict): diff --git a/settings.py b/settings.py index 1f1a152..53b12ce 100644 --- a/settings.py +++ b/settings.py @@ -32,6 +32,7 @@ import requests import tornado from tornado.web import Application from urllib3.exceptions import InsecureRequestWarning +from typing import Optional try: import ddddocr @@ -2921,8 +2922,31 @@ async def main_server(): print("server running on port:", CONST_SERVER_PORT) await asyncio.Event().wait() +def is_connectable(port: int, host: Optional[str] = "localhost") -> bool: + """Tries to connect to the server at port to see if it is running. + + :Args: + - port - The port to connect. + """ + socket_ = None + _is_connectable_exceptions = (socket.error, ConnectionResetError) + try: + socket_ = socket.create_connection((host, port), 1) + result = True + except _is_connectable_exceptions: + result = False + finally: + if socket_: + socket_.close() + return result + def web_server(): - asyncio.run(main_server()) + is_port_binded = is_connectable(CONST_SERVER_PORT) + #print("is_port_binded:", is_port_binded) + if not is_port_binded: + asyncio.run(main_server()) + else: + print("port:", CONST_SERVER_PORT, " is in used.") def preview_question_text_file(): if os.path.exists(CONST_MAXBOT_QUESTION_FILE):