def MANUAL(driver, data, test_blanc): if not (test_blanc): audio = test_Feature("sentenceAudioReader", driver) if test_Feature("popupContent", driver): try: driver.find_element_by_id("btn_fermer").click() except: print_debug("[BOT] FAILED TO EXECUTE FEATURE IN", "red") return "feature_in" else: audio = False try: Phrase = driver.find_element_by_class_name("sentence").text except: return "no_sentence" print_debug("[BOT] PHRASE: " + str(Phrase), "white") question = found_matche(Phrase, data) if question.matche != "": if audio: return question.corr_in_matche else: return question.err_in_phrase else: if audio: return "not_found" else: return "no_error" print(question.err_list) return question.err_list
def switch_bot(self): if self.bot_on: self.bot_on = False self.btn_auto["image"] = self.Auto_off elif self.module.data != []: self.bot_on = True self.btn_auto["image"] = self.Auto_on self.td = Thread(target=self.ROUTINE_BOT) self.td.start() else: self.log.insert("end", "erreur aucun fichier chargé\n", "red") print_debug("AUCUN FICHIER CHARGÉ", "red")
def memory_data(self, input_list): f = open("./file/auto_learning_data.txt", "r", encoding="utf-8") memory_data = f.read() memory_data_list = [] extr = " " i = 0 while extr != "": extr = memory_data[memory_data.find("[", i ):memory_data.find("]", i) + 1] memory_data_list += [extr] i = memory_data.find("\n", i + 1) memory_call = difflib.get_close_matches(str(input_list), memory_data_list) f.close() if memory_call != []: learning = difflib.get_close_matches( memory_data[memory_data.find(memory_call[0]) + len(memory_call[0]) + 1:memory_data. find("\n", memory_data.find(memory_call[0]))], input_list) if learning != []: print_debug("[auto_learning] found error in memory", "magenta") return input_list.index(learning[0]) else: print_debug("[auto_learning] no error found in memory", "magenta") return 0 else: print_debug("[auto_learning] no error found in memory", "magenta") return 0
def add_match(self, sentence, real_err): print_debug("[auto_learning] failed to found match, learning...", "yellow") f = open("./file/auto_learning_match.txt", "a", encoding="utf-8") sentence = " " + sentence try: sentence = sentence[:sentence.index( " " + real_err)] + " <@" + real_err + ">" + sentence[ sentence.index(" " + real_err) + len(real_err) + 1:] + "\n" except: try: sentence = sentence[:sentence.index( "'" + real_err)] + "'<@" + real_err + ">" + sentence[ sentence.index("'" + real_err) + len(real_err) + 1:] + "\n" except: sentence = sentence[:sentence.index( "-" + real_err)] + "-<@" + real_err + ">" + sentence[ sentence.index("-" + real_err) + len(real_err) + 1:] + "\n" f.write(sentence[1:]) f.close()
def found_matche(Phrase, data): matches = difflib.get_close_matches( Phrase, data) + auto_learning().memory_match(Phrase) print_debug("[found_matche] close matches: " + str(matches), "white") if matches != []: for i in range(0, len(matches)): if "<" in matches[i]: question = Question(Phrase, matches[i]) if question.err_in_phrase != "": print_debug( "[found_matche] CLOSE MATCH FOUND: " + str(matches[i]), "white") print_debug( "[found_matche] ERROR: " + str(question.err_in_phrase), "green") return question print_debug("[found_matche] NO CLOSE MATCH FOUND", "white") print_debug("[found_matche] NO ERROR", "green") return Question(Phrase, "")
def init(): open("./file/DEBUG.txt", "w", encoding="utf-8").close() try: option = chrome_options() option.add_argument("--headless") v_driver = webdriver.Chrome(options=option) except: print_debug("[v_driver] don't detect Chrome", "yellow") try: option = firefox_options() option.add_argument("--headless") v_driver = webdriver.Opera(options=option) except: print_debug("[v_driver] don't detect Opera", "yellow") try: option = opera_options() option.add_argument("--headless") v_driver = webdriver.Firefox(options=option) except: print_debug("[v_driver] CANT FIND COMPATIBLE DRIVER -> EXIT", "red") e = pop_up( "/msg{-txt:aucun moteur\n de recherche detecté \n(chrome, opera ou firefox) -title:VoltaireTaMere -link:https://www.google.com/intl/fr_fr/chrome/ -lock:0 -size:180x90}" ) e.start_root() e.root.mainloop() exit() return v_driver.get("https://sites.google.com/view/voltairetamere/init") v_driver.implicitly_wait(1) init_command = v_driver.find_element_by_class_name("yaqOZd").text print("init_command:", init_command) v_driver.close() if init_command[init_command.index("version:") + 8:] != found_data( "./file/version.txt", "version", "str"): init_command = "/msg{-txt:VoltaireTaMere doit être\n mis à jour -title:VoltaireTaMere -link:https://sites.google.com/view/voltairetamere/accueil -lock:1 -size:180x70}" if init_command != "version:" + found_data("./file/version.txt", "version", "str"): w = pop_up(init_command) w.start_root() w.root.mainloop() if w.option.lock: exit()
from GUI import GUI, Login from File import print_debug, found_data, connect from init import init, pop_up from selenium import webdriver from os import path import subprocess init() try: ch_output = subprocess.Popen(["chromedriver"]) driver = webdriver.Chrome() except: print_debug("[DRIVER] don't detect Chrome", "yellow") driver.implicitly_wait(1) if open("./file/log.txt","r", encoding="utf-8").read() == "" or open("./file/log.txt","r", encoding="utf-8").read() == "None": Login(driver).root.mainloop() else: connect(driver) gui = GUI(driver) gui.Menu_1(gui.BG1) gui.root.mainloop()
def add_data(self, list_err, real_err): print_debug("[auto_learning] failed to locate error, learning...", "yellow") f = open("./file/auto_learning_data.txt", "a", encoding="utf-8") f.write(str(list_err) + " " + real_err + "\n") f.close()
def find_err(self): if self.matche == "": print_debug("[find_err] No Close Match", "yellow") return "" Words_err = "" extrt = " " i = 0 while extrt != "": extrt = self.matche[self.matche.find("<", i):self.matche. find(">", i)].replace("<", "").replace(">", "") try: if self.matche[self.matche.find(">", i) + 1] == "-": extrt += "-" except: None i = self.matche.find(">", i) + 1 if extrt != "" and extrt not in Words_err: Words_err += extrt + " " Words_err = split_Word(Words_err) list_String_Err = split_Word(self.phrase) list_String_Corr = split_Word( self.matche.replace("<", "").replace(">", "")) print_debug("[find_err] err: " + str(Words_err), "cyan") print_debug("[find_err] phrase: " + str(list_String_Err), "cyan") print_debug("[find_err] matche: " + str(list_String_Corr), "cyan") for i in range(0, len(list_String_Corr)): if list_String_Corr[i] in list_String_Err: list_String_Err[list_String_Err.index( list_String_Corr[i])] = "" list_String_Corr[i] = "" list_String_Err = [ list_String_Err[i] for i in range(0, len(list_String_Err)) if list_String_Err[i] != "" ] list_String_Corr = [ list_String_Corr[i] for i in range(0, len(list_String_Corr)) if list_String_Corr[i] != "" ] for i in range(0, len(list_String_Corr)): if list_String_Corr[i].replace("…", "") not in Words_err: print_debug("[find_err] Words_err: " + str(Words_err), "cyan") print_debug( "[find_err] list_String_Corr: " + str(list_String_Corr), "cyan") print_debug( "[find_err] list_String_Err: " + str(list_String_Err), "cyan") print_debug("[find_err] Close Match INCORRECT\n", "yellow") return "" if list_String_Corr == [] and list_String_Err == []: print_debug("[find_err] Close Match INCORRECT\n", "yellow") return "" print_debug("[find_err] Close Match CORRECT", "green") if list_String_Err == []: list_String_Err = Words_err if "'" in list_String_Err[0]: try: list_String_Err[0] = list_String_Err[1] except: list_String_Err[0] = list_String_Err[0][0:list_String_Err[0]. find("'")] if "-" in list_String_Err[0]: list_String_Err[0] = list_String_Err[0][0:list_String_Err[0]. find("-")] print_debug("[find_err] Words_err: " + str(Words_err), "cyan") print_debug("[find_err] list_String_Corr: " + str(list_String_Corr), "cyan") print_debug("[find_err] list_String_Err: " + str(list_String_Err), "cyan") self.err_list = list_String_Err if len(list_String_Err) > 1: return list_String_Err[auto_learning().memory_data( list_String_Err)] else: return list_String_Err[0]
def print_class(self): print_debug("[Question] phrase:" + self.phrase, "white") print_debug("[Question] match:" + self.matche, "white") print_debug("[Question] corr_in_matche" + self.corr_in_matche, "white") print_debug("[Question] err_in_phrase" + self.err_in_phrase, "white")
def BOT(driver, data, test_blanc, accr): print_debug("[BOT] ####### WORKING #######", "white") if not (test_blanc): audio = test_Feature("sentenceAudioReader", driver) if test_Feature("popupContent", driver): try: driver.find_element_by_id("btn_fermer").click() except: print_debug("[BOT] FAILED TO EXECUTE FEATURE IN", "red") return "feature_in" else: audio = False try: Phrase = driver.find_element_by_class_name("sentence").text except: return "no_sentence" print_debug("[BOT] PHRASE: " + str(Phrase), "white") question = found_matche(Phrase, data) if randint(1, 100) > accr and not (audio): if question.matche != "": if not (test_blanc): driver.find_element_by_id("btn_pas_de_faute").click() else: driver.find_elements_by_xpath( "//span[@class = 'pointAndClickSpan'][.='" + split_Word(question.phrase)[0] + "']")[0].click() return ["auto_fail"] if question.matche != "": if audio: driver.find_element_by_xpath( "//input[@class='gwt-TextBox writingExerciseSpan']").send_keys( question.corr_in_matche.replace("@", "")) driver.find_element_by_id("btn_pas_de_faute").click() print_debug("[BOT] EXECUTION AUDIO DONE", "green") else: try: driver.find_elements_by_xpath( "//span[@class = 'pointAndClickSpan'][.='" + question.err_in_phrase + "']")[found_good_one( question.phrase, question.matche, question.err_in_phrase)].click() print_debug("[BOT] EXECUTION CLICK DONE", "green") except: if "…" in question.err_in_phrase: driver.find_elements_by_xpath( "//span[@class = 'pointAndClickSpan'][.='" + question.err_in_phrase.replace("…", "") + "']")[found_good_one( question.phrase, question.matche, question.err_in_phrase.replace("…", ""))].click() else: print_debug( "[BOT] FAILED TO EXECUTE CAN'T TOUCH: " + str(question.err_in_phrase), "red") return "can't_touche &" + str(question.err_in_phrase) else: if audio: print_debug("[BOT] FAILED TO EXECUTE NO MATCH FOUND\n", "yellow") return "not_found" else: try: driver.find_element_by_class_name("noMistakeButton").click() print_debug("[BOT] EXECUTION NO MISTAKE DONE", "green") except: return [] print(question.err_list) return question.err_list
def ROUTINE_BOT(self): if self.accuracy.get() < 0: self.accuracy.set(0) write_data("./file/options.txt", "accuracy", 0) print_debug("[option] accuracy valeur interdite", "red") if self.time_next.get() < 1: self.time_next.set(1) write_data("./file/options.txt", "time", 1) print_debug("[option] time valeur interdite", "red") while self.bot_on: self.log.delete(1.0, "end") return_tag = BOT(self.driver, self.module.data, self.module.test_blanc, self.accuracy.get()) print_debug("return_tag: " + str(return_tag) + "\n", "yellow") if type(return_tag) != list: if return_tag == "feature_in": self.log.insert("end", "Merci de fermer la Pop-up\n", "yellow") elif "can't_touche" in return_tag: self.log.insert( "end", "Je n'arrive pas a toucher: " + return_tag[return_tag.index("&") + 1:len(return_tag)] + "\n", "yellow") elif return_tag == "not_found": self.log.insert("end", "je trouve pas sorry UwU\n", "yellow") break self.number_q += 1 if self.module.test_blanc == False: if self.driver.find_elements_by_xpath( "//span[@title='Mauvaise réponse']" ) != [] and return_tag != ["auto_fail"]: text = '' answer_word_els = self.driver.find_elements_by_xpath( "//span[@class = 'answerWord']/span[@class = 'pointAndClickSpan']" ) if len(answer_word_els) >= 1: text = answer_word_els[1].text else: text = answer_word_els[0].text or "" if return_tag == []: auto_learning().add_match( self.driver.find_element_by_class_name( "sentence").text, text) else: auto_learning().add_data(return_tag, text) self.log.insert("end", "erreur détéctée apprentissage...\n", "green") try: self.driver.find_element_by_class_name( "nextButton").click() except Exception: pass self.log.insert("end", "[" + str(self.number_q) + "]: Clique fait !\n", "green") self.log.insert( "end", open("./file/VTMtext.txt", "r", encoding="utf-8").read()) self.log.insert("end", "\n\nWaiting...\n", "green") i = 0 while i < self.time_next.get() and self.bot_on: sleep(1) i += 1 self.bot_on = False self.btn_auto["image"] = self.Auto_off self.time_next.set(found_data("./file/options.txt", "time", "int")) print_debug( "[BOT_ROUTINE] I am a bot, and this action was performed automatically.\nI answered " + str(self.number_q) + " questions", "green") self.log.insert( "end", "I am a bot, and this action was performed automatically.\nI answered " + str(self.number_q) + " questions\n", "green") self.number_q = 0 return 0
def __init__(self, driver): self.root = Tk() self.root.title("VoltaireTaMere") self.root.resizable(False, False) self.root.geometry('600x350') self.root.iconphoto( True, PhotoImage(file="asset/VoltaireTaMere_icon[PNG].png")) self.root.configure(bg='#23272A') self.Auto_off = PhotoImage(file="asset/Boutton_Auto_off.png") self.Auto_on = PhotoImage(file="asset/Boutton_Auto_on.png") self.Manual = PhotoImage(file="asset/Boutton_Manuel.png") self.back = PhotoImage(file="asset/Boutton_Retour.png") self.load_file = PhotoImage(file="asset/Boutton_Load.png") self.Quitter = PhotoImage(file="asset/boutton_Quitter.png") self.BG1 = PhotoImage(file="asset/Menu_1.png") self.BG2 = PhotoImage(file="asset/Menu_2.png") self.BG3 = PhotoImage(file="asset/Menu_3.png") self.driver = driver self.module = Module("") self.bot_on = False self.accuracy = IntVar() self.time_next = IntVar() self.accuracy.set(found_data("./file/options.txt", "accuracy", "int")) self.time_next.set(found_data("./file/options.txt", "accuracy", "int")) self.number_q = 0 self.prgm = StringVar() self.niveau = StringVar() self.fond = Label(self.root, image=None, bg='#23272A') self.btn_pont_sup = Button( self.root, text="PONT\nSUPÉRIEUR", command=lambda: [ self.prgm.set("pont_Supérieur"), self.niveau. set("Module\\ 1 Module\\ 2 Module\\ 3 Module\\ 4 Module\\ 5 Module\\ 6 Module\\ 7 Module\\ 8 Test\\ Blanc" ), self.Menu_Unpack(), self.Menu_2(self.BG2) ], bg="#a2d417", highlightthickness=2, bd=0, height=6, width=12, font=('Helvetica', '10', "bold")) self.btn_sup = Button( self.root, text="SUPÉRIEUR", command=lambda: [ self.prgm.set("Supérieur"), self.niveau. set("Module\\ 1 Module\\ 2 Module\\ 3 Module\\ 4 Module\\ 5 Module\\ 6 Module\\ 7 Module\\ 8 Module\\ 9 Module\\ 10 Test\\ Blanc" ), self.Menu_Unpack(), self.Menu_2(self.BG2) ], bg="#a2d417", highlightthickness=2, bd=0, height=6, width=12, font=('Helvetica', '10', "bold")) self.btn_exc = Button( self.root, text="EXCELLENCE", command=lambda: [ self.prgm.set("Excellence"), self.niveau. set("Module\\ 1 Module\\ 2 Module\\ 3 Module\\ 4 Module\\ 5 Module\\ 6 Module\\ 7 Module\\ 8 Module\\ 9 Module\\ 10 Module\\ 11 Module\\ 12 Verbes\\ Pronominaux\\ II" ), self.Menu_Unpack(), self.Menu_2(self.BG2) ], bg="#a2d417", highlightthickness=2, bd=0, height=6, width=12, font=('Helvetica', '10', "bold")) self.btn_cus = Button(self.root, text="CUSTOM", bg="#a2d417", command=lambda: [ self.prgm.set("CUS"), self.niveau.set(""), self.Menu_Unpack(), self.Menu_3(self.BG3) ], activebackground="#ffffff", bd=0, height=6, width=12, font=('Helvetica', '10', "bold")) self.btn_auto = Button(self.root, image=self.Auto_off, command=self.switch_bot, bg="#a2d417", activebackground="#a2d417", bd=0) self.btn_manual = Button( self.root, image=self.Manual, command=lambda: Thread(target=self.ROUTINE_MANUAL).start(), bg="#23272A", activebackground="#23272A", bd=0) self.btn_load_file = Button(self.root, image=self.load_file, command=self.init_module, bg="#23272A", activebackground="#23272A", bd=0) self.btn_back = Button( self.root, image=self.back, command=lambda: [self.Menu_Unpack(), self.Menu_1(self.BG1)], bg="#23272A", activebackground="#23272A", bd=0) self.btn_quit = Button(self.root, image=self.Quitter, command=self.root.destroy, bg="#23272A", activebackground="#23272A", bd=0) self.listB_Module = Listbox(self.root, exportselection=0, listvariable=self.niveau, selectmode="single", activestyle="none", height=14, width=21, bd=0, bg="#2C2F33", fg="#ffffff", selectbackground="#a2d417", font=('Helvetica', '10')) self.log = Text(self.root, height=12, width=47, bg="#2C2F33", fg="#ffffff", bd=0, font=('Helvetica', '10')) self.log.tag_config("green", foreground="#40ff46") self.log.tag_config("red", foreground="#ff4040") self.log.tag_config("yellow", foreground="#f5ff40") self.log.tag_config("cyan", foreground="#00ffff") self.log.tag_config("magenta", foreground="#ff00ff") self.log.tag_config("white", foreground="#ffffff") self.menuAide = Menubutton(self.root, text='Aide', width='6', fg='#ffffff', bg='#2c2e30', activebackground='#a2d417', bd=0) self.SousMenuAide = Menu(self.menuAide, fg='#ffffff', bg='#2c2e30', activebackground='#a2d417') self.SousMenuAide.add_command( label='Notice', command=lambda: open_file("./file/NOTICE.pdf")) self.SousMenuAide.add_command( label='réinitialiser Login', command=lambda: [Login(self.driver, self.root)]) self.menuAide.configure(menu=self.SousMenuAide) self.menuOption = Menubutton(self.root, text='Option', width='6', fg='#ffffff', bg='#2c2e30', activebackground='#a2d417', bd=0) self.SousMenuOption = Menu(self.menuOption, fg='#ffffff', bg='#2c2e30', activebackground='#a2d417') self.SousMenuOption.add_command( label='OverClock', command=lambda: [ self.time_next.set(1), print_debug("[MAIN] Overclock ON", "yellow"), self.log.insert("end", "Overclock ON\n", "yellow") ]) self.SousMenuOption.add_command( label='options', command=lambda: [self.Menu_Unpack(), self.Menu_4()]) self.menuOption.configure(menu=self.SousMenuOption) self.option_auto_login = Button( self.root, text="auto login", command=lambda: [ self.log.delete(1.0, "end"), self.input_data.place_forget(), self.log.insert( "end", "L'auto login permet de se connecter automatiquement a son compte projet voltaire lors du démarage" ), self.switch_auto_login.place(x=320, y=30) ], bg="#a2d417", highlightthickness=2, bd=0, height=2, width=20, font=('Helvetica', '10')) self.option_accuracy = Button( self.root, text="précision", command=lambda: [ self.switch_auto_login.place_forget(), self.log.delete(1.0, "end"), self.set_accurate_buffer(), self.input_data.place(x=320, y=30), self.log.insert("end", "Définit le pourcentage de bonnes réponses") ], bg="#a2d417", highlightthickness=2, bd=0, height=2, width=20, font=('Helvetica', '10')) self.option_time = Button( self.root, text="temps d'attente", command=lambda: [ self.switch_auto_login.place_forget(), self.log.delete(1.0, "end"), self.set_time_buffer(), self.input_data.place(x=320, y=30), self.log.insert( "end", "définit le temps d'attente entre chaque question") ], bg="#a2d417", highlightthickness=2, bd=0, height=2, width=20, font=('Helvetica', '10')) self.switch_auto_login = Button(self.root, text="", command=None, bg="#a2d417", highlightthickness=2, bd=0, height=1, width=10, font=('Helvetica', '10')) self.time_buffer = StringVar() self.time_buffer.set(found_data("./file/options.txt", "time", "int")) self.accurate_buffer = StringVar() self.accurate_buffer.set( found_data("./file/options.txt", "accuracy", "int")) self.input_data = Entry(self.root, textvariable=None, bg="#2C2F33", fg="#ffffff", width=11, bd=1, font=('Helvetica', '10'))