-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
144 lines (123 loc) · 4.59 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
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
import AppKit
import logging
import config
import pyautogui
import time
import webbrowser
from os import system
from datetime import datetime
from selenium import webdriver
from webdriver_manager import driver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.relative_locator import locate_with
USER = config.USER
PASS = config.PASS
pyautogui.FAILSAFE = True
def getWebDriver():
driver = webdriver.Chrome()
driver.maximize_window() # For maximizing window
driver.implicitly_wait(20)
driver.get(config.SITE_URL)
return driver
def signIn(driver, username, password):
inputUserElement = driver.find_element(By.ID, 'sso_username')
inputPassElement = driver.find_element(By.ID, 'ssopassword')
inputUserElement.send_keys(username)
inputPassElement.send_keys(password)
inputPassElement.send_keys(Keys.ENTER)
agreeButton = driver.find_element(By.XPATH,'//button[text()="I AGREE"]')
agreeButton.click()
notificationsButton = driver.find_element(By.ID, 'rejectDesktopNotifications')
time.sleep(1)
notificationsButton.click()
def checkHelpdesk(driver, previousCount, timeRemaining):
helpDeskSpan = driver.find_element(By.XPATH,'//span[text()="Helpdesk"]')
helpDeskRecord = driver.find_element(locate_with(By.CLASS_NAME, "dijitImageAccordionRowCount").to_right_of(helpDeskSpan))
time.sleep(.5)
helpDeskRecordText = "Helpdesk " + helpDeskRecord.text[8:-1]
helpDeskCount = helpDeskRecord.text[15:-1]
try:
helpDeskCount = int(helpDeskCount.replace(" ", ""))
except:
print("Page not loaded")
time.sleep(1)
driver.refresh()
time.sleep(5)
checkHelpdesk(driver, 0, timeRemaining)
print("Previous Count: ", previousCount)
print("Current Count: ", helpDeskCount)
if previousCount != helpDeskCount:
sayAlerts(helpDeskRecordText)
sayAlerts(timeRemaining)
checkForS1(driver)
return helpDeskCount
def checkForS1(driver):
try:
severity1Element = driver.find_element(By.XPATH,'//td[text()="1-Critical"]')
except:
print("No Severity 1's")
print("\n\n")
else:
sayAlerts("Severity 1 on HelpDesk")
# createTextMessage("Severity 1 on Helpesk")
def sayAlerts(text):
system("say -v 'Alex' " + "'" + text + "'")
def convertHour(hour):
howLongInt = float(hour) * 3600
return howLongInt
def formatTime(time):
time = abs(time)
hours = int(time)
minutes = (time*60) % 60
seconds = (time*3600) % 60
if hours < 1:
return "Time Remaining is: %02d minutes and %02d seconds" % (minutes, seconds)
elif hours == 1:
return "Time Remaining is: %d hour %02d minutes and %02d seconds" % (hours, minutes, seconds)
else:
return "Time Remaining is: %d hours %02d minutes and %02d seconds" % (hours, minutes, seconds)
### MAIN LOOP ###
def mainLoop():
howLong = input("How many hours?")
whatType = input("HD or Drop?").lower()
timeout = convertHour(howLong)
timeout_start = time.time()
if whatType == "drop":
while time.time() < timeout_start + timeout:
pyautogui.FAILSAFE = True
mouse_pos = pyautogui.position()
pyautogui.moveRel(0, 100, duration=1)
pyautogui.moveRel(0, -100, duration=1)
timeString = (time.time() - (timeout_start + timeout)) / 3600
sayAlerts(formatTime(timeString))
time.sleep(60)
elif whatType == "hd":
try:
driver = getWebDriver()
signIn(driver, USER, PASS)
time.sleep(5)
previousCount = 0
while time.time() < timeout_start + timeout:
timeString = (time.time() - (timeout_start + timeout)) / 3600
time.sleep(3)
previousCount = checkHelpdesk(driver, previousCount, formatTime(timeString))
pyautogui.moveRel(0, -1, duration=0.1)
pyautogui.moveRel(0, 1, duration=0.1)
time.sleep(21)
driver.refresh()
except Exception as Argument:
now = datetime.now()
date_time = now.strftime("%m/%d/%Y, %H:%M:%S")
f = open("errors.txt", "a")
f.write(date_time + "\n")
f.write(str(Argument))
f.write("\n")
f.close()
else:
print("Not an option, please type either 'HD' or 'Drop")
mainLoop()
sayAlerts("Program is over.")
if __name__ == "__main__":
mainLoop()