Skip to content
This repository was archived by the owner on Jul 4, 2024. It is now read-only.

Commit 1e64785

Browse files
authored
Code clean up and live count optimize
1 parent d9d4d56 commit 1e64785

File tree

1 file changed

+40
-12
lines changed

1 file changed

+40
-12
lines changed

Source/Automeet.py

+40-12
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,44 @@ def live_count(): # Print Live count of participants
215215
print(f'{"Live count of participants: " + live_count.number_of_participants + " "}\r', end='', flush=True) # Prints the live count
216216
time.sleep(0.5)
217217

218+
except NoSuchElementException: # An exception if Network change is detected.
219+
try:
220+
connection_lost = driver.find_element_by_class_name("RkzbPb").text
221+
if "You lost your network connection. Trying to reconnect." in connection_lost:
222+
try:
223+
WebDriverWait(driver, 180).until(expected_conditions.presence_of_element_located((By.CLASS_NAME, "crqnQb")))
224+
except TimeoutException:
225+
print("Please check your Internet connection and Re-Start the Automeet.")
226+
exit_now()
227+
except NoSuchElementException:
228+
live_count()
229+
pass
230+
231+
def exit_checker():
232+
try:
218233
# Several Participants left the meeting or recording Stopped.
219234
try:
220-
live_count.left_or_rec_stop = driver.find_element_by_class_name("aGJE1b").text
235+
exit_checker.left_or_rec_stop = driver.find_element_by_class_name("aGJE1b").text
221236
except NoSuchElementException:
222237
pass
223238
except StaleElementReferenceException:
224239
try:
225-
live_count.left_or_rec_stop = driver.find_element_by_class_name("aGJE1b").text
240+
exit_checker.left_or_rec_stop = driver.find_element_by_class_name("aGJE1b").text
241+
except NoSuchElementException:
242+
pass
243+
except WebDriverException as e:
244+
if "not connected to DevTools" in e:
245+
print("Please check your Internet connection and Re-Start the Automeet.")
246+
exit_now()
247+
248+
# Your host ended the meeting for everyone.
249+
try:
250+
exit_checker.host_end_meeting = driver.find_element_by_class_name("CRFCdf").text
251+
except NoSuchElementException:
252+
pass
253+
except StaleElementReferenceException:
254+
try:
255+
exit_checker.host_end_meeting = driver.find_element_by_class_name("CRFCdf").text
226256
except NoSuchElementException:
227257
pass
228258
except WebDriverException as e:
@@ -246,7 +276,7 @@ def live_count(): # Print Live count of participants
246276

247277
def end_class(did_host_end): # Ends the current session
248278
live_count.max_count = 0
249-
live_count.left_or_rec_stop = ""
279+
exit_checker.left_or_rec_stop = ""
250280
time.sleep(10)
251281
if not did_host_end:
252282
# Clicks leave call button
@@ -323,20 +353,18 @@ def exit_now(): # Exits the script
323353
"profile.default_content_setting_values.geolocation": 2,
324354
"profile.default_content_setting_values.notifications": 2})
325355

326-
driverPath = 'chromedriver.exe'
327-
328356
try:
329357
try:
330358
# For Chrome
331-
driver = webdriver.Chrome(executable_path=resource_path(driverPath), options=options)
359+
driver = webdriver.Chrome(executable_path=resource_path('chromedriver.exe'), options=options)
332360
except WebDriverException:
333361
try:
334362
# For 64 Bit Brave
335363
options.binary_location = "C:\\Program Files\\BraveSoftware\\Brave-Browser\\Application\\brave.exe"
336364
except WebDriverException:
337365
# For 32 Bit Brave
338366
options.binary_location = "C:\\Program Files (x86)\\BraveSoftware\\Brave-Browser\\Application\\brave.exe"
339-
driver = webdriver.Chrome(options=options, executable_path=resource_path(driverPath))
367+
driver = webdriver.Chrome(options=options, executable_path=resource_path('chromedriver.exe'))
340368
except FileNotFoundError:
341369
print("Webdriver seems to be outdated, download the LATEST VERSION of AUTOMEET from here: "
342370
"'https://github.com/pixincreate/Automeet/releases/latest'", end='\n')
@@ -379,7 +407,7 @@ def exit_now(): # Exits the script
379407
# Declarations
380408
lastClass = False
381409
live_count.max_count = 0
382-
live_count.left_or_rec_stop = live_count.rec_button = scheduledTimeInSeconds = classTime = classTitle = ""
410+
exit_checker.left_or_rec_stop = exit_checker.host_end_meeting = live_count.rec_button = scheduledTimeInSeconds = classTime = classTitle = ""
383411

384412
# Deleting the user data, i.e., taken in the beginning
385413
del USERNAME, PASSWORD
@@ -520,9 +548,9 @@ def exit_now(): # Exits the script
520548
# Ends session when either of the condition is satisfied
521549
while True:
522550
live_count()
523-
551+
exit_checker()
524552
try:
525-
if "Your host ended the meeting for everyone" in driver.find_element_by_class_name("CRFCdf"):
553+
if "Your host ended the meeting for everyone" in exit_checker.host_end_meeting:
526554
print('Meeting will end now as Host ended the meeting.', end='\r', flush=True)
527555
host_ended = 1
528556
end_class(host_ended)
@@ -532,12 +560,12 @@ def exit_now(): # Exits the script
532560
host_ended = 0
533561
end_class(host_ended)
534562
break
535-
elif "Several participants left the meeting." in live_count.left_or_rec_stop:
563+
elif "Several participants left the meeting." in exit_checker.left_or_rec_stop:
536564
print('Meeting will end now as Several participants left the meeting.', end='\r', flush=True)
537565
host_ended = 0
538566
end_class(host_ended)
539567
break
540-
elif "stopped recording" in live_count.left_or_rec_stop:
568+
elif "stopped recording" in exit_checker.left_or_rec_stop:
541569
print('Meeting will end now as the recording stopped.', end='\r', flush=True)
542570
host_ended = 0
543571
end_class(host_ended)

0 commit comments

Comments
 (0)