-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzZoom.py
312 lines (271 loc) · 12.1 KB
/
zZoom.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
import time
import sys
import csv
import sched
import datetime
import os
import re
from time import time, sleep, strftime, localtime, strptime, mktime
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import ElementClickInterceptedException
from urllib.parse import urlparse
import cookies #cookies for Zoom Web session
def write_file(participants):
"""Write attendance data to the disk as a CSV file"""
try:
with open("attendance.csv", 'w', encoding='utf-8') as f:
fields = ['Name', 'Timestamp']
csvwriter = csv.DictWriter(f, fieldnames=fields)
for userData in participants:
csvwriter.writerow(userData)
print("Data saved successfully!")
except IOError:
print("Error occured while writing to the disk")
def suspend_pc(stat):
"""Suspend system - Sleep|Hibernate"""
if stat.lower() == 'yes':
print('\n', '*' * 25)
print("-- Suspending system --")
os.system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0")
def load_meeting_data():
"""Load meeting data from file"""
try:
with open("MeetingData.txt", 'r') as f:
lines = f.readlines()
for line in lines:
if line[0] == '#' or line.strip() == '':
continue
data = line.split('=', 1)
if data[0].strip() == 'username':
username = data[1].strip()
elif data[0].strip() == 'meetingLink':
meetingLink = data[1].strip()
elif data[0].strip() == 'startDate':
startDate = data[1].strip()
elif data[0].strip() == 'startTime':
startTime = data[1].strip()
elif data[0].strip() == 'stopIncomingVideo':
stopIncomingVideo = data[1].strip()
elif data[0].strip() == 'minimumUsersLimit':
minimumUsersLimit = data[1].strip()
elif data[0].strip() == 'waitTime':
waitTime = data[1].strip()
elif data[0].strip() == 'sleepSystemOnEnd':
sleepSystemOnEnd = data[1].strip()
print("Meeting data successfully imported!")
return([username, meetingLink, startDate, startTime, stopIncomingVideo,
minimumUsersLimit, waitTime, sleepSystemOnEnd])
except IOError:
print("Error occured while reading the file")
def launcher():
"""Match the time & date to launch the joining process"""
print("Loading meeting data...")
data = load_meeting_data()
parsedLink = urlparse(data[1])
if (not('zoom.us' in parsedLink[1]) or not('zoom.us/j/' in data[1])):
print("""Seems like a invalid meeting link - Check again!
\nExample: https://zoom.us/j/12345678912?pwd=ed43djGF5D0RndrcmdJfrsuN1""")
input('\nPress \'ENTER\' to quit... ')
sys.exit()
try:
data[1] = data[1].split('?')[0].replace('/j/', '/wc/') + '/join?' + data[1].split('?')[1]
except:
print("""Error occured while processing meeting link - Check again!
\nExample: https://zoom.us/j/12345678912?pwd=ed43djGF5D0RndrcmdJfrsuN1""")
input('\nPress \'ENTER\' to quit... ')
sys.exit()
scheduler1 = sched.scheduler(time, sleep)
startTime = datetime.datetime.strptime(' '.join(data[2:4]), '%Y-%m-%d %H:%M')
if startTime < datetime.datetime.now():
print('Start time is not valid!')
input('\nPress \'ENTER\' to quit... ')
sys.exit()
startTime = strptime(' '.join(data[2:4]), '%Y-%m-%d %H:%M')
startTime = mktime(startTime)
task = scheduler1.enterabs(startTime, 1, zZoom_join, [data])
print(f'Waiting untill -- {data[2]} - {data[3]}\n')
scheduler1.run()
def check_waiting_room(driver):
"""Check waiting room / meeting status in Zoom meeting"""
connectCount = 0
while connectCount < 30:
meetingStat = driver.title
isWaitingRoom = driver.find_elements(By.XPATH, "//span[text()='Please wait, the meeting host will let you in soon.']")
if len(isWaitingRoom) != 0 or meetingStat == 'The meeting has not started - Zoom':
print('Waiting...')
sleep(10)
connectCount += 1
else:
sleep(10)
return False
return True
def check_audio_stat(driver, timeCount):
"""Manage join audio settings in Zoom meeting"""
connectCount = 0
sleep(timeCount)
muteBtn = driver.find_elements(By.XPATH, "//button[text()='Mute']")
unmuteBtn = driver.find_elements(By.XPATH, "//button[text()='Unmute']")
joinAudioBtn = driver.find_elements(By.XPATH, "//button[text()='Join Audio']")
audioPopup = driver.find_elements(By.XPATH, "//span[text()='Computer Audio']")
if len(audioPopup) != 0:
return "Popup"
elif len(joinAudioBtn) != 0:
joinAudioBtn[0].click()
return "Popup"
elif len(muteBtn)!= 0:
muteBtn[0].click()
return "Muted"
elif len(unmuteBtn) != 0:
return "Unmute"
def zZoom_join(data):
"""Automate the joining process on Zoom meeting (Throuh Browser)"""
print('=' * 15)
print('Username: ', data[0])
print('Minimum Users Limit:', data[5])
print('Suspend at Meeting End :', data[7])
print('=' * 15, '\n')
print('Starting the joining process...')
#fireFoxOptions = webdriver.FirefoxOptions()
#fireFoxOptions.set_headless()
#driver = webdriver.Firefox(firefox_options=fireFoxOptions)
driver = webdriver.Firefox()
driver.get(data[1])
for cookie in cookies.manage_cookies(data[0]):
driver.add_cookie(cookie)
print("Added Session Cookies")
print("Refreshing the page...")
driver.refresh()
try:
print("Joining the meeting...")
print("Checking meeting status...")
meetingStat = check_waiting_room(driver)
if meetingStat:
print("- Waiting [startup] timeout -\nClosing the webdriver...")
driver.quit()
suspend_pc(data[7])
driver.find_elements(By.XPATH, "//button[text()='Join']")[0].click()
sleep(2)
isCodeError = driver.find_elements(By.ID, "unlogin-join-form")
if len(isCodeError) != 0:
print("Seems like Meeting Passcode is incorrect!")
print("Closing the webdriver...")
driver.quit()
suspend_pc(data[7])
print("Checking for waiting room | Meeting status")
isWaiting = check_waiting_room(driver)
if isWaiting:
print("- Waiting timeout -\nClosing the webdriver...")
driver.quit()
suspend_pc(data[7])
print("Connecting via computer audio...")
except:
print("Error occured while connecting to meeting!")
driver.quit()
suspend_pc(data[7])
connectCount = 0
while connectCount < 6:
try:
isRecording = driver.find_elements(By.XPATH, "//div[text()='This meeting is being recorded']")
if len(isRecording) != 0:
driver.find_elements(By.XPATH, "//button[text()='Got it']")[0].click()
sleep(1)
print("Connecting...")
currStat = check_audio_stat(driver, 5)
if currStat == "Unmute":
print("-- Mic is already muted --")
break
elif currStat == "Muted":
print("-- Mic is now muted --")
break
elif currStat == "Popup":
driver.find_elements(By.XPATH, "//button[text()='Join Audio by Computer']")[0].click()
check_audio_stat(driver, 2)
print("Connected via computer audio")
break
except (IndexError, ElementClickInterceptedException):
sleep(5)
connectCount += 1
print("Please wait...")
if data[4].lower() == 'yes':
try:
sleep(3)
driver.find_elements(By.XPATH, "//div[text()='More']")[0].click()
sleep(2)
driver.find_elements(By.XPATH, "//a[text()='Stop Incoming Video']")[0].click()
print("Disabled incoming video")
except:
print("Error occured while stopping incoming video")
log_participants(driver, data[5], data[6], data[7])
def log_participants(driver, minUsers=5, waitTime=10, suspendStat='yes'):
"""Log participants' names & timestamps"""
try:
print("Logging data...\nSit back & relax... :)")
participants = []
driver.find_elements(By.XPATH, "//span[text()='Participants']")[0].click()
sleep(5)
waitTime = int(waitTime)
waitTime *= 60
nowSecs = 0
while True:
try:
isWaiting = check_waiting_room(driver)
if isWaiting:
print("-- Waiting room timeout --\nClosing the webdriver...")
raise Exception
isEnded = driver.find_elements(By.XPATH, "//div[text()='This meeting has been ended by host']")
if len(isEnded) != 0:
print('-- Host ended the meeting --')
raise Exception
limitExceeded = driver.find_elements(By.XPATH, "//div[text()='This free Zoom meeting has ended']")
if len(limitExceeded) != 0:
print('-- Meeting has ended due to time limit --')
raise Exception
meetingUpgraded = driver.find_elements(By.XPATH, "//div[text()='This meeting has been upgraded by the host and now includes unlimited minutes.']")
if len(meetingUpgraded) != 0:
print('-- Meeting has been upgraded --')
driver.find_elements(By.XPATH, "//button[text()='OK']")[0].click()
isRecording = driver.find_elements(By.XPATH, "//div[text()='This meeting is being recorded']")
if len(isRecording) != 0:
driver.find_elements(By.XPATH, "//button[text()='Got it']")[0].click()
askAudio = driver.find_elements(By.XPATH, "//div[text()='The host would like you to speak']")
if len(askAudio) != 0:
sleep(1)
print("=== Host asked to unmute ===")
driver.find_elements(By.XPATH, "//button[text()='Stay Muted']")[0].click()
print("--- Request rejected ---")
askVideo = driver.find_elements(By.XPATH, "//div[text()='The host has asked you to start your video']")
if len(askVideo) != 0:
sleep(1)
print("=== Host asked to enable video ===")
driver.find_elements(By.XPATH, "//button[text()='Later']")[0].click()
print("--- Request rejected ---")
activeUsers = driver.find_elements(By.CLASS_NAME, "participants-item__name-section")
#print('Users: ', len(activeUsers))
for user in activeUsers[1:]:
tempText = re.findall(r"^<span .*\">(.*)<\/span.*\">(.*)<\/span>", user.get_attribute("innerHTML").strip())
uName = tempText[0][0] + tempText[0][1]
if not any(participant['Name']==uName for participant in participants):
#print('Not Found -- Appending: ', uName)
participants.append({'Name':uName, 'Timestamp': strftime("%H:%M:%S", localtime())})
#print('Curr Amount: ', len(participants))
if (len(activeUsers) <= int(minUsers)) and (nowSecs > waitTime):
print("Minimum users amount reached. -- Leaving from meeting...")
write_file(participants)
driver.quit()
suspend_pc(suspendStat)
sleep(10)
nowSecs += 10
except:
print('Seems like session has been ended')
write_file(participants)
break
driver.quit()
suspend_pc(suspendStat)
except:
print('-'*25)
write_file(participants)
driver.quit()
suspend_pc(suspendStat)
if __name__ == '__main__':
launcher()