Skip to content

Commit 8a32b11

Browse files
committed
Add auto update driver
Signed-off-by: GarfieldGod <1351763110@qq.com>
1 parent 43da2f2 commit 8a32b11

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

src/core/auto_clock.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
from selenium.webdriver.support.ui import WebDriverWait
1010
from selenium.webdriver.support import expected_conditions as EC
1111

12+
from src.utils.const import Key, AppPath
1213
from src.utils.log import Log
1314
from src.core.clock import clock
1415
from src.core.login import login
1516
from src.core.captcha import captcha, Selectors
17+
from src.utils.utils import Utils
18+
1619

1720
@dataclass
1821
class Config:
@@ -25,6 +28,7 @@ class Config:
2528
wait_time: int = 2
2629
always_retry: bool = False
2730
show_web_page: bool = True
31+
auto_update_driver: bool = True
2832

2933
class AutoClock:
3034
def __init__(self, config: Config):
@@ -37,12 +41,35 @@ def __init__(self, config: Config):
3741
self.remote_url = config.remote_url
3842
self.always_retry = config.always_retry
3943
self.show_web_page = config.show_web_page
44+
self.auto_update_driver = config.auto_update_driver
4045
self.driver = None
4146
try:
4247
self.driver = self.create_driver()
4348
except Exception as e:
4449
Log.error(f"Create driver error: {e}")
45-
raise Exception(f"Failed to create WebDriver: {e}")
50+
51+
if 'version' in str(e):
52+
try:
53+
if not self.auto_update_driver:
54+
raise Exception("Edge version not support, need to redownload driver.")
55+
56+
ok, driver_path = Utils.download_edge_web_driver()
57+
if not ok:
58+
raise Exception("Redownload Edge web driver error.")
59+
60+
self.driver_path = driver_path
61+
self.driver = self.create_driver()
62+
63+
if self.driver is not None:
64+
data = Utils.read_dict_from_json(AppPath.DataJson)
65+
data[Key.DriverPath] = self.driver_path
66+
Utils.write_dict_to_file(AppPath.DataJson, data)
67+
68+
except Exception as e:
69+
Log.error(f"Redownload and Create driver error: {e}")
70+
raise Exception(f"Failed to create WebDriver: {e}")
71+
else:
72+
raise Exception(f"Failed to create WebDriver: {e}")
4673

4774
def create_driver(self):
4875
# 创建浏览器驱动

0 commit comments

Comments
 (0)