-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
68 lines (47 loc) · 1.83 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os.path
from readProp import readProps
import zipfile
import requests
class GetChromedriver:
"""
Contains functionality for getting the chrome driver along with element locations.
"""
recent_repo_xpath = "/html/body/div[1]/div/div[2]/div[3]/div/div[1]/section[2]/div[2]/div/div/div/div/div/div/div/div/p[3]/a/span"
win32_xpath = "/html/body/table/tbody/tr[7]/td[2]/a"
def __init__(self):
self.download_link = f"https://chromedriver.storage.googleapis.com/{readProps.ReadConfig.getNeededVersion()}/chromedriver_win32.zip"
def download_zip_file(self):
"""
Downloads zip file using requests
"""
response = requests.get(self.download_link)
downloads_dir = os.path.expanduser(readProps.ReadConfig.getDownloadPath())
with open(os.path.join(downloads_dir, readProps.ReadConfig.getZipFileName()), 'wb') as f:
f.write(response.content)
def extract_driver_from_zip(self):
"""
Extracts the chromedriver.exe from the zip file.
"""
downloads_dir = os.path.expanduser(readProps.ReadConfig.getDownloadPath())
chromedriver_zip_path = os.path.join(downloads_dir, readProps.ReadConfig.getZipFileName())
with zipfile.ZipFile(chromedriver_zip_path, 'r') as zip_ref:
zip_ref.extract("chromedriver.exe", readProps.ReadConfig.getExtractToPath())
os.remove(chromedriver_zip_path)
def delete_old_driver():
"""
Deletes the old driver.
"""
os.remove(readProps.ReadConfig.getExtractToPath() + "\chromedriver.exe")
def update_driver():
"""
Updates the driver
"""
try:
delete_old_driver()
except:
pass
updater = GetChromedriver()
updater.download_zip_file()
updater.extract_driver_from_zip()
if __name__ == "__main__":
update_driver()