-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
93 lines (73 loc) · 2.59 KB
/
setup.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Web Automation Drive Setup
# Updated 09/06/2021 by Kieran Lane
# Change Log (v1.0)
# 1.0 Initial script creation
# Usage 'import webauto as wa'
# Examples
# alt_dir = 'DRIVE:\\Users\\USERNAME\\DIRECTORY'
# wa.latest_download()
# wa.latest_download(alt_dir)
# SCRIPT START
import os
import requests
import wget
from zipfile import ZipFile
from sys import platform
import shutil
# Web Driver URL/File Parts
url_release = 'LATEST_RELEASE'
if platform == 'darwin':
url_base = 'http://chromedriver.storage.googleapis.com/'
iam = 'darwin (Mac OS X)'
file_name = 'chromedriver_mac64.zip'
plain_name = 'chromedriver'
divider = '/'
elif platform == 'win32':
url_base = 'https://chromedriver.storage.googleapis.com/'
iam = 'win32 (Windows)'
file_name = 'chromedriver_win32.zip'
plain_name = 'chromedriver.exe'
divider = '\\'
file_dir = 'driver'
down_dir = 'download'
def latest_driver():
# Fetches the latest version number for download URL construction
url_latest = url_base + url_release
return requests.get(url_latest).text
def driver_unzip(file, directory):
# Unzips downloaded driver file to specified directory
# Inherits default directory from latest_download()
# Removes remaining *.zip file
with ZipFile(file, 'r') as zipObj:
zipObj.extractall(directory + divider + file_dir)
os.remove(file)
def latest_download(directory=os.getcwd()):
# Constructs download URL of latest web driver using latest_driver()
# Confirms download directory exists and initiates download
# Downloaded file unzipped using driver_unzip()
url_download = url_base + latest_driver() + '/' + file_name
# Check if supplied directory exists
if not os.path.exists(directory):
os.makedirs(directory)
# Check if /driver folder already exists, if so, delete it
if os.path.exists(directory + divider + file_dir):
shutil.rmtree(directory + divider + file_dir)
wget.download(url_download, out=directory, bar=False)
driver_unzip(directory + divider + file_name, directory)
def driver_setup(directory=os.getcwd(), mode=''):
if mode == 'path':
return directory + divider + file_dir + divider + plain_name
if mode == 'root':
root = directory + divider + down_dir
if not os.path.exists(root):
os.mkdir(root)
return root
if os.path.exists(directory + divider + file_dir):
return True
else:
return False
def what_am_i(returntype='fullos'):
if returntype == 'fullos':
return iam
if returntype == 'divider':
return divider