-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpercifiak.py
177 lines (112 loc) · 4.42 KB
/
percifiak.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
from selenium import webdriver
from Tools import Tools
from time import sleep
import os
import sys
import getopt
import json
# Lancement d'un webdriver
def init_webdriver(debug, firefox_location)-> webdriver:
if not debug:
os.environ['MOZ_HEADLESS'] = '1'
# Les options du navigateur, ici Firefox
# l'emplacement du navigateur
options = webdriver.FirefoxOptions()
options.binary_location = firefox_location
# Lancement du browser
# Options : -> emplacement exécutable geckodriver
# -> emplacement logs geckodriver
# -> options du navigateur
browser = webdriver.Firefox(
executable_path='selenium/geckodriver.exe', service_log_path='selenium/geckodriver.log', options=options)
# browser.maximize_window()
return browser
def usage():
print("Pour que l'outil se lance correctement, il faut définir au premier lancement :")
print(" - Le nom d'utilisateur (exemple : jean.dupont@gmail.com)")
print(" - Le mot de passe associe (exemple : tonmeilleurmotdepasse)")
print(" - La location de l'exe de firefox (exemple : C:/Program Files/Mozilla Firefox/firefox)")
print("Ces informations sont stockees dans le fichier conf.json")
print("Vous n'aurez pas à les remplir à chaque utilisation\n")
print("-h --help Affiche l'aide")
print("-u --username Met à jour le nom d'utilisateur")
print("-p --password Met à jour le mot de passe de l'utilisateur")
print("-b --browser Met à jour la location de l'exe de firefox")
print("-d --debug Affiche la fenetre du navigateur")
sys.exit()
def main():
# Vérification des arguments passés dans la ligne de commande
try:
opts, args = getopt.getopt(sys.argv[1:], "u:p:b:hd", ["user=", "password=", "browser=", "debug", "help"])
except getopt.GetoptError as err:
# print help information and exit:
print(err)
usage()
sys.exit()
# Argument optionnel
debug = False
# Argument obligatoire
usr = ''
pwd = ''
browser_location = ''
for o, a in opts:
if o in ("-d", "--debug"):
debug = True
elif o in ("-h", "--help"):
usage()
elif o in ("-u", "--user"):
usr = a
elif o in ("-p", "--password"):
pwd = a
elif o in ("-b", "--browser"):
browser_location = a
else:
assert False, "unhandled option"
with open("conf.json", "r") as jsonFile:
conf = json.load(jsonFile)
if usr != '':
conf["username"] = usr
if pwd != '':
conf["password"] = pwd
if browser_location != '':
conf["browser"]["location"] = browser_location
with open("conf.json", "w") as jsonFile:
json.dump(conf, jsonFile)
if conf["browser"]["location"] == '' or conf["password"] == '' or conf["username"] == '':
print("Il manque un element a configurer : nom d'utilisateur, mot de passe ou la location du navigateur")
sys.exit()
browser = init_webdriver(debug, conf["browser"]["location"])
tools = Tools(browser)
tools.connection(conf["username"], conf["password"])
tools.go_to_assignement()
sleep(2)
courses, videos = tools.get_all_cours()
sleep(1)
for video in videos:
print("Début video : " + video)
tools.get_video(video)
tools.launch_video()
while browser.find_element_by_xpath("//div[@class='jw-icon jw-icon-inline "
"jw-button-color jw-reset jw-icon-playback']").get_attribute('aria-label') \
!= 'Play':
sleep(10)
print("Fin video : " + video)
for course in courses:
print("Début du cours : " + course)
tools.get_cours(course)
sleep(1)
tools.launch_video()
sleep(1)
# Tant que le cours n'est pas fini
while tools.get_completion_status() is False:
sleep(5)
print("Fin du cours : " + course)
test_url = tools.check_for_test()
if test_url != '':
browser.get(test_url)
tools.passing_test()
print('Tout les cours sont fini !')
# Fin du programme
browser.quit()
if __name__ == "__main__":
main()