How to Automate MS Teams with Python

Search for a command to run...

Great idea, code and explanation. Recently my school shifted to Teams and I needed an automation tool for that. I think this will be of huge help for me. But, can I know what is the principle behind finding a component on screen with its image. I'm asking this because, I modified(changing the images with mine as I'm using dark mode) the code so that it fits my need though it isn't working. Please help me out. I've challenged my friends on getting my teams app automated!! If I fail to they'll troll me a lot. I hope you can understand my situations, so please help me to fix this functionality. Thanks in advance...
work also with linux ?
Will it automatically log me in teams? I have 7 meetings every day, so looking to auto join
All you need to know about Hacktoberfest 2021

Hello reader! Well, Hacktoberfest is something, you are gonna hear a lot about in the coming month. You can refer to my YouTube video Tutorial to see a working tutorial for better understanding and a step-by-step guide of the same. https://www.yo...

Hello reader! In this Blog post, I will share some useful code snippets and functions in Python. Give it a read. Let's get started! 1. Memory The method getsizeof can be used to retrieve the size of any object. Here's an example of the same. import...

Hello reader! Whenever a client sends a request to the server, the response always contains a status code. You might not see it always but it's returned at every client-server interaction. Well, even if you are not a programmer, you would still know...

Hello reader! Microsoft subsidiary GitHub launched Copilot to power pair programming with AI. In this blog post, I will share all you need to know about it. You can refer to my YouTube video Tutorial to see a working tutorial for better understandin...

Do you use MS Teams?
Due to this pandemic situation, the usage of these video conferencing apps also increased and most of the classes and lectures and conferences are conducted in Teams nowadays.
Repository for Ultimate Resource in python. Drop a star if you find it useful! Got anything to add? Open a PR on the same!
Disclaimer: This code is for educational purposes only and the author is not responsible for any consequences resulted. Please do not try it if you do not agree with the condition.
Do you wish to automate MS teams?

Let us see how I have automated Teams so that it automatically logs into one's meetings/classes on time.
- Microsoft Teams application
- Python
- Pyautogui
MS Teams is a popular chat and video conferencing app which allows us to attend/conduct meetings.
You can download it by clicking at the Link
PyAutoGUI is a cross-platform GUI automation Python module. It programmatically controls the mouse & keyboard. It has screenshot features and image finding features. PyAutoGUI works on Windows, macOS, and Linux, and runs on Python 2 and 3.
You can refer to the Pyautogui's documentation
Installation
pip install pyautogui
The source is available on https://github.com/asweigart/pyautogui

You can find my code at GitHub
An infinite loop keeps checking the current time of the system using this function.
datetime.now()
Necessary modules
we will import the necessary modules.
import os
import pyautogui
import time
from time import sleep
from datetime import datetime
Before startUp, make sure that the Teams application is closed.
Opening Teams The Teams app is opened using
os.startfile()
os.startfile("C:/Users/username/AppData/Local/Microsoft/Teams/current/Teams.exe")
locateCenterOnScreen()
pyautogui.locateCenterOnScreen() function locates the center of the first found instance of the image on the screen.
Capture the screenshot of settings button and use the below chunk of code to move the mouse to that button and click it.

pyautogui.moveTo()
moves the cursor to that location.
pyautogui.click()
performs a click operation.
settings = pyautogui.locateCenterOnScreen("settings.PNG")
pyautogui.moveTo(settings)
pyautogui.click()
time.sleep(2)
Moving forward, we need to click on Manage Teams button to get a list of teams vertically.
manageteams = pyautogui.locateCenterOnScreen("manageteams.PNG")
pyautogui.moveTo(manageteams)
pyautogui.click()
time.sleep(2)
Next, you will get the Teams List tab screen.
Now we run the below code snippet in an infinite loop.
We get the current time and compare it with the class ending time.
For example,
If the current time is 10:00 and my class is at 10:00 but the meeting has started. If I give my class ending time i.e 11:00 then as soon as the meeting starts the scripts automatically clicks on join button with camera and microphone turned off.
Capture screenshot of your class name. DemoMeetOne and DemoMeetTwo in my case
Similarily Join button


if now < '18:00':
DemoMeetOne=pyautogui.locateCenterOnScreen("DemoMeetOne.PNG")
pyautogui.moveTo(DemoMeetOne)
pyautogui.click()
time.sleep(2)
join = pyautogui.locateCenterOnScreen("join.PNG")
pyautogui.moveTo(join)
pyautogui.click()
time.sleep(2)
audiooff = pyautogui.locateCenterOnScreen("audiooff.PNG")
pyautogui.moveTo(audiooff)
pyautogui.click()
time.sleep(2)
I have done it for 2 classes.
DemoMeetOne
DemoMeetTwo you can do it for any number of classes you want.
You can find my code at GitHub
I have uploaded the entire code and all the necessary files in my repository. Please drop a star if you like it.
You can also connect with me on Twitter Also, have a look at my other Blogs:
If you have any Queries or Suggestions, please reach out to me in the Comments Section below.