improved error logging and fixed some typo issues

This commit is contained in:
piair 2022-02-17 14:20:44 +01:00
parent 793e3c9b6b
commit 9bcfe14527
1 changed files with 18 additions and 21 deletions

39
V4.py
View File

@ -246,10 +246,7 @@ def PlayQuiz8(override = None):
if 'iscorrectoption="True" 'in Card.get_attribute('outerHTML') : if 'iscorrectoption="True" 'in Card.get_attribute('outerHTML') :
ListeOfGood.append(f'rqAnswerOption{i-1}') #premier div = 3 ? ListeOfGood.append(f'rqAnswerOption{i-1}') #premier div = 3 ?
except Exception as e : except Exception as e :
if override : LogError("playquiz8 - 1 - " + e)
LogError(e)
else :
LogError(e)
shuffle(ListeOfGood) shuffle(ListeOfGood)
for i in ListeOfGood : for i in ListeOfGood :
@ -263,15 +260,15 @@ def PlayQuiz8(override = None):
try : try :
driver.execute_script("arguments[0].click();", elem) driver.execute_script("arguments[0].click();", elem)
except Exception as e : except Exception as e :
LogError(e) LogError("playquizz8 - 2 - " + e)
except Exception as e : except Exception as e :
if override : if override :
printf(e) printf("playquiz8 - 3 -" +e)
else : else :
LogError(e) LogError("playquizz8 - 3 - " + e)
except Exception as e : except Exception as e :
LogError("PlayQuiz8" + str(e) + str(ListeOfGood)) LogError("PlayQuiz8 - 4 - " + str(e) + str(ListeOfGood))
def PlayQuiz4(override = None): def PlayQuiz4(override = None):
@ -371,7 +368,7 @@ def AllCard(): #fonction qui clique sur les cartes
titre = driver.title titre = driver.title
except Exception as e : except Exception as e :
titre = "inconnu" titre = "inconnu"
LogError(f"impossible de recuperer le titre. {e}") LogError(f"Allcards - impossible de recuperer le titre. {e}")
TryPlay(titre) TryPlay(titre)
reset(True) reset(True)
@ -424,12 +421,12 @@ def login() :
try : try :
driver.find_element(By.ID, 'KmsiCheckboxField').click() driver.find_element(By.ID, 'KmsiCheckboxField').click()
except Exception as e : except Exception as e :
printf(f"erreur validation bouton KmsiCheckboxField. pas forcement grave {e}") printf(f"login - 1 - erreur validation bouton KmsiCheckboxField. pas forcement grave {e}")
CustomSleep(5) CustomSleep(5)
try : try :
driver.find_element(By.ID, 'idSIButton9').click() driver.find_element(By.ID, 'idSIButton9').click()
except Exception as e : except Exception as e :
printf(f"erreur validation bouton idSIButton9. pas forcement grave {e}") printf(f"login - 2 - erreur validation bouton idSIButton9. pas forcement grave {e}")
printf("login completed") printf("login completed")
@ -441,7 +438,7 @@ def login() :
return(MainWindows) return(MainWindows)
except Exception as e: except Exception as e:
LogError(e) LogError("login - 3 - " +e)
def BingPcSearch(override = randint(35,40)): def BingPcSearch(override = randint(35,40)):
@ -486,7 +483,7 @@ def BingMobileSearch(override = randint(22,25)):
MobileDriver = FirefoxMobile(Os=hash(_mail)%10) #change device for each account MobileDriver = FirefoxMobile(Os=hash(_mail)%10) #change device for each account
except Exception as e : except Exception as e :
sleep(30) sleep(30)
LogError('echec de la creation du driver mobile') LogError('BingMobileSearch - 1 - echec de la creation du driver mobile')
MobileDriver = FirefoxMobile() MobileDriver = FirefoxMobile()
echec = 0 echec = 0
@ -572,7 +569,7 @@ def BingMobileSearch(override = randint(22,25)):
try : try :
MobileDriver.quit() MobileDriver.quit()
except Exception as e: except Exception as e:
LogError(f"can't close mobile driveerr . {e}") LogError(f"can't close mobile driveer . {e}")
def TryPlay(nom ="inconnu"): def TryPlay(nom ="inconnu"):
@ -602,7 +599,7 @@ def TryPlay(nom ="inconnu"):
except Exception as e : except Exception as e :
printf(f'echec de PlayQuiz 2. Aborted {e}') printf(f'echec de PlayQuiz 2. Aborted {e}')
else : else :
LogError('probleme dans la carte : il y a un bouton play et aucun quiz') LogError('probleme dans la carte : il y a un bouton play et aucun quiz detecté')
try : try :
driver.find_element(By.ID, 'rqStartQuiz').click() #start the quiz driver.find_element(By.ID, 'rqStartQuiz').click() #start the quiz
number = driver.page_source.count('rqAnswerOption') number = driver.page_source.count('rqAnswerOption')
@ -617,7 +614,7 @@ def TryPlay(nom ="inconnu"):
PlayPoll() PlayPoll()
print('Poll reussit ') print('Poll reussit ')
except Exception as e : except Exception as e :
printf(f'Poll aborted {e}') printf(f'TryPlay - 1 - Poll aborted {e}')
elif "rqQuestionState" in driver.page_source : elif "rqQuestionState" in driver.page_source :
try : try :
@ -626,7 +623,7 @@ def TryPlay(nom ="inconnu"):
printf(f"recovery détécté. quiz : {number}, restant : {restant +1}") printf(f"recovery détécté. quiz : {number}, restant : {restant +1}")
play(number, override=restant + 1 ) play(number, override=restant + 1 )
except Exception as e : except Exception as e :
printf(e) printf("TryPlay - 2 - " + e)
elif search("([0-9]) de ([0-9]) finalisée",driver.page_source) : elif search("([0-9]) de ([0-9]) finalisée",driver.page_source) :
print('fidélité') print('fidélité')
@ -651,7 +648,7 @@ def LogPoint(account="unknown"): #log des points sur discord
point = search(regex1, driver.page_source)[1].replace(',', '') point = search(regex1, driver.page_source)[1].replace(',', '')
except Exception as e : except Exception as e :
print(f"LogPoint : {e}") print(f"LogPoint - 1 - {e}")
elem = driver.find_element(By.CSS_SELECTOR, '[title="Microsoft Rewards"]') elem = driver.find_element(By.CSS_SELECTOR, '[title="Microsoft Rewards"]')
elem.click() elem.click()
@ -661,7 +658,7 @@ def LogPoint(account="unknown"): #log des points sur discord
try : try :
point = search("availablePoints\":([\d]+)",driver.page_source)[1] point = search("availablePoints\":([\d]+)",driver.page_source)[1]
except Exception as e : except Exception as e :
LogError(f"LogPoint : {e}") LogError(f"LogPoint - 2 - {e}")
point = "erreur" point = "erreur"
CustomSleep(uniform(3,20)) CustomSleep(uniform(3,20))
@ -779,7 +776,7 @@ def CustomStart(Credentials):
_mail =Credentials[choice1][0] _mail =Credentials[choice1][0]
_password = Credentials[choice1][1] _password = Credentials[choice1][1]
login()
if choice2 == 0 : if choice2 == 0 :
DailyRoutine() DailyRoutine()
elif choice2 == 1 : elif choice2 == 1 :
@ -801,7 +798,7 @@ def CustomStart(Credentials):
try : try :
LogPoint(_mail) LogPoint(_mail)
except Exception as e : except Exception as e :
print(e) print("CustomStart" + e)
with open(LogPath) as f: with open(LogPath) as f:
reader = reader(f) reader = reader(f)