allow run settings twice, add time delay for ticket-plus /activity/ page.

master
Your Name 2024-01-17 09:44:38 +08:00
parent 66d62cef21
commit 87156e5ca8
2 changed files with 54 additions and 9 deletions

View File

@ -425,13 +425,21 @@ def get_chrome_options(webdriver_path, config_dict):
chrome_options.add_argument('--headless=new') chrome_options.add_argument('--headless=new')
chrome_options.add_argument("--user-agent=%s" % (USER_AGENT)) 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-features=TranslateUI')
chrome_options.add_argument('--disable-translate') chrome_options.add_argument('--disable-translate')
chrome_options.add_argument('--lang=zh-TW')
chrome_options.add_argument('--disable-web-security') chrome_options.add_argument('--disable-web-security')
chrome_options.add_argument("--no-sandbox"); chrome_options.add_argument('--lang=zh-TW')
chrome_options.add_argument("--disable-popup-blocking")
chrome_options.add_argument("--disable-notifications")
# for navigator.webdriver # for navigator.webdriver
chrome_options.add_experimental_option("excludeSwitches", ['enable-automation']) 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('--headless=new')
options.add_argument("--user-agent=%s" % (USER_AGENT)) 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-features=TranslateUI')
options.add_argument('--disable-translate') options.add_argument('--disable-translate')
options.add_argument('--lang=zh-TW')
options.add_argument('--disable-web-security') options.add_argument('--disable-web-security')
options.add_argument("--no-sandbox"); options.add_argument('--lang=zh-TW')
options.add_argument("--disable-popup-blocking")
options.add_argument("--disable-notifications")
options.add_argument("--password-store=basic") options.add_argument("--password-store=basic")
options.add_experimental_option("prefs", {"credentials_enable_service": False, "profile.password_manager_enabled": False, "translate":{"enabled": False}}) 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 is_date_clicked:
if not formated_area_list is None: if not formated_area_list is None:
if len(formated_area_list) == 0: if len(formated_area_list) == 0:
# in fact, no need reload on /activity/ page, should reload in /order/ page.
try: try:
driver.refresh() driver.refresh()
time.sleep(0.3) time.sleep(0.3)
except Exception as exc: except Exception as exc:
pass pass
if config_dict["advanced"]["auto_reload_page_interval"] > 0:
time.sleep(config_dict["advanced"]["auto_reload_page_interval"])
return is_date_clicked return is_date_clicked
def ticketplus_assign_ticket_number(target_area, config_dict): def ticketplus_assign_ticket_number(target_area, config_dict):

View File

@ -32,6 +32,7 @@ import requests
import tornado import tornado
from tornado.web import Application from tornado.web import Application
from urllib3.exceptions import InsecureRequestWarning from urllib3.exceptions import InsecureRequestWarning
from typing import Optional
try: try:
import ddddocr import ddddocr
@ -2921,8 +2922,31 @@ async def main_server():
print("server running on port:", CONST_SERVER_PORT) print("server running on port:", CONST_SERVER_PORT)
await asyncio.Event().wait() 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(): def web_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()) asyncio.run(main_server())
else:
print("port:", CONST_SERVER_PORT, " is in used.")
def preview_question_text_file(): def preview_question_text_file():
if os.path.exists(CONST_MAXBOT_QUESTION_FILE): if os.path.exists(CONST_MAXBOT_QUESTION_FILE):