|
| 1 | +from selenium import webdriver |
| 2 | +import time |
| 3 | +import re |
| 4 | +# from pynput.keyboard import Controller |
| 5 | +from notify_run import Notify |
| 6 | + |
| 7 | + |
| 8 | +class AutoMeet(): |
| 9 | + usernameStr = None |
| 10 | + passwordStr = None |
| 11 | + url_meet = None |
| 12 | + options = None |
| 13 | + browser = None |
| 14 | + |
| 15 | + def __init__(self, username_string, password_string, url_of_meet,): |
| 16 | + self.usernameStr = username_string |
| 17 | + self.passwordStr = password_string |
| 18 | + self.url_meet = url_of_meet |
| 19 | + self.options = webdriver.ChromeOptions() |
| 20 | + self.options.add_argument("--disable-infobars") |
| 21 | + self.options.add_argument("--window-size=800,600") |
| 22 | + self.options.add_experimental_option("prefs", { |
| 23 | + "profile.default_content_setting_values.media_stream_camera": 2, |
| 24 | + "profile.default_content_setting_values.media_stream_mic": 2, |
| 25 | + # "profile.default_content_setting_values.geolocation": 2, |
| 26 | + "profile.default_content_setting_values.notifications": 2 |
| 27 | + }) |
| 28 | + self.browser = webdriver.Chrome(chrome_options=self.options) |
| 29 | + |
| 30 | + # ---------------Wrapper for Gmail ID And Non Gmail ID----------------- |
| 31 | + def automeetG(self): |
| 32 | + self.browser.get(('https://stackoverflow.com/')) |
| 33 | + # self.browser.find_element_by_xpath("/html/body/header/div/ol[2]/li[2]/a[2]").click() |
| 34 | + self.waiting_N_click("/html/body/header/div/ol[2]/li[2]/a[2]") |
| 35 | + # self.browser.find_element_by_xpath("//*[@id=\"openid-buttons\"]/button[1]").click() |
| 36 | + self.waiting_N_click("//*[@id=\"openid-buttons\"]/button[1]") |
| 37 | + username = self.browser.find_element_by_id('identifierId') |
| 38 | + username.send_keys(self.usernameStr) |
| 39 | + nextButton = self.browser.find_element_by_id('identifierNext') |
| 40 | + nextButton.click() |
| 41 | + time.sleep(15) # 5 |
| 42 | + # keyboard = Controller() |
| 43 | + # keyboard.type(passwordStr) |
| 44 | + password = self.browser.find_element_by_xpath("//input[@class='whsOnd zHQkBf']") |
| 45 | + password.send_keys(self.passwordStr) |
| 46 | + # keyboard.type(passwordStr) |
| 47 | + signInButton = self.browser.find_element_by_id('passwordNext') |
| 48 | + signInButton.click() |
| 49 | + time.sleep(5) # 3 |
| 50 | + self.browser.get(self.url_meet) |
| 51 | + time.sleep(10) # 6 |
| 52 | + element = self.browser.find_element_by_class_name('Ce1Y1c') |
| 53 | + self.browser.execute_script("arguments[0].click();", element) |
| 54 | + try: |
| 55 | + self.browser.find_element_by_xpath('//*[@id="yDmH0d"]/div[3]/div/div[2]/div[3]/div').click() |
| 56 | + try: |
| 57 | + self.browser.find_element_by_xpath("//span[@class='NPEfkd RveJvd snByac' and contains(text(), \ |
| 58 | + 'Ask to join')]").click() |
| 59 | + except BaseException: |
| 60 | + self.browser.find_element_by_xpath("//span[@class='NPEfkd RveJvd snByac' and contains(text(), \ |
| 61 | + 'Join now')]").click() |
| 62 | + except BaseException: |
| 63 | + try: |
| 64 | + self.browser.find_element_by_xpath("//span[@class='NPEfkd RveJvd snByac' and contains(text(), \ |
| 65 | + 'Ask to join')]").click() |
| 66 | + except BaseException: |
| 67 | + self.browser.find_element_by_xpath("//span[@class='NPEfkd RveJvd snByac' and contains(text(), \ |
| 68 | + 'Join now')]").click() |
| 69 | + # time.sleep(15) # Wasnt here |
| 70 | + # self.browser.find_element_by_xpath("//*[@id=\"ow3\"]/div[1]/div/div[4]/div[3]/div[6]/div[3]/div/div[2]/div[3]/span/span").click() |
| 71 | + self.waiting_N_click("//*[@id=\"ow3\"]/div[1]/div/div[4]/div[3]/div[6]/div[3]/div/div[2]/div[3]/span/span") |
| 72 | + currentStudents = 0 |
| 73 | + greatestStudents = 0 |
| 74 | + text_temp = "" |
| 75 | + final_text = "" |
| 76 | + while True: |
| 77 | + time.sleep(25) # reduce it later |
| 78 | + text = self.browser.find_element_by_xpath("/html/body/div[1]/c-wiz/div[1]/div/div[4]/div[3]/div[3]/ \ |
| 79 | + div/div[2]/div[2]/div[2]/span[2]/div/div[1]").text |
| 80 | + people = self.browser.find_element_by_xpath("/html/body/div[1]/c-wiz/div[1]/div/div[4]/div[3]/div[3]/ \ |
| 81 | + div/div[2]/div[2]/div[1]/div[1]").text |
| 82 | + # print(people) |
| 83 | + # print(text) |
| 84 | + final_text = text.replace(text_temp, "") |
| 85 | + # print(final_text) |
| 86 | + text_temp = text |
| 87 | + link = re.findall(r"(http|ftp|https)://([\w-]+(?:(?:.[\w-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?", |
| 88 | + final_text) |
| 89 | + if ("http" in final_text): |
| 90 | + notify = Notify() |
| 91 | + notify.send(link[0][0] + "://" + link[0][1], link[0][0] + "://" + link[0][1]) |
| 92 | + print(link[0][0] + "://" + link[0][1]) |
| 93 | + people_int = re.findall(r'[0-9]+', people) |
| 94 | + # print(people_int[0]) |
| 95 | + currentStudents = int(people_int[0]) |
| 96 | + if currentStudents > greatestStudents: |
| 97 | + greatestStudents = currentStudents |
| 98 | + else: |
| 99 | + if currentStudents < greatestStudents / 2: |
| 100 | + self.browser.close() |
| 101 | + break |
| 102 | + |
| 103 | + def waiting_N_click(self, path): |
| 104 | + try: |
| 105 | + self.browser.find_element_by_xpath(path).click() |
| 106 | + except BaseException: |
| 107 | + # print("1") |
| 108 | + time.sleep(2) |
| 109 | + self.waiting_N_click(path) |
0 commit comments