This repository has been archived by the owner on Sep 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_english_sad_supinfo.py
executable file
·150 lines (105 loc) · 3.78 KB
/
check_english_sad_supinfo.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
#!/usr/bin/python3
import smtplib
import time
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from selenium import webdriver
IDBOOSTER = ""
SUPINFO_PASSWORD = ""
GMAIL_ADDRESS = ""
GMAIL_PASSWORD = ""
RECEIVER_ADDRESS = ""
BROWSER = ""
if "" in (IDBOOSTER, SUPINFO_PASSWORD, GMAIL_ADDRESS, GMAIL_PASSWORD, RECEIVER_ADDRESS, BROWSER):
print("Please run INSTALL.sh first !")
exit(1)
def check_available_slot(inner_html):
if "<span style=\"color: green;\">" in inner_html:
return True
else:
return False
def get_date(inner_html):
if "<span style=\"color: green;\">" not in inner_html:
return False
# Get the Year
i = inner_html.index("2018</strong>")
i_end = i + 4
# Get the month
while inner_html[i] != ">":
i -= 1
# Get the month and year
date = str(inner_html[i + 1:i_end])
# Get the time
i = inner_html.index("<span style=\"color: green;\">")
slot_time = inner_html[i + 28: i + 30] + "h to " + inner_html[i + 37: i + 39] + "h"
# Get the day number
i = inner_html.index("<span style=\"color: green;\">")
while inner_html[i:i + 18] != "<span class=\"day\">":
i += 1
# Add some text
date += " from " + slot_time
if inner_html[i + 19] == "<":
return str(inner_html[i + 18] + " " + date)
else:
return str(inner_html[i + 18:i + 20] + " " + date)
def send_mail(place_time):
msg = MIMEMultipart()
msg['From'] = GMAIL_ADDRESS
msg['To'] = RECEIVER_ADDRESS
msg['Subject'] = "[English - Check] " + str(len(place_time)) + " slot(s) available !"
body = "They are " + str(len(place_time)) + " slot(s) available on http://english.sad.supinfo.com/\n\n"
for slot_time in place_time:
body += "The " + slot_time + "\n\n"
msg.attach(MIMEText(body))
mail_server = smtplib.SMTP('smtp.gmail.com', 587)
mail_server.starttls()
mail_server.login(GMAIL_ADDRESS, GMAIL_PASSWORD)
mail_server.sendmail(GMAIL_ADDRESS, RECEIVER_ADDRESS, msg.as_string())
mail_server.quit()
def get_html_site():
if BROWSER == "firefox":
options = webdriver.FirefoxOptions()
options.add_argument("--headless")
browser = webdriver.Firefox(firefox_options=options)
elif BROWSER in ("chrome", "chromium"):
options = webdriver.ChromeOptions()
options.add_argument("--headless")
browser = webdriver.Chrome(chrome_options=options)
# Go to the English website
browser.get("http://english.sad.supinfo.com")
time.sleep(2)
# Find and input the IDBOOSTER
id_booster = browser.find_element_by_name("boosterId")
id_booster.send_keys(IDBOOSTER)
# Log in to the website
button = browser.find_element_by_xpath("//input[@value='Connexion']")
button.click()
time.sleep(2)
# Log in to the SSO
password = browser.find_element_by_id("Password")
password.send_keys(SUPINFO_PASSWORD)
button = browser.find_element_by_id("LoginButton")
button.click()
time.sleep(2)
# Go to the calendar tab
browser.get("http://english.sad.supinfo.com/student/calendar")
time.sleep(2)
return browser
def main():
browser = get_html_site()
slot_time = []
# Check for the current month and the 4 next ones
for i in range(5):
if i != 0:
next_month_button = browser.find_element_by_xpath("//*[contains(text(),'>')]")
next_month_button.click()
inner_html = browser.execute_script("return document.body.innerHTML")
if check_available_slot(inner_html):
slot_time.append(get_date(inner_html))
browser.quit()
if not slot_time:
print("Found " + str(len(slot_time)) + "slot(s) available !")
send_mail(slot_time)
else:
print("Nothing found ..."
main()