-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathteams-status-bot.py
executable file
·171 lines (121 loc) · 5.3 KB
/
teams-status-bot.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
#!/usr/bin/python3
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver import ActionChains
from datetime import datetime
import time
# ======================================================================================== #
# ====================================== SETTINGS ======================================== #
# ======================================================================================== #
# you can get yours updated driver from here: https://sites.google.com/a/chromium.org/chromedriver/downloads
driver = webdriver.Chrome("./chromedriver")
# Email
email = "REPLACE_THIS_WITH_YOUR_TEAMS_EMAIL_ADDRESS"
# Password
password = "REPLACE_THIS_WITH_YOUR_PASSWORD"
# The frequency that you want to update your status in minutes
updateEvery = 1 # => in minutes, means it will update your status ever one minute
# For how long you want to keep this running, default = 1 hour
forHours = 8 # => in hours, means it will keep the program running for 8 hours
# ======================================================================================== #
# ======================================== LOGIC ========================================= #
# ======================================================================================== #
def setupDriver():
# opens MS teams web page
driver.get("https://teams.microsoft.com/")
# Sets a sticky timeout to implicitly wait for an element to be found,
# or a command to complete.
# This method only needs to be called one time per session.
driver.implicitly_wait(45)
driver.set_page_load_timeout(30)
def findElement(xPath, _driver=driver):
"""
Finds an element by it's xPath.
:Args:
- xPath: HTML xPath.
- _driver: WebDriver
:Usage:
findElement(xPath="html/...")
"""
return _driver.find_element_by_xpath(xPath)
def login(email, password):
# getting email text box
emailBox = findElement("/html/body/div/form[1]/div/div/div[2]/div[1]/div/div/div/div/div[1]/div[3]/div/div/div/div[2]/div[2]/div/input[1]")
# adding email address in the text box
emailBox.send_keys(email)
# clicking enter to continue
emailBox.send_keys(Keys.RETURN)
# getting the password text box element
passwordBox = findElement("/html/body/div[2]/div[2]/div[1]/div[2]/div/div/form/div[2]/div[2]/input")
# adding the password
passwordBox.send_keys(password)
# clicking enter to continue
passwordBox.send_keys(Keys.RETURN)
useOTP = findElement("/html/body/div/form[1]/div/div/div[2]/div[1]/div/div/div/div/div/div/div[1]/div/div[2]/div[2]/div/div[2]/div/div[2]/div/div[1]/div/div/div[2]/div")
useOTP.click()
def stayLoggedIn(value: bool = False):
if value:
saveSession = findElement("/html/body/div/form/div[1]/div/div[1]/div[2]/div/div[2]/div/div[3]/div[2]/div/div/div[2]/input")
saveSession.send_keys(Keys.RETURN)
else:
# don't stay logged in
saveSession = findElement("/html/body/div/form/div/div/div[2]/div[1]/div/div/div/div/div/div/div[1]/div[2]/div/div[2]/div/div[3]/div[2]/div/div/div[1]/input")
saveSession.send_keys(Keys.RETURN)
def useTeamsOnTheWeb():
# use MS teams on the web
# useOnWeb = findElement("/html/body/promote-desktop/div/div/div/div[1]/div[2]/div/a")
# useOnWeb.click()
# print("useOnWeb has been clicked 😎 ..")
time.sleep(5)
def updateStatus(status: str = "/busy"):
"""
Set your profile status to whatever you pass.
:Args:
- status: "/available".
:Usage:
updateStatus(status="/available")
"""
# select the search bar
searchBox = findElement("/html/body/div[2]/div[1]/app-header-bar/div/power-bar/div/div/form/search-box/div/input")
searchBox.send_keys(status)
# select `available` from the dropdown menu
select = findElement("/html/body/div[2]/div[1]/app-header-bar/div/power-bar/div/div/form/slash-command-box/div/slash-command-popover/div/div[2]/ul/li/div")
select.click()
# datetime object containing current date and time
now = datetime.now()
# dd/mm/YY H:M:S
dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
print("updateStatus, 😎 .. date and time =", dt_string)
# busy
# available
def keepUpdating(status: str = "/busy", every: int = 5, hours: int = 1):
"""
Automate updating your status with time logic.
:Args:
- status: "/available".
- every: the frequency that you want to update your status
- hours: for how long you want to keep this running, default = 1 hour
:Usage:
# The below usage example will keep updating the status every 5 minuts
# for maxmum 8 hours then it will stop.
keepUpdating(status="/available", every=5, hours=8)
"""
selectedRange: int = int((hours * 60) / every)
for _ in range(selectedRange):
updateStatus(status)
time.sleep(every * 60)
def runAutomation(email, password, every, hours):
setupDriver()
login(email, password)
stayLoggedIn(False)
useTeamsOnTheWeb()
keepUpdating(every=every, hours=hours)
# then quit the browser once done
driver.quit()
# MAIN RUNNING POINT OF THIS APP
runAutomation(
email=email,
password=password,
every=updateEvery,
hours=forHours
)