remove some not necessary codes.

master
Max 2023-08-03 14:26:30 +08:00 committed by GitHub
parent 264bb34137
commit 5c690d03a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 51 additions and 67 deletions

View File

@ -52,7 +52,6 @@ except Exception as exc:
import webbrowser
import argparse
import itertools
import chromedriver_autoinstaller
CONST_APP_VERSION = "MaxBot (2023.07.23)"
@ -85,7 +84,6 @@ CONST_OCR_CAPTCH_IMAGE_SOURCE_NON_BROWSER = "NonBrowser"
CONST_OCR_CAPTCH_IMAGE_SOURCE_CANVAS = "canvas"
CONST_WEBDRIVER_TYPE_SELENIUM = "selenium"
#CONST_WEBDRIVER_TYPE_STEALTH = "stealth"
CONST_WEBDRIVER_TYPE_UC = "undetected_chromedriver"
CONST_AUTO_RELOAD_RANDOM_DELAY_MAX_SECOND = 4
@ -510,7 +508,6 @@ def clean_uc_exe_cache():
return is_cache_exist
def load_chromdriver_uc(config_dict):
import undetected_chromedriver as uc
@ -648,22 +645,19 @@ def get_driver_by_config(config_dict):
# read config.
homepage = config_dict["homepage"]
browser = config_dict["browser"]
driver_type = config_dict["webdriver_type"]
# output config:
print("maxbot app version:", CONST_APP_VERSION)
print("python version:", platform.python_version())
print("platform:", platform.platform())
print("homepage:", homepage)
print("browser:", browser)
print("browser:", config_dict["browser"])
print("ticket_number:", str(config_dict["ticket_number"]))
print(config_dict["tixcraft"])
print("==[advanced config]==")
print(config_dict["advanced"])
print("webdriver_type:", driver_type)
print("webdriver_type:", config_dict["webdriver_type"])
# entry point
if homepage is None:
@ -675,10 +669,10 @@ def get_driver_by_config(config_dict):
webdriver_path = os.path.join(Root_Dir, "webdriver")
print("platform.system().lower():", platform.system().lower())
if browser in ["chrome","brave"]:
if config_dict["browser"] in ["chrome","brave"]:
# method 6: Selenium Stealth
if driver_type != CONST_WEBDRIVER_TYPE_UC:
driver = load_chromdriver_normal(config_dict, driver_type)
if config_dict["webdriver_type"] != CONST_WEBDRIVER_TYPE_UC:
driver = load_chromdriver_normal(config_dict, config_dict["webdriver_type"])
else:
# method 5: uc
# multiprocessing not work bug.
@ -688,7 +682,7 @@ def get_driver_by_config(config_dict):
freeze_support()
driver = load_chromdriver_uc(config_dict)
if browser == "firefox":
if config_dict["browser"] == "firefox":
# default os is linux/mac
# download url: https://github.com/mozilla/geckodriver/releases
chromedriver_path = os.path.join(webdriver_path,"geckodriver")
@ -727,7 +721,7 @@ def get_driver_by_config(config_dict):
else:
print(exc)
if browser == "edge":
if config_dict["browser"] == "edge":
# default os is linux/mac
# download url: https://developer.microsoft.com/zh-tw/microsoft-edge/tools/webdriver/
chromedriver_path = os.path.join(webdriver_path,"msedgedriver")
@ -748,7 +742,7 @@ def get_driver_by_config(config_dict):
left_part = error_message.split("Stacktrace:")[0]
print(left_part)
if browser == "safari":
if config_dict["browser"] == "safari":
driver = None
try:
driver = webdriver.Safari()
@ -11079,20 +11073,11 @@ def main(args):
while True:
time.sleep(0.05)
is_alert_popup = False
# pass if driver not loaded.
if driver is None:
print("web driver not accessible!")
break
#is_alert_popup = check_pop_alert(driver)
#MUST "do nothing: if alert popup.
#print("is_alert_popup:", is_alert_popup)
if is_alert_popup:
continue
url, is_quit_bot = get_current_url(driver)
if is_quit_bot:
break
@ -11103,9 +11088,6 @@ def main(args):
if len(url) == 0:
continue
# 說明:輸出目前網址,覺得吵的話,請註解掉這行。
#print("url:", url)
if len(url) > 0 :
if url != last_url:
print(url)
@ -11179,7 +11161,7 @@ def main(args):
def cli():
parser = argparse.ArgumentParser(
description="resize image to new width")
description="MaxBot Aggument Parser")
parser.add_argument("--input",
help="config file path",
@ -11217,22 +11199,14 @@ def cli():
parser.add_argument("--browser",
help="overwrite browser setting",
default='',
choices=['chrome','firefox','edge','safari'],
choices=['chrome','firefox','edge','safari','brave'],
type=str)
args = parser.parse_args()
main(args)
if __name__ == "__main__":
CONST_MODE_GUI = 0
CONST_MODE_CLI = 1
mode = CONST_MODE_GUI
#mode = CONST_MODE_CLI
if mode == CONST_MODE_GUI:
cli()
else:
#for test kktix infer answer.
def test_captcha_model():
#for test kktix answer.
captcha_text_div_text = u"請回答下列問題,請在下方空格輸入DELIGHT請以半形輸入法作答大小寫需要一模一樣"
#captcha_text_div_text = u"請在下方空白處輸入引號內文字「abc」"
#captcha_text_div_text = u"請在下方空白處輸入引號內文字「0118eveconcert」請以半形小寫作答。"
@ -11265,3 +11239,13 @@ if __name__ == "__main__":
image_bytes = f.read()
res = ocr.classification(image_bytes)
print(res)
if __name__ == "__main__":
debug_captcha_model_flag = False # online mode
# for debug purpose.
#debug_captcha_model_flag = True
if not debug_captcha_model_flag:
cli()
else:
test_captcha_model()