问题
I was thinking about a simple python automation script that will open and enter a google meet meeting via the link at a specific time.
I am just learning, can anybody help me out
回答1:
I know this isn't much of an answer, but I also use google meets. I was thinking of the same thing. Getting on to my point, try using a python library called selenium
. I use it to automate daily web things every day.
In my opinion it works best on linux because linux has a service called crontab or something like that..
Update
I know this is a bit...unconventional for Stack Overflow, but if you're willing to, I could post my code here when I am done writing it. The reason I say unconventional, is because it will take some time.
Update 2.0
I finished the code...earlier than I expected. For the time being it ONLY:
- Logs into Google with a normal google account OR with a google account with an Active Directory login.
- Uses fallback loops to ensure that the program works on slow wifi because, not all of us have 5G yet.
- Opens Google Meets after signing into Google. (Trust me, it was tricky doing this...Google doesn't like people autonomously signing into things)
My "TODO" list:
- I'm going to have the program look at Google meets for any scheduled meets, and join 5 minutes before. (estimated project time - 1 day)
Below is the code, with some adjustments it should work on Windows, Mac OS, and any other system. I'm currently using Firefox with selenium...just my advice, but I advise that you do the same.
If you're wondering why I kept USE_FAILSAFE_PERCAUTIONS
, it's because the program fails whenever I use driver.implicitly_wait()
. If someone knows how to properly use it, it would be more useful than time.sleep()
.
import selenium, os, time, datetime, random, warnings, sys
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
warnings.filterwarnings("ignore", category=DeprecationWarning)
print("Timestamp: " + datetime.datetime.now().strftime("%D %H:%M:%S"))
AUTOMATION_FAILED = False
USE_FAILSAFE_PERCAUTIONS = True
EMAIL_ADDRESS = ""
AD_USERNAME = None # Leave blank or put 'None' to use a regular Google account
AD_PASSWORD = ""
options = Options()
options.headless = False
profile = webdriver.FirefoxProfile()
binary = FirefoxBinary('/usr/lib/firefox-esr/firefox-esr') # Absolute path to Firefox executable
driver = webdriver.Firefox(profile, options=options, firefox_binary=binary)
driver.maximize_window()
driver.get("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1<mpl=default<mplcache=2&emr=1&osid=1#identifier")
print("Successfully loaded Google Authetication point! [Gmail]")
time.sleep(2)
if AUTOMATION_FAILED == False:
for i in range(6):
try:
driver.find_element_by_id("identifierId").send_keys(EMAIL_ADDRESS)
driver.find_element_by_id("identifierNext").click()
print("Sucessfully uploaded email...")
break
except selenium.common.exceptions.NoSuchElementException:
print("[ERROR]: Attempting to resend email address.")
if USE_FAILSAFE_PERCAUTIONS: time.sleep(6)
else: driver.implicitly_wait(6)
except selenium.common.exceptions.WebDriverException as e:
print("[ERROR]: Web driver error.\n[ERROR DETAILS]:",e)
AUTOMATION_FAILED = True
break
if AUTOMATION_FAILED == False:
if AD_USERNAME == "" or AD_USERNAME == None:
for i in range(6):
try:
driver.find_element_by_name("password").send_keys(AD_PASSWORD)
driver.find_element_by_id("passwordNext").click()
print("Sucessfully sent credentials...")
break
except selenium.common.exceptions.NoSuchElementException:
print("[ERROR]: Attempting to find password input.")
if USE_FAILSAFE_PERCAUTIONS: time.sleep(6)
else: driver.implicitly_wait(6)
else:
for i in range(6):
try:
driver.find_element_by_id("userNameInput").send_keys(AD_USERNAME)
driver.find_element_by_id("passwordInput").send_keys(AD_PASSWORD)
driver.find_element_by_id("submitButton").click()
print("Sucessfully sent Active Directory credentials...")
break
except selenium.common.exceptions.NoSuchElementException:
print("[ERROR]: Attempting to find active directory login elements.")
if USE_FAILSAFE_PERCAUTIONS: time.sleep(6)
else: driver.implicitly_wait(6)
except selenium.common.exceptions.WebDriverException as e:
print("[ERROR]: Web driver error.\n[ERROR DETAILS]:",e)
AUTOMATION_FAILED = True
break
time.sleep(2)
print("Loading Google Meets...")
driver.get("https://meet.google.com")
driver.refresh()
Update 3
I got it to the point where the program joins the first meet it finds when you load the website, for example: if "English" is right below the button that says "Use a meeting code", the program will join "English". It can easily be reconfigured to join when it is time for English.
The program also turns off your microphone by pressing CTRL + d
, and turns off your camera by pressing CTRL + e
. Again, this can be reconfigured for Mac OS.
import selenium, os, time, datetime, random, warnings, sys
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
warnings.filterwarnings("ignore", category=DeprecationWarning)
print("Timestamp: " + datetime.datetime.now().strftime("%D %H:%M:%S"))
AUTOMATION_FAILED = False
USE_FAILSAFE_PERCAUTIONS = True
EMAIL_ADDRESS = ""
AD_USERNAME = ""
AD_PASSWORD = ""
options = Options()
options.headless = False
profile = webdriver.FirefoxProfile()
binary = FirefoxBinary('/usr/lib/firefox-esr/firefox-esr') # Absolute path to Firefox executable
driver = webdriver.Firefox(profile, options=options, firefox_binary=binary)
driver.maximize_window()
driver.get("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1<mpl=default<mplcache=2&emr=1&osid=1#identifier")
print("Successfully loaded Google Authetication point! [Gmail]")
time.sleep(2)
if AUTOMATION_FAILED == False:
for i in range(6):
try:
driver.find_element_by_id("identifierId").send_keys(EMAIL_ADDRESS)
driver.find_element_by_id("identifierNext").click()
print("Sucessfully uploaded email...")
break
except selenium.common.exceptions.NoSuchElementException:
print("[ERROR]: Attempting to resend email address.")
if USE_FAILSAFE_PERCAUTIONS: time.sleep(6)
else: driver.implicitly_wait(6)
except selenium.common.exceptions.WebDriverException as e:
print("[ERROR]: Web driver error.\n[ERROR DETAILS]:",e)
AUTOMATION_FAILED = True
break
if AUTOMATION_FAILED == False:
if AD_USERNAME == "" or AD_USERNAME == None:
for i in range(6):
try:
driver.find_element_by_name("password").send_keys(AD_PASSWORD)
driver.find_element_by_id("passwordNext").click()
print("Sucessfully sent credentials...")
break
except selenium.common.exceptions.NoSuchElementException:
print("[ERROR]: Attempting to find password input.")
if USE_FAILSAFE_PERCAUTIONS: time.sleep(6)
else: driver.implicitly_wait(6)
else:
for i in range(6):
try:
driver.find_element_by_id("userNameInput").send_keys(AD_USERNAME)
driver.find_element_by_id("passwordInput").send_keys(AD_PASSWORD)
driver.find_element_by_id("submitButton").click()
print("Sucessfully sent Active Directory credentials...")
break
except selenium.common.exceptions.NoSuchElementException:
print("[ERROR]: Attempting to find active directory login elements.")
if USE_FAILSAFE_PERCAUTIONS: time.sleep(6)
else: driver.implicitly_wait(6)
except selenium.common.exceptions.WebDriverException as e:
print("[ERROR]: Web driver error.\n[ERROR DETAILS]:",e)
AUTOMATION_FAILED = True
break
time.sleep(2)
print("Loading Google Meets...")
driver.get("https://meet.google.com")
#driver.refresh()
a = driver.find_elements_by_class_name("mobgod")
print(len(a))
a[0].click()
time.sleep(7) # Ensure that the browser fully loads the next part.
for i in range(6):
try:
WebDriverWait(driver, 36).until(EC.presence_of_element_located((By.XPATH, "//span[contains(text(),'Join now')]")))
time.sleep(2)
turn_off_mic_action = ActionChains(driver)
turn_off_mic_action.key_down(Keys.CONTROL).send_keys("d").key_up(Keys.CONTROL).perform();
turn_off_camera_action = ActionChains(driver)
turn_off_camera_action.key_down(Keys.CONTROL).send_keys("e").key_up(Keys.CONTROL).perform();
print("Sucessfully found landmark...turned off camera and microphone.")
break
except selenium.common.exceptions.TimeoutException:
print("[ERROR]: Attempting to find landmark...")
if USE_FAILSAFE_PERCAUTIONS: time.sleep(6)
else: driver.implicitly_wait(6)
try:
join_button = WebDriverWait(driver, 36).until(EC.presence_of_element_located((By.XPATH, "//span[contains(text(),'Join now')]")))
driver.execute_script("arguments[0].click();", join_button)
except selenium.common.exceptions.TimeoutException:
try:
join_button = WebDriverWait(driver, 36).until(EC.presence_of_element_located((By.XPATH, "//span[contains(text(),'Ask to join')]")))
driver.execute_script("arguments[0].click();", join_button)
except selenium.common.exceptions.TimeoutException:
print("Couldn't join Google Meet.")
Update 3 (For Real)
This update includes the ability to use a code instead, that's about it. The previous versions rely mostly on having a Google account that is connected with Google's Active Directory service. ...lucky for you now in this update, you can use your personal account.
import selenium, os, time, datetime, random, warnings, sys
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
warnings.filterwarnings("ignore", category=DeprecationWarning)
print("Timestamp: " + datetime.datetime.now().strftime("%D %H:%M:%S"))
AUTOMATION_FAILED = False
USE_FAILSAFE_PERCAUTIONS = True
CLASS_CODE = ""
EMAIL_ADDRESS = ""
AD_USERNAME = ""
AD_PASSWORD = ""
options = Options()
options.headless = False
profile = webdriver.FirefoxProfile()
binary = FirefoxBinary('/usr/lib/firefox-esr/firefox-esr') # Absolute path to Firefox executable
driver = webdriver.Firefox(profile, options=options, firefox_binary=binary)
driver.maximize_window()
driver.get("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1<mpl=default<mplcache=2&emr=1&osid=1#identifier")
print("Successfully loaded Google Authetication point! [Gmail]")
time.sleep(2)
if AUTOMATION_FAILED == False:
for i in range(6):
try:
driver.find_element_by_id("identifierId").send_keys(EMAIL_ADDRESS)
driver.find_element_by_id("identifierNext").click()
print("Sucessfully uploaded email...")
break
except selenium.common.exceptions.NoSuchElementException:
print("[ERROR]: Attempting to resend email address.")
if USE_FAILSAFE_PERCAUTIONS: time.sleep(6)
else: driver.implicitly_wait(6)
except selenium.common.exceptions.WebDriverException as e:
print("[ERROR]: Web driver error.\n[ERROR DETAILS]:",e)
AUTOMATION_FAILED = True
break
if AUTOMATION_FAILED == False:
if AD_USERNAME == "" or AD_USERNAME == None:
for i in range(6):
try:
driver.find_element_by_name("password").send_keys(AD_PASSWORD)
driver.find_element_by_id("passwordNext").click()
print("Sucessfully sent credentials...")
break
except selenium.common.exceptions.NoSuchElementException:
print("[ERROR]: Attempting to find password input.")
if USE_FAILSAFE_PERCAUTIONS: time.sleep(6)
else: driver.implicitly_wait(6)
else:
for i in range(6):
try:
driver.find_element_by_id("userNameInput").send_keys(AD_USERNAME)
driver.find_element_by_id("passwordInput").send_keys(AD_PASSWORD)
driver.find_element_by_id("submitButton").click()
print("Sucessfully sent Active Directory credentials...")
break
except selenium.common.exceptions.NoSuchElementException:
print("[ERROR]: Attempting to find active directory login elements.")
if USE_FAILSAFE_PERCAUTIONS: time.sleep(6)
else: driver.implicitly_wait(6)
except selenium.common.exceptions.WebDriverException as e:
print("[ERROR]: Web driver error.\n[ERROR DETAILS]:",e)
AUTOMATION_FAILED = True
break
time.sleep(2)
print("Loading Google Meets...")
driver.get("https://meet.google.com")
#driver.refresh()
a = driver.find_elements_by_class_name("mobgod")
print(len(a))
if len(a) != 0:
a[0].click()
if AD_USERNAME == "" or AD_USERNAME == None:
for i in range(6):
try:
driver.find_element_by_id("i3").send_keys(CLASS_CODE)
press_enter = ActionChains(driver)
press_enter.key_down(Keys.ENTER).key_up(Keys.ENTER).perform();
print("Sucessfully uploaded meeting code.")
break
except selenium.common.exceptions.NoSuchElementException:
print("[ERROR]: Attempting to upload meeting code...")
if USE_FAILSAFE_PERCAUTIONS: time.sleep(6)
else: driver.implicitly_wait(6)
time.sleep(7) # Ensure that the browser fully loads the next part.
for i in range(6):
try:
WebDriverWait(driver, 6).until(EC.presence_of_element_located((By.XPATH, "//span[contains(text(),'Join now')]")))
time.sleep(2)
turn_off_mic_action = ActionChains(driver)
turn_off_mic_action.key_down(Keys.CONTROL).send_keys("d").key_up(Keys.CONTROL).perform();
turn_off_camera_action = ActionChains(driver)
turn_off_camera_action.key_down(Keys.CONTROL).send_keys("e").key_up(Keys.CONTROL).perform();
print("Sucessfully found landmark...turned off camera and microphone.")
break
except selenium.common.exceptions.TimeoutException:
try:
WebDriverWait(driver, 6).until(EC.presence_of_element_located((By.XPATH, "//span[contains(text(),'Ask to join')]")))
time.sleep(2)
turn_off_mic_action = ActionChains(driver)
turn_off_mic_action.key_down(Keys.CONTROL).send_keys("d").key_up(Keys.CONTROL).perform();
turn_off_camera_action = ActionChains(driver)
turn_off_camera_action.key_down(Keys.CONTROL).send_keys("e").key_up(Keys.CONTROL).perform();
print("Sucessfully found landmark...turned off camera and microphone.")
break
except selenium.common.exceptions.TimeoutException:
print("[ERROR]: Attempting to find landmark...")
if USE_FAILSAFE_PERCAUTIONS: time.sleep(6)
else: driver.implicitly_wait(6)
try:
join_button = WebDriverWait(driver, 36).until(EC.presence_of_element_located((By.XPATH, "//span[contains(text(),'Join now')]")))
driver.execute_script("arguments[0].click();", join_button)
except selenium.common.exceptions.TimeoutException:
try:
join_button = WebDriverWait(driver, 36).until(EC.presence_of_element_located((By.XPATH, "//span[contains(text(),'Ask to join')]")))
driver.execute_script("arguments[0].click();", join_button)
except selenium.common.exceptions.TimeoutException:
print("Couldn't join Google Meet. Are you sure you have the right code?")
来源:https://stackoverflow.com/questions/64793334/join-google-meet-meetings-automatically