-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgmeet_bot.py
127 lines (118 loc) · 4.35 KB
/
gmeet_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
from selenium import webdriver
from time import sleep
from configparser import ConfigParser
from datetime import datetime
import csv
config = ConfigParser()
config.read('config.ini')
username = config.get('AUTH', 'USERNAME')
password = config.get('AUTH', 'PASSWORD')
firefox_profile_path = config.get('FIREFOX', 'PROFILE_PATH')
classTime = []
class ClassAutomation():
def __init__(self):
self.getClasstime()
self.count = 0
self.findCount()
#Runs endlessly and calls initClass method when it's class time
while True:
if datetime.now().strftime("%H:%M") in classTime:
print(datetime.now().strftime("%H:%M"))
self.initClass()
sleep(30)
#Reads class timings from the schedule.csv
def getClasstime(self):
with open('schedule.csv','r') as csvFile:
reader = csv.DictReader(csvFile)
for row in reader:
for i in row:
classTime.append(i)
classTime.pop(0)
break
#Initiates Class
def initClass(self):
className = self.findClass()
if className is None:
return
print("Initiating...")
self.login()
self.driver.find_element_by_xpath("//div[text()='{}']".format(className)).click()
sleep(10)
link=self.driver.find_element_by_partial_link_text("https://meet.google.com/lookup/").text
self.driver.get(link)
sleep(10)
self.driver.find_element_by_xpath("//span[text()='Join now']").click()
sleep(60*60)
print("Quitting...")
sleep(5)
self.driver.quit()
if self.count < 2:
self.count = self.count + 1
else:
self.count = 0
self.findCount()
#Returns the ClassName for the current time
def findClass(self):
with open("schedule.csv","r") as csvFile:
reader = csv.DictReader(csvFile)
for row in reader:
if row["Day"]==datetime.now().strftime("%a"):
return row[classTime[self.count]]
return None
#Determines the current time position in the classTime list
def findCount(self):
if self.findClass() is None:
print("No Class Today")
return
currentTime=datetime.now().strftime("%H:%M")
currentHour = int(currentTime.split(":")[0])
currentMin = int(currentTime.split(":")[1])
for i in classTime:
if currentHour==int(i.split(":")[0]) and currentMin<int(i.split(":")[1]):
self.count = classTime.index(i)
print("Next Class at",classTime[self.count],"Today")
break
elif currentHour<int(i.split(":")[0]):
self.count = classTime.index(i)
print("Next Class at",classTime[self.count],"Today")
break
else:
if classTime.index(i)==2:
self.count=0
print("Next Class at",classTime[self.count],"Tomorrow")
break
continue
#Logs into the google classroom with the account credentials
def login(self):
profile = webdriver.FirefoxProfile(firefox_profile_path)
self.driver = webdriver.Firefox(profile)
self.driver.get("https://accounts.google.com/")
sleep(2)
try:
self.driver.find_element_by_name("identifier").send_keys(username)
sleep(1)
except:
self.driver.find_element_by_name("Email").send_keys(username)
sleep(1)
try:
self.driver.find_element_by_id("identifierNext").click()
sleep(4)
except:
self.driver.find_element_by_id("next").click()
sleep(4)
try:
self.driver.find_element_by_name("password").send_keys(password)
sleep(1)
except:
self.driver.find_element_by_name("Passwd").send_keys(password)
sleep(1)
try:
self.driver.find_element_by_id("passwordNext").click()
sleep(4)
except:
self.driver.find_element_by_id("trustDevice").click()
self.driver.find_element_by_id("submit").click()
sleep(4)
self.driver.get("https://classroom.google.com/")
sleep(6)
ClassAutomation()