-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattend_my_classes.py
executable file
·396 lines (272 loc) · 17 KB
/
attend_my_classes.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
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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
from scripts import student_info # importing student_info for student's login credentials
from scripts import class_info # importing class_info for url of google classrooms and class timings
from scripts.time_and_date import time_now # use time_now module to get current time as par IST time-zone
from scripts.time_and_date import today_date
from selenium.common.exceptions import NoSuchElementException as NoSuchElementException # to deal with NoSuchElementException error
from selenium import webdriver # using selenium module for automation
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.action_chains import ActionChains
#from win10toast import ToastNotifier
import time # to time.sleep as some page(s) load much slower and selenium may raise NoSuchElementException error
#NoSuchElementException = selenium.common.exceptions.NoSuchElementException
class Firelord_Azula:
def __init__(self):
print('''
___ _____ __ __ __ ___
/ | /__ / / / / / / / / |
/ /| | / / / / / / / / / /| |
/ ___ | / /__ / /_/ / / /___ / ___ |
/_/ |_| /____/ \____/ /_____/ /_/ |_|
v 1.1
is
starting''',end="")
for j in range(5):
print('.',end="",flush=True)
time.sleep(0.7)
print('\n')
chrome_options = Options()
chrome_options.add_argument("--use-fake-ui-for-media-stream")
self.driver = webdriver.Chrome(options=chrome_options)
print('-----------------------------------------------------------------',end='\n')
# using webdriver to initiate our Browser
self.driver = webdriver.Browser('/path_to_webdriver')
# set attendance today to 0 at start, and checks if it is 0, if not then the object calls the attendance function for the particular subject else pass
self.xyz_attendance_today = 0
self.abc_attendance_today = 0
# to send notifications (windows 10 only)
##self.notifier = ToastNotifier()
# log file to log each and everything from initiation to end.
self.log_file = open("/attend_my_classes.log",'a+')
self.log_file.write('initiated {} {} \n'.format(time_now(),today_date()))
def login(self):
# logging in into google classroom dashboard
self.driver.get(class_info.google_classroom_login)
# finding gmail input box, clicking it and entering gmail
email = self.driver.find_element_by_xpath('//*[@id="identifierId"]')
email.click()
email.send_keys(student_info.email)
# finding next button and clicking it after entering gmail
next_button = self.driver.find_element_by_xpath('//*[@id="identifierNext"]/div/button/div[2]')
next_button.click()
self.driver.implicitly_wait(25)
# time.sleep, so as the next page loads otherwise selenium may raise NoSuchElementException error
# finding password entry, clicking it and entering password
password = self.driver.find_element_by_xpath('//*[@id="password"]/div[1]/div/div[1]/input')
password.click()
password.send_keys(student_info.password)
# finding next button and clicking it after entering password
next_button2 = self.driver.find_element_by_xpath('//*[@id="passwordNext"]/div/button/div[2]')
next_button2.click()
self.log_file.write('login {} {} \n'.format(time_now(),today_date()))
print('Logged in -- {} -- {}'.format(time_now(),today_date()),end="\n")
#time.sleep as it takes some time to load classroom page (even on fast connection :P)
time.sleep(7)
########################################################################################
# Code block for #
# attending live google meet classess #
# embedded in google classroom banner #
########################################################################################
def attend_class(self,subject,class_url,class_timing,class_ending):
# object's method to attend xyz class
class_name = subject
self.driver.get(class_url) # opening xyz classroom
try:
self.driver.implicitly_wait(25)
class_live = self.driver.find_element_by_xpath('//*[@id="yDmH0d"]/div[2]/div/div[1]/div/div[2]/div[2]/div/span/a/div').text
self.driver.get(class_live) # clicks it
# finds the mic button and click on it
try:
# ----- code for mic here ----- #
#self.driver.implicitly_wait(25)
#mic = self.driver.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div/div[4]/div[3]/div/div[2]/div/div/div[1]/div[1]/div[3]/div[1]/div/div/div/div[1]')
#self.driver.execute_script("arguments[0].click()",mic)
# // __code__here__
# // for disabling
# // __webcam__
# finds join now button and clicks it
time.sleep(10)
self.driver.implicitly_wait(25)
join_class = self.driver.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div/div[5]/div[3]/div/div/div[2]/div/div/div[2]/div/div[2]/div/div[1]/div[1]/span/span')
join_class.click()
print('Attending {} Class... -- {} -- {}'.format(subject,time_now(),today_date()))
self.log_file.write('{} class {} {} \n'.format(subject,time_now(),today_date()))
while True:
if time_now() > class_ending:
try:
no_of_people = self.driver.find_element_by_xpath('//*[@id="ow3"]/div[1]/div/div[5]/div[3]/div[6]/div[3]/div/div[2]/div[1]/span/span/div/div/span[2]')
if no_of_people.text != '':
people = int(no_of_people.text)
print(people)
if people < 10:
print('{} class is over -- {} -- {}'.format(subject,time_now(),today_date()),end='\n')
self.driver.get(class_info.google_classroom)
# notification when a class ends
##self.notifier.show_toast('English Class Ended','English class ended just now',duration=15)
self.log_file.write('{} class ended {} {} \n'.format(subject,time_now(),today_date()))
break
else:
time.sleep(1.2)
continue
else:
pass
except NoSuchElementException:
print('no such element : no_of_people')
time.sleep(5)
except NoSuchElementException:
try:
self.driver.implicitly_wait(25)
no_class = self.driver.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div[2]/div[1]').text
if no_class == 'You can\'t create a meeting yourself. Contact your system administrator for more information.':
time.sleep(300)
except NoSuchElementException:
pass
# time.sleep(25000)
# the_end = self.driver.find_element_by_xpath('//*[@id="ow3"]/div[1]/div/div[4]/div[3]/div[9]/div[2]/div[2]/div/span/span/svg')
# finds the google meet link/icon
except NoSuchElementException:
for k in range(2):
# sample notification
##self.notifier.show_toast('No English Class','there is no google meet link for english, try heading to classroom',duration=50)
time.sleep(300)
print('\n')
########################################################################################
# Code block for #
# attendance #
# in posts in google classroom #
########################################################################################
def attendance(self,subject):
if subject == 'xyz':
# this is to ensure that the bot only comments in specific posts which are meant for attendance
check_1 = 'any consistent word in attendance post'
check_2 = 'any other consistent word in attendance post'
class_link = class_info.xyz_class_url
teacher = class_info.xyz_teacher
attendance_line = 'Present Sir/Ma\'am'
elif subject == 'abc':
check_1 = 'give your presence here'
check_2 = ' '
class_link = class_info.abc_class_url
teacher = class_info.abc_teacher
attendance_line = 'Present Sir/Ma\'am'
if True:
self.driver.get(class_link)
for k in range(1,5):
for code_id in ['37','38','39']:
try:
teacher_name = self.driver.find_element_by_xpath('//*[@id="ow{}"]/div[2]/div[{}]/div[1]/div[1]/div[1]/div/div/span'.format(code_id,k)).text
except NoSuchElementException:
continue
if teacher_name == teacher:
try:
time_of_post = self.driver.find_element_by_xpath('//*[@id="ow{}"]/div[2]/div[{}]/div[1]/div[1]/div[1]/span/span[2]'.format(code_id,k)).text.upper()
if "AM" in time_of_post or "PM" in time_of_post:
post_content = self.driver.find_element_by_xpath('//*[@id="ow{}"]/div[2]/div[{}]/div[1]/div[2]/div[1]/html-blob/span'.format(code_id,k)).text.lower()
if check_1 in post_content and check_2 in post_content:
comment_box = self.driver.find_element_by_xpath('//*[@id="ow{}"]/div[2]/div[{}]/div[2]/div/div[3]/div/div[2]/div[1]'.format(code_id,k))
time.sleep(1.5)
ActionChains(self.driver).move_to_element(comment_box).click(comment_box).send_keys(attendance_line).perform()
time.sleep(1.5)
send_key = self.driver.find_element_by_xpath('//*[@id="ow{}"]/div[2]/div[{}]/div[2]/div/div[3]/div/div[2]/div[2]/div/span'.format(code_id,k))
time.sleep(2.5)
send_key.click()
if subject == 'xyz':
self.xyz_attendance_today+=1
if self.xyz_attendance_today == 1:
print('xyz Attendance marked present -- {} -- {}'.format(time_now(),today_date()),end='\n')
self.log_file.write('xyz attendance {} {} \n'.format(time_now(),today_date()))
elif subject == 'abc':
self.abc_attendance_today+=1
if self.abc_attendance_today == 1:
print('abc Attendance marked present -- {} -- {}'.format(time_now(),today_date()),end='\n')
self.log_file.write('abc attendance {} {} \n'.format(time_now(),today_date()))
except NoSuchElementException:
continue
########################################################################################
# Code block for #
# testing purposes #
# #
########################################################################################
# function to test new features
def attend_test_class(self):
inp_link = str(input('Google meet code: ')).strip()
inp_link = 'https://meet.google.com/' + inp_link + '/'
self.driver.get(inp_link)
self.driver.implicitly_wait(25)
mic = self.driver.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div/div[4]/div[3]/div/div[2]/div/div/div[1]/div[1]/div[3]/div[1]/div/div/div/div[1]')
# self.driver.execute_script("arguments[0].click()",mic)
# // __code__here__
# // for disabling
# // __webcam__
# finds join now button and clicks it
time.sleep(10)
self.driver.implicitly_wait(25)
join_class = self.driver.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div/div[4]/div[3]/div/div[2]/div/div/div[2]/div/div[2]/div/div/div[1]/span/span')
join_class.click()
print('Attending Test Class... -- {} -- {}'.format(time_now(),today_date()))
self.driver.implicitly_wait(25)
while True:
if time_now() > '14:27:55':
no_of_people = self.driver.find_element_by_xpath('//*[@id="ow3"]/div[1]/div/div[4]/div[3]/div[7]/div[3]/div/div[2]/div[1]/span/span/div/div/span[2]')
people = int(no_of_people.text)
print(people)
print(type(people))
if people<5:
print('Test class is over -- {} -- {}'.format(time_now(),today_date()),end='\n')
self.driver.get(class_info.google_classroom)
# self.driver.execute_script("arguments[0].click()",end_button)
break
else:
continue
time.sleep(5)
def __str__(self):
return('''
HELPS YOU to attend online classes,
AND helps you with attendance,
ENJOY!
v 1.1
''')
Azula = Firelord_Azula()
Azula.login()
time.sleep(3)
def run():
while True:
# xyz attendance and class
if time_now() > "08:05:00" and time_now() < class_info.xyz_class_timing:
if Azula.xyz_attendance_today == 0:
Azula.attendance('xyz')
elif time_now() > class_info.xyz_class_timing and time_now() < class_info.xyz_class_ending:
Azula.attend_class("xyz",class_info.xyz_class_url,class_info.xyz_class_timing,class_info.xyz_class_ending)
# abc attendance and class
elif time_now() > "12:50:25" and time_now() < class_info.abc_class_timing:
if Azula.abc_attendance_today == 0:
Azula.attendance('abc')
elif time_now() > class_info.abc_class_timing and time_now() < class_info.abc_class_ending:
Azula.attend_class("abc",class_info.abc_class_url,class_info.abc_class_timing,class_info.xyz_class_ending)
# to exit forever loop
elif time_now() > '14:05:05':
break
# time.sleep(x) to keep the cpu usage low if forever is running
time.sleep(10)
def end():
Azula.driver.close()
Azula.log_file.close()
print('-----------------------------------------------------------------',end='\n')
time.sleep(1.1)
print('''
___ _____ __ __ __ ___
/ | /__ / / / / / / / / |
/ /| | / / / / / / / / / /| |
/ ___ | / /__ / /_/ / / /___ / ___ |
/_/ |_| /____/ \____/ /_____/ /_/ |_|
is
shutting down''',end="")
for k in range(5):
print(".",end="",flush=True)
time.sleep(0.5)
print("!",end="\n")
if __name__ == '__main__':
run()
k = 1
#Azula.attend_test_class()
end()
quit()