-
Notifications
You must be signed in to change notification settings - Fork 3
/
main_calendar.py
73 lines (66 loc) · 2 KB
/
main_calendar.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
#!/usr/bin/env python
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from time import sleep
import sys
import requests
import paramiko
import subprocess
__author__ = "Pierre-Louis D'Agostino"
__email__ = "200197@umons.ac.be"
"""
VARIABLES GLOBALES
"""
# Adresse mail UMons (matricule@umons.ac.be)
user = ""
# Mot de passe UMons
passw = ""
"""
FIN DES VARS
"""
# Opening selenium webdriver
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
# Connection to gestac
try:
driver.get("https://gestacumons.umons.ac.be/login_ad.php?destination=student")
print("Connection...")
driver.find_element(By.ID, "username").send_keys(user)
driver.find_element(By.ID, "password").send_keys(passw)
driver.find_element(By.ID, "SubmitCreds").click()
except:
print("Username/password incorrect or geckodriver not installed")
sys.exit(1)
print("Finding schedule...")
try:
# Find schedule and download iCalendar
driver.get("https://gestacumons.umons.ac.be/MyUmons/mon_horaire.php")
driver.find_element(By.ID, "menu").click()
driver.find_elements(
By.PARTIAL_LINK_TEXT, "Télécharger")[0].click()
sleep(1)
matricule = user.split("@")[0]
url = "https://gestacumons.umons.ac.be/MyUmons/module_horaire/monIcalendar.php?fichier=" + matricule + ".ics"
cookies = driver.get_cookies()
s = requests.Session()
for cookie in cookies:
s.cookies.set(cookie['name'], cookie['value'])
except:
print("Schedule not found...")
sys.exit(1)
try:
print("Downloading...")
#fo = open(str(matricule)+'horaire.ics', 'wb')
fo = open('horaire.ics', 'wb')
fo.write(requests.get(url, cookies=s.cookies).content)
fo.close()
s.close()
driver.quit()
except:
print("Cannot download schedule...")
sys.exit(1)
print("Done !")