-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoconnect.py
72 lines (65 loc) · 2.64 KB
/
autoconnect.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
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options
#Ici mettre ses identifiants LDV
emailDevinci = '##########'
mdp = '#######'
#Lancement du navigateur
def init():
options = Options()
options.headless = False
return webdriver.Firefox(options=options)
#Connection au portail LDV
def connect(driver):
driver.get('https://www.leonard-de-vinci.net/') # loaded when `onload` even has fired
time.sleep(1)
driver.find_element_by_id("login").send_keys(emailDevinci)
driver.find_element_by_css_selector(".pull-right").click()
time.sleep(1)
driver.find_element_by_id('passwordInput').send_keys(mdp)
driver.find_element_by_css_selector("#submitButton").click()
def checking(driver):
time.sleep(1)
driver.get('https://www.leonard-de-vinci.net')
time.sleep(2)
#check if LDV is responding
if driver.find_element_by_xpath("//*[text()[contains(., 'Relevé de présence')]]"):
driver.find_element_by_xpath("//*[text()[contains(., 'Relevé de présence')]]").click()
time.sleep(1)
elif driver.find_element_by_xpath("//*[text()[contains(., 'Relevé de présence')]]"):
time.sleep(5)
btn = driver.find_element_by_xpath("//*[text()[contains(., 'Relevé de présence')]]")
btn.click()
time.sleep(1)
else:
return print('unable to get the ldv portail, system is having maintenance')
def getNumberOfLesson(driver):
#Check if got lessons today
if driver.find_elements_by_css_selector('tbody tr'):
cours = len(driver.find_elements_by_css_selector('tbody tr'))
return cours
else:
return print("Pas de cours aujourd'hui, go dodo ;)")
def getToPresencePage(cours, driver):
driver.get('https://www.leonard-de-vinci.net/student/presences/')
time.sleep(1)
ex = driver.find_elements_by_css_selector("tbody tr")
ex[cours].find_element_by_css_selector('a').click()
def main():
driver = init()
connect(driver)
while True:
checking(driver)
nbLessons = getNumberOfLesson(driver)
#Check which lessons the attendance can be taken
for cours in range(nbLessons):
getToPresencePage(cours, driver)
if len(driver.find_elements_by_css_selector("#set-presence")) > 0:
driver.find_element_by_id("set-presence").click()
return print("Je t'es mis présent pour ton cours ;) ")
else:
print(driver.find_elements_by_css_selector('#body_presence div')[0].get_attribute("innerHTML"))
driver.quit()
if __name__ == '__main__':
main()