-
Notifications
You must be signed in to change notification settings - Fork 0
/
leave.py
158 lines (101 loc) · 5.01 KB
/
leave.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
145
146
147
148
149
150
151
152
153
154
155
156
157
# Dont run this, run leave_applier.py
# Run this only if want to run without GUI of firefox opening
# This is strictly terminal based
# PLEASE LOOK AT LINE 129 FOR MOR REFERENCE!!!
# No threads have been put to sleep (pretty quick as well)
# Script will now close any UMS pop-ups automatically
# Stability has been added (some .sleep exist)
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
import time
import getpass
GREEN = "\033[92m"
RESET = "\033[0m"
def get_creds():
username = input("Username-> ")
password = getpass.getpass("Password-> ")
print()
print("which type?")
print("'1' for night leave")
print("'2' for day leave")
print("'3' for day leave (extended)")
print("'4' for night leave (extended)")
num = input("Enter digit only-> ")
print()
stay_adress = input("Stay Address-> ")
mobile_number = input("Guardian mobile number-> ")
leave_reason = input("Leave reason-> ")
date1 = input("Date of leaving-> ")
time1 = input("Time of leaving (format ex: 7:45 PM)-> ")
date2 = input("Date of returning-> ")
time2 = input("Time of returning (format ex: 7:45 PM)-> ")
return username,password,stay_adress,mobile_number,leave_reason, date1, date2, time1, time2, num
def login_to_website(username, password, stay_adress, mobile_number, leave_reason, date1, date2, time1, time2, num):
options = webdriver.FirefoxOptions()
options.add_argument("-headless")
driver = webdriver.Firefox(options=options)
# driver = webdriver.Firefox()
driver.get("https://ums.lpu.in/lpuums/")
driver.find_element("name","txtU").send_keys(username)
driver.find_element("id","TxtpwdAutoId_8767").send_keys(password)
time.sleep(1)
driver.find_element("id","TxtpwdAutoId_8767").send_keys(password)
driver.find_element("id","iBtnLogins150203125").click()
# time.sleep(1)
try:
checkbox = driver.find_element("id","chkReadMessage")
confirm = driver.find_element("id","btnClose")
checkbox.click()
confirm.click()
print(f"{RED}UMS pop-up message closed{RESET}")
except:
print()
print(f"{GREEN}no pop-up message found, continuing with the script{RESET}\n")
driver.get("https://ums.lpu.in/lpuums/frmStudentHostelLeaveApplicationTermWise.aspx")
time.sleep(1)
dropdown = Select(driver.find_element("name","ctl00$cphHeading$ddlLeaveTerm"))
dropdown.select_by_index(1)
time.sleep(1)
dropdown = Select(driver.find_element("name","ctl00$cphHeading$drpLeaveType"))
dropdown.select_by_index(num)
time.sleep(1)
dropdown = Select(driver.find_element("name","ctl00$cphHeading$ddlVisitDay"))
dropdown.select_by_visible_text("Other")
time.sleep(1)
driver.find_element("id","ctl00_cphHeading_txtPlaceToVisit").send_keys(stay_adress)
time.sleep(1)
driver.find_element("id","ctl00_cphHeading_txtVisitingMobile").send_keys(mobile_number)
time.sleep(1)
driver.find_element("id","ctl00_cphHeading_txtLeaveReason").send_keys(leave_reason)
driver.find_element("id","ctl00_cphHeading_startdateRadDateTimePicker1_popupButton").click()
xpath_expression1 = f"//a[contains(text(), '{date1}')]"
xpath_expression2 = f"//a[contains(text(), '{date2}')]"
xpath_expression3 = f"//a[contains(text(), '{time1}')]"
xpath_expression4 = f"//a[contains(text(), '{time2}')]"
driver.find_element(By.XPATH, xpath_expression1).click()
#driver.find_element(By.XPATH, "//a[text()='22']").click()
time.sleep(1)
driver.find_element("id","ctl00_cphHeading_startdateRadDateTimePicker1_timePopupLink").click()
driver.find_element(By.XPATH, xpath_expression3).click()
#driver.find_element(By.XPATH, "//a[text()='7:45 PM']").click()
time.sleep(1)
driver.find_element("id","ctl00_cphHeading_enddateRadDateTimePicker2_popupButton").click()
driver.find_element(By.XPATH, xpath_expression2).click()
# driver.find_element(By.XPATH, "//a[text()='23']").click()
time.sleep(1)
driver.find_element("id","ctl00_cphHeading_enddateRadDateTimePicker2_timePopupLink").click()
driver.find_element(By.XPATH, xpath_expression4).click()
# driver.find_element(By.XPATH, "//a[text()='7:45 PM']").click()
print(f"{GREEN}Leave applied successfully{RESET}")
# UNCOMMENT THIS ONLY IF YOU ARE SURE ABOUT SUBMITTING
# THIS WILL SUBMIT, SO MAKE SURE THAT INFO ENTERED IS CORRECT
#driver.find_element("name","ctl00$cphHeading$btnSubmit").click()
driver.quit()
def main():
username, password, stay_adress, mobile_number, leave_reason, date1, date2, time1, time2, num = get_creds()
login_to_website(username, password, stay_adress, mobile_number, leave_reason, date1, date2, time1, time2, num)
if __name__ == "__main__":
main()