Google Meet Self Attendance Bot ~Sarvesh Wadi

Wadisarvesh
Analytics Vidhya
Published in
7 min readAug 8, 2021

--

I have been missing my morning online lectures lately because of this irregular sleep cycle and procrastination. So I came up with this innovative idea of developing a python program that will automatically open the meet link for me and join the lecture using my account credentials.

Moreover, I added a versatile feature to this project, making this project totally self-acting in handling the Google Meetings web page. I have developed a program that will answer as “Present” through the Microphone of the laptop whenever the teacher takes your name. Pygame, selenium and chrome driver are used in this project. In this tutorial, I‘ll walk you through the project step by step to create your own Google Meet Attendance bot.

Step 1: Installing required Softwares

Run the following commands on your command prompt to install selenium and pygame.

pip install seleniumpip install pygame==2.0.0.dev8

Selenium supports all major browsers on the market such as Chromium, Firefox, Internet Explorer, Opera, and Safari. WebDriver aims to emulate a real user’s interaction with the browser as closely as possible. This is possible at varying levels in different browsers. Pygame is used to play and process mp3 files.

In this project, I have used Chrome Driver as the WebDriver to automate tasks that are to be performed on Chrome.

Download the latest chromedriver that matches with your version of chrome.

https://chromedriver.chromium.org/downloads

If you’re using firefox, Microsoft edge or any other application, you can download driver for your application accordingly

Step 2: Writing Python code for web automation.

Note: The indentations provided in the snippets are improper. You can refer to the link for the GitHub repo at the end.

import webbrowser
import time
import math
# importing webdriver from selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import StaleElementReferenceException
from pygame._sdl2 import get_num_audio_devices, get_audio_device_name #Get playback device names
from pygame import mixer #Playing sound

Import all the required libraries into your python code.

url = ‘https://accounts.google.com/signin/v2/identifier?ltmpl=meet&continue=https%3A%2F%2Fmeet.google.com%3Fhs%3D193&&flowName=GlifWebSignIn&flowEntry=ServiceLogin'# Here Chrome will be usedchrome_options = Options()#chrome_options.add_argument(‘use-fake-device-for-media-stream’)chrome_options.add_argument(‘use-fake-ui-for-media-stream’)chrome_options.add_argument(‘ — disable-notifications’)driver=webdriver.Chrome(“D://openlink_meet/chromedriver.exe”,chrome_options=chrome_options)

The URL at the starting of the snippet is an URL to the sign-in page of google meet.This URL is fed to chromedriver with provided chrome options.

The 3 chrome options provided to the chrome driver ensures that some specific permissions are allowed on chrome.

Finally, at the end of the snippet add the path of the chromedriver that you installed to webdriver.Chrome(“here”)

# Opening the website 
driver.get(url)

# getting the button by class name
SignIn = driver.find_element_by_id("identifierId")
# clicking on the button SignIn.send_keys("your email here")
SignIn.send_keys(Keys.ENTER)
driver.implicitly_wait(10)
EnterPass =driver.find_element_by_xpath("//*[@id='password']/div[1]/div/div[1]/input")
EnterPass.send_keys("your password here")
EnterPass.send_keys(Keys.ENTER)EnterCode=driver.find_element_by_xpath("//*[@id='i3']")
EnterCode.send_keys("Enter the meet code here")JoinLink=driver.find_element_by_xpath("/html/body/cwiz/div/div[2]/div/div[1]/div[3]/div/div[2]/div[2]/button/span")
JoinLink.click()

driver.get function loads the URL provided in the argument in a new chrome tab. SignIn is used to enter your email into the text field. Enter your email id in the argument of SignIn.send_keys function. Similarly, Enter your password in the argument of EnterPass.send_keys function. Again, Enter your meeting code in the argument of EnterCode.send_keys funciton.

Here find_element_by_path function takes in the XPath of any element on the web page as input and loads it for you. implicitly_wait function makes the web driver wait(do nothing) for a given seconds to load some elements on the webpage

Tip: To get XPath of any element on a webpage right click on that element on your chrome browser and click inspect-> Right-click on the highlighted definition of that element in the inspect section->copy->copy full XPath.

ignored_exceptions=(NoSuchElementException,StaleElementReferenceException)Mute = driver.find_element_by_xpath(“//*[@id=’yDmH0d’]/c-wiz/div/div/div[9]/div[3]/div/div/div[4]/div/div/div[1]/div[1]/div/div[4]/div[1]/div/div/div”)
Mute.click()
CamOff = driver.find_element_by_xpath(“/html/body/div/c-wiz/div/div/div[9]/div[3]/div/div/div[4]/div/div/div[1]/div[1]/div/div[4]/div[2]/div/div”)
CamOff.click()
JoinNow=WebDriverWait(driver,10,ignored_exceptions=ignored_exceptions).until(EC.element_to_be_clickable((By.XPATH, “/html/body/div[1]/c-wiz/div/div/div[9]/div[3]/div/div/div[4]/div/div/div[2]/div/div[2]/div/div[1]/div[1]/span/span”)))
JoinNow.click()

Ignored exceptions is a tuple of exceptions that code occurs while runtime. Again mute button and camera off button is located by XPath and then clicked using the .click() function. The last line of the snippet defines the join now button which joins the meeting. As it takes time for this button to load, an explicit driver wait is provided with given exceptions. It waits until the element is clickable or the time(here 10 secs) runs out.

TurnOnCaptions = driver.find_element_by_xpath(“/html/body/div[1]/c-wiz/div[1]/div/div[9]/div[3]/div[10]/div[2]/div/div[3]/div/span/button/span[2]”)
TurnOnCaptions.click()
students=WebDriverWait(driver,20,ignored_exceptions=ignored_exceptions).until(EC.element_to_be_clickable((By.XPATH, “/html/body/div[1]/c-wiz/div[1]/div/div[9]/div[3]/div[10]/div[3]/div[2]/div/div/div[2]/div/div”)))text = students.text
Total_numStudents = int(text)
print(Total_numStudents)
Caption_tray=WebDriverWait(driver,100,ignored_exceptions=ignored_exceptions).until(EC.presence_of_element_located((By.XPATH, “/html/body/div[1]/c-wiz/div[1]/div/div[9]/div[3]/div[7]/div”)))Captions=WebDriverWait(driver,100,ignored_exceptions=ignored_exceptions).until(EC.presence_of_element_located((By.XPATH,”/html/body/div[1]/cwiz/div[1]/div/div[9]/div[3]/div[7]/div/div[2]/div/span/span”)))count = 0

Further, we need to turn the captions on to read and analyze them.TurnOnCaptions does the same for us. students variable keeps the track of the number of people present in the meeting which is afterwards used to end the meeting if a lot of people are leaving the meet.

Caption_tray is the tray holding all the captions that we need to transcribe.Caption_tray and caption again are located by their XPath.

staleElement = Truewhile staleElement :try :Caption_tray = driver.find_element_by_xpath(“/html/body/div[1]/c-wiz/div[1]/div/div[9]/div[3]/div[7]/div”)Captions = driver.find_element_by_xpath(“/html/body/div[1]/c-wiz/div[1]/div/div[9]/div[3]/div[7]/div/div[2]/div”)if Captions.is_displayed() :Caption_text= Captions.text
Caption_text = Caption_text.lower()
print(Caption_text)
except(StaleElementReferenceException):
staleElement = True
except(NoSuchElementException) :
staleElement = True

This snippet continuously extracts the text from the captions tray into the python terminal. If your name, roll number, etc is displayed in this text you can analyze it and further play a recorded voice once the above event occurs.

changed_numstudents = int(students.text)
print(changed_numstudents)
if changed_numstudents > Total_numStudents :
Total_numStudents = changed_numstudents
elif changed_numstudents < Total_numStudents :if changed_numstudents <=math.floor(0.2*Total_numStudents):
EndCall=driver.find_element_by_xpath(“/html/body/div[1]/c-wiz/div[1]/div/div[9]/div[3]/div[10]/div[2]/div/div[7]/span/button/i”)
EndCall.click()

This is an algorithm that ends the call automatically for you if a lot of people are leaving the meet. EndCall variables define the End call button on the webpage.

if count ==0 :words = (“roll number 22”, “Jondoe” , “Johndoe” , “Jon Doe” ,”June Doe” , “Jon” )if any(name in Caption_text for name in words): UnMute = driver.find_element_by_xpath(“/html/body/div[1]/c-wiz/div[1]/div/div[9]/div[3]/div[10]/div[2]/div/div[1]/div/div/span/button/div[2]”)
UnMute.click()
mixer.init(devicename=’CABLE Input (VB-Audio Virtual Cable)’) mixer.music.load(“Enter path of your voice recording here”) mixer.music.play()
time.sleep(4)
mixer.music.stop()
UnMute.click()
count+=1

Now we check if your name or roll number has been displayed in the captions. Add your name and different combinations of how it is misspelt by text-to-speech into the words tuple at the start. If true, Unmute button is clicked and audio is played by pygame mixer. And the mic is again muted.

Enter the path of your recorded voice mp3 file into the argument of mixer.music.load(“here”).

Step 3: Installing and setting up VB-Audio Virtual Cable

VB-Audio Virtual Apps

https://vb-audio.com/Cable

Download and install VB-Audio Virtual Cable from the above link.

VB-CABLE is a virtual audio device working as a virtual audio cable. All audio coming in the CABLE input is simply forwarded to the CABLE output. It helps us to play the recorded voice file stored locally on your device to the microphone.

To set up VB-Audio Virtual Cable install the setup normally and reboot your device.Now you need select VB-Audio as your microphone device. To do this search for Change System Sounds on your windows search bar.The following dialogue box will appear after clicking it.

Go to the recording tab, find CABLE Output in the list, click and set default this device.

Note: VB-audio virtual cable links your PC’s speaker output virtually to your microphone. So remember to change the default microphone to your microphone device when in a call where you’re expected to speak.

Step 4: Creating a batch file for running our python application.

python D:\openlink_meet\openlink_meet_CV.py
pause

Open notepad and type the above snippet into it. And save the file as .bat extension. Now you can launch the python program just by clicking this batch file.

Step 5: Scheduling the batch file at a specific time(start of the meeting) using windows task scheduler.

Search and click task scheduler in the windows search bar. On the right, you can see the create task option. Provide the path of the batch file that we created in new options of the actions tab. Define the time of meeting in the triggers tab. You can define multiple triggers too!

Now your meeting will be automatically launched at the specified time and attend the whole meeting for you. It’ll mark you present and also end the meeting when most of the people have left the meet.

Checkout my GitHub repo:

Please like and share my post on LinkedIn (Demonstration of the project)

LinkedIn link :

Thankyou !

--

--