-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto.py
More file actions
321 lines (290 loc) · 10.4 KB
/
auto.py
File metadata and controls
321 lines (290 loc) · 10.4 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
import os
import time
import pyautogui
import subprocess
import customtkinter
from pyautogui import *
from pynput import *
from pynput.keyboard import *
from tkinter.ttk import *
from time import strftime
from selenium import *
from datetime import datetime
from selenium import webdriver
from selenium.common import NoSuchElementException, ElementNotInteractableException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import ActionChains
from selenium.webdriver import Keys
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
import undetected_chromedriver as uc
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.select import Select
from zenrows import ZenRowsClient
from selenium.webdriver.chrome.service import Service
from googleapiclient.discovery import build
from google.oauth2 import service_account
from googleapiclient.http import MediaFileUpload
import datetime as dt
from tkinter import *
from tkcalendar import *
now = datetime.now()
Num = str(now.strftime("%b") + "_" + now.strftime("%d"))
o = uc.ChromeOptions()
SERVICE_ACCOUNT_FILE = 'argos_cred.json'
FOLDER_ID = '1Ph6YRWYl_KJ9tCMAj19FgFj1aJH499bF'
credentials = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE
)
drive_service = build('drive', 'v3', credentials=credentials)
old_name = 'C:/Users/Zach/Documents/VSLeads.csv'
new_name = 'C:/Users/Zach/Documents/FullArgos_' + Num + '.csv'
old_lead = 'C:/Users/Zach/Downloads/leads.csv'
new_lead = 'C:/Users/Zach/Downloads/ArgosLeads_' + Num + '.csv'
f = ('Times', 20)
class App(customtkinter.CTk):
WIDTH = 350
HEIGHT = 500
customtkinter.set_appearance_mode("dark")
customtkinter.set_default_color_theme("blue")
def __init__(self):
super().__init__()
self.title("AutoUpDown")
self.geometry(f"{self.WIDTH}x{self.HEIGHT}")
self.grid_columnconfigure(1, weight=1)
self.grid_rowconfigure(0, weight=1)
self.frame = customtkinter.CTkFrame(master=self)
self.frame.grid(row=0, column=1, sticky="nsew", padx=10, pady=10)
self.frame.grid_columnconfigure(0, weight=1)
self.frame.grid_columnconfigure(1, weight=1)
self.frame.grid_columnconfigure(5, weight=1)
frame_time = customtkinter.CTkFrame(master=self,
width=280,
height=300,
corner_radius=10)
frame_time.place(relx=0.5, rely=0.46, anchor=CENTER)
global cal, min_sb, sec_hour, sec, msg_display
cal = Calendar(
frame_time,
selectmode="day",
)
cal.place(relx=0.5, rely=0.32, anchor=CENTER)
min_sb = Spinbox(
frame_time,
from_=0,
to=23,
wrap=True,
width=2,
state="readonly",
font=f,
justify=CENTER
)
sec_hour = Spinbox(
frame_time,
from_=0,
to=59,
wrap=True,
state="readonly",
font=f,
width=2,
justify=CENTER
)
sec = Spinbox(
frame_time,
from_=0,
to=59,
wrap=True,
state="readonly",
width=2,
font=f,
justify=CENTER
)
min_sb.place(relx=0.26, rely=0.65)
sec_hour.place(relx=0.44, rely=0.65)
sec.place(relx=0.62, rely=0.65)
msg = Label(
frame_time,
text="H : M : S",
font=("Times", 12),
background="#2b2b2b",
foreground="white"
)
msg.place(relx=0.5, rely=0.82, anchor=CENTER)
msg_display = Label(
frame_time,
text="",
background="#2b2b2b",
foreground="white"
)
msg_display.place(relx=0.5, rely=0.9, anchor=CENTER)
def my_time():
global time_string
time_string = strftime('%H:%M:%S %p-%a, %m/%d/%Y') # time format
l.config(text=time_string, background="#2b2b2b", foreground="white")
l.after(1000, my_time) # time delay of 1000 milliseconds
my_font = ('times', 16, 'bold') # display size and style
l = Label(self, font=my_font)
l.place(x=35, y=50)
my_time()
# title section
self.title = customtkinter.CTkLabel(
master=self.frame, text="Current Time", font=("Times", -25),
)
self.title.grid(row=1, column=1, pady=10)
# button section
self.start_auto_button = customtkinter.CTkButton(
master=self.frame,
text="Start",
fg_color=("black"),
font=("Roboto Medium", -16),
command=self.start_action,
)
self.start_auto_button.place(x=95, y=370)
self.stop_auto_button = customtkinter.CTkButton(
master=self.frame,
text="Stop",
fg_color=("black"),
font=("Roboto Medium", -16),
state="disabled",
command=self.stop_action,
)
self.stop_auto_button.place(x=95, y=405)
self.exit_auto_button = customtkinter.CTkButton(
master=self.frame,
text="Exit",
fg_color=("red"),
font=("Roboto Medium", -16),
command=self.on_close,
)
self.exit_auto_button.place(x=95, y=440)
def start_action(self):
date = cal.get_date()
m = min_sb.get()
h = sec_hour.get()
s = sec.get()
t = f"Automation will start at {m}:{h}:{s}, {date}."
msg_display.config(text=t)
self.start_auto_button.configure(state="disabled")
self.stop_auto_button.configure(state="enable")
if os.path.isfile(new_name):
os.remove(new_name)
if os.path.isfile(old_name):
os.remove(old_name)
if os.path.isfile(new_lead):
os.remove(new_lead)
if os.path.isfile(old_lead):
os.remove(old_lead)
print("This is test!")
def section1():
os.startfile("C:\VS Automation Suite\VSAutomationSuite.exe")
time.sleep(20)
keyDown("Alt")
keyUp("Alt")
keyDown("Tab")
keyUp("Tab")
keyDown("Tab")
keyUp("Tab")
keyDown("Tab")
keyUp("Tab")
keyDown("Tab")
keyUp("Tab")
keyDown("Enter")
keyUp("Enter")
time.sleep(15)
keyDown("Tab")
keyUp("Tab")
keyDown("Tab")
keyUp("Tab")
keyDown("Enter")
keyUp("Enter")
os.rename(old_name, new_name)
time.sleep(1)
os.system("taskkill /f /im VSAutomationSuite.exe")
section1()
driver = uc.Chrome(options=o)
def section2():
if os.path.isfile(new_name):
time.sleep(0.5)
driver.maximize_window()
driver.get("http://ushtoolkit.com/login?next=%2Fhome")
time.sleep(0.5)
mailaddress = driver.find_element(By.ID, "email")
loginpwd = driver.find_element(By.ID, "password")
time.sleep(4)
mailaddress.send_keys("admin@admin")
loginpwd.send_keys("123@dmin123")
loginpwd.send_keys(Keys.ENTER)
time.sleep(1)
driver.get("http://ushtoolkit.com/home")
time.sleep(0.5)
s = driver.find_element(By.XPATH, "//input[@type='file']")
s.send_keys(
r"C:\Users\Zack\Documents\FullArgos_" + Num + r".csv")
time.sleep(1)
pullnumber = driver.find_element(
By.XPATH, "/html/body/div/div/div[2]/div[2]/form/input")
pullnumber.send_keys(3000)
pullnumber.send_keys(Keys.ENTER)
else:
section1()
section2()
time.sleep(1)
os.rename(old_lead, new_lead)
driver.close()
section2()
results = drive_service.files().list(
q=f"name='{Num}' and mimeType='application/vnd.google-apps.folder' and trashed=false",
fields="files(id)").execute()
items = results.get('files', [])
# Delete the folder(s) with the specified name
for item in items:
folder_id = item['id']
drive_service.files().delete(fileId=folder_id).execute()
print(f"Deleted folder: {folder_id}")
# drive_service.files().delete(filename = Num).exvute
folder_metadata = {
'name': Num,
'parents': [FOLDER_ID],
'mimeType': 'application/vnd.google-apps.folder'
}
# Create the folder in Google Drive
created_folder = drive_service.files().create(
body=folder_metadata,
fields='id'
).execute()
CREATED_FOLDER_ID = created_folder.get("id")
# Change this to the file you want to upload
file_name = 'ArgosLeads_' + Num + '.csv'
# # Change this to the actual file path
file_path = 'C:/Users/Zach/Downloads/' + file_name
# Create a file metadata with the desired folder ID
file_metadata = {
'name': file_name,
'parents': [CREATED_FOLDER_ID]
}
# Upload the file to Google Drive
media_body = MediaFileUpload(file_path, resumable=True)
file = drive_service.files().create(
body=file_metadata,
media_body=media_body,
fields='id'
).execute()
self.start_auto_button.configure(state="enable")
self.stop_auto_button.configure(state="disable")
def stop_action(self):
self.start_auto_button.configure(state="enable")
self.stop_auto_button.configure(state="disabled")
def on_close(self):
self.destroy()
def start(self):
self.mainloop()
if __name__ == "__main__":
app = App()
app.attributes("-topmost", True)
app.resizable(False, False)
app.update()
app.start()