-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.py
108 lines (70 loc) · 3.41 KB
/
functions.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
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from twilio.rest import Client
# push notifications
from spontit import SpontitResource
import time
import smtplib
import settings
resource = SpontitResource(settings.SPONTIT_USERNAME, settings.SPONTIT_SECCRET_KEY)
def login(driver):
email = settings.PARENT_ACCESS_EMAIL
password = settings.PARENT_ACCESS_PASSWORD
driver.get("https://parents.ebnet.org/genesis/sis/view?gohome=true")
# find login fields
parent_access_email = driver.find_element(By.XPATH, '//*[@id="j_username"]')
parent_access_password = driver.find_element(By.XPATH, '//*[@id="j_password"]')
parent_access_email.send_keys(email)
parent_access_password.send_keys(password)
parent_access_password.send_keys(Keys.ENTER)
# switch siblings
driver.get("https://parents.ebnet.org/genesis/parents?tab1=studentdata&tab2=gradebook&tab3=weeklysummary&studentid=" + settings.STUDENT_ID + "&action=form")
pushSpointit("logged in")
# wait for page to load before finding elements
time.sleep(2)
def getInitialGrades(driver, classes, initialGrades):
for subject in settings.classes:
intialGrade = driver.find_element(By.XPATH, settings.classes[subject]).text
initialGrades[subject] = intialGrade
print(initialGrades)
def logout(driver):
driver.get("https://parents.ebnet.org/genesis/parents?logout=true")
def sendNotification(method, gradeChangedMessage):
if(method.lower() == "sms"):
try:
client = Client(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN)
message = client.messages.create(
to = settings.DESTINATION_PHONE_NUMBER,
from_ = settings.TWILIO_PHONE_NUMBER,
body = gradeChangedMessage)
print(gradeChangedMessage + " sent to " + settings.DESTINATION_PHONE_NUMBER)
except Exception as e:
print(e)
elif (method.lower() == "email"):
try:
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.ehlo()
server.login(settings.GMAIL_ACCOUNT_EMAIL, settings.GMAIL_ACCOUNT_PASSWORD)
server.sendmail(settings.GMAIL_ACCOUNT_EMAIL, settings.PHONE_NUMBER_EMAIL, gradeChangedMessage)
server.close()
print(gradeChangedMessage + " sent to " + settings.PHONE_NUMBER_EMAIL)
except Exception as e:
print(e)
elif (method.lower() == "push"):
pushSpointit(gradeChangedMessage)
def checkAndUpdateGrades(driver, previousGrades):
driver.get("https://parents.ebnet.org/genesis/parents?tab1=studentdata&tab2=gradebook&tab3=weeklysummary&studentid=" + settings.STUDENT_ID + "&action=form")
for subject in settings.classes:
previousGrade = previousGrades[subject]
newGrade = driver.find_element(By.XPATH, settings.classes[subject]).text
# if grade changed
if(previousGrade != newGrade):
print(subject + " grade changed from " + str(previousGrade) + " to " + str(newGrade))
sendNotification(settings.NOTIFICATION_METHOD, subject + " grade changed from " + str(previousGrade) + " to " + str(newGrade))
previousGrades[subject] = newGrade
print("checked - grades not changed")
sendNotification(settings.NOTIFICATION_METHOD, subject + " grade not changed, still is " + str(newGrade))
def pushSpointit(message):
response = resource.push(message)