/
gstudent.py
215 lines (168 loc) · 6.97 KB
/
gstudent.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
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
from selenium import webdriver
import time
import getpass
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import os
import csv
from datetime import datetime
import bot
import tbot
# now = datetime.now()
# current_time = now.strftime("%H:%M:%S")
# print("Current Time =", current_time)
def main(usernameInput, passwordInput, width, height, hookName, token):
# user inputs
with open('save.txt', 'w') as f:
f.write(usernameInput + ',' + passwordInput + ',' + width + ',' + height + ',' + hookName + ',' + token)
# declaring the driver
options = webdriver.ChromeOptions()
options.binary_location = "C:/Program Files/Google/Chrome/Application/chrome.exe"
chrome_driver_binary = "chromedriver.exe"
driver = webdriver.Chrome(chrome_driver_binary, options=options)
# driver = webdriver.Chrome()
driver.set_window_position(0, 0)
driver.set_window_size(width, height)
# opening the website using get()
driver.get('https://login.gitam.edu/Login.aspx')
# setting user inputs to the portal
# username
username = driver.find_element_by_id('txtusername')
username.send_keys(usernameInput)
#password
password = driver.find_element_by_id('password')
password.send_keys(passwordInput)
# clicking login button
login = driver.find_element_by_id('Submit')
login.click()
# wait time for the site to load
driver.implicitly_wait(30)
myElem = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="form1"]/div[3]/section[2]/div/div/div[1]/h5')))
# clicking and opening glearn sitye
glearn = driver.find_element_by_xpath('//*[@id="form1"]/div[4]/ul/li[1]')
glearn.click()
driver.execute_script('window.scrollTo(0, document.body.scrollHeight)')
meetings = driver.find_elements_by_xpath('//*[@id="ContentPlaceHolder1_GridViewonline"]/tbody/tr')
n = len(meetings)
print(n, type(n))
meet = []
for i in range(1, n+1):
details = [driver.find_element_by_xpath('//*[@id="ContentPlaceHolder1_GridViewonline"]/tbody/tr[' + str(i) + ']/td/a/div/h4').text,
driver.find_element_by_xpath('//*[@id="ContentPlaceHolder1_GridViewonline"]/tbody/tr[' + str(i) + ']/td/a/div/h6').text,
driver.find_element_by_xpath('//*[@id="ContentPlaceHolder1_GridViewonline"]/tbody/tr[' + str(i) + ']/td/a').get_attribute('href')]
meet.append(details)
# print(meet)
with open("meet.csv", "w", newline="") as f:
writer = csv.writer(f)
writer.writerows(meet)
bot.bot(hookName, usernameInput)
tbot.tbot(token)
#looping all the available tabs
def closeTab():
handles = driver.window_handles
for handle in handles:
#switching to the tab(handle) // here handle = (0, 1, 2, 3,....)
driver.switch_to.window(handle)
#printing the tab title
print(driver.title)
#closing the parent tab by checking the name
if driver.title == "G-Learn":
return
else:
driver.close()
#clicking the Attendance button
def Attendance():
closeTab()
repeat = driver.find_element_by_link_text('Attendance')
repeat.click()
driver.implicitly_wait(5)
#clicking the Home button
def Home():
closeTab()
repeatHome = driver.find_element_by_link_text('Home')
repeatHome.click()
driver.implicitly_wait(5)
try:
# looping through the pages in a 300s time interval // here 1 = 1s so, 300 = 300s = 5m
while 1==1:
# sleeping for 300s
print('Sleeping for 300s')
time.sleep(300)
# navigating to the attendance page
print('Clicking Attendance Page')
Attendance()
# sleeping for 300s
print('Sleeping for 300s')
time.sleep(300)
# navigating to the home page
print('Clicking Home Page')
Home()
except KeyboardInterrupt:
# click ctr + c to interrupt and exit the program
print("Thanks for using! Program is Exiting\nPress ctrl+c to exit")
#quitting the browser after the interrupt
driver.quit()
exit()
def login():
usernameInput = input('Username: ')
passwordInput = getpass.getpass(prompt='Password: ', stream=None)
print('\nScreen Resolution(Ex: 1920x1080):\nWidth: 1920, Height: 1080')
width = input('Width: ')
height = input('Height: ')
return usernameInput, passwordInput, width, height
def isBot():
print('Do you want to integrate with your discord webhook?[y, n]: ')
isBot = input()
if isBot == 'y' or isBot == 'Y':
hookName = input("Enter your webhook link: ")
else:
hookName=""
pass
return hookName
def isTBot():
print('Do you want to integrate with your Telegram Bot?[y, n]: ')
isTBot = input()
if isTBot == 'y' or isTBot == 'Y':
token = input("Enter your webhook link: ")
else:
token=""
pass
return token
if os.path.isfile('save.txt'):
with open('save.txt', 'r') as f:
loginDetails = f.read()
if loginDetails == '':
print('There are no saved settings!')
print('Please enter login details: ')
usernameInput, passwordInput, width, height = login()
hookName = isBot()
token = isTBot()
main(usernameInput, passwordInput, width, height, hookName, token)
else:
openSaved = input('Do you want to open your saved settings? [y, n]: ')
if openSaved == 'n' or openSaved == 'N':
usernameInput, passwordInput, width, height = login()
hookName = isBot()
token = isTBot()
main(usernameInput, passwordInput, width, height, hookName, token)
elif openSaved == 'y' or openSaved == 'Y':
with open('save.txt', 'r') as f:
loginDetails = f.read()
loginDetails = loginDetails.split(',')
print(loginDetails)
usernameInput = loginDetails[0]
passwordInput = loginDetails[1]
width = loginDetails[2]
height = loginDetails[3]
hookName = loginDetails[4]
token = loginDetails[5]
main(usernameInput, passwordInput, width, height, hookName, token)
else:
print('Wrong input! Please restart the program!')
exit()
else:
usernameInput, passwordInput, width, height = login()
hookName = isBot()
token = isTBot()
main(usernameInput, passwordInput, width, height, hookName, token)