typo + better logic + WTF everything has failed today

This commit is contained in:
piair 2023-04-02 11:02:37 +02:00
parent f30832d8cd
commit ccf284f6e2
3 changed files with 31 additions and 36 deletions

45
V5.py
View File

@ -19,8 +19,6 @@ def printf(e, f = ""):
# check that each card worked (lot of misses lately) -- test that -- don't crash at least # check that each card worked (lot of misses lately) -- test that -- don't crash at least
# Fix l'affichage du compteur de custom_sleep # Fix l'affichage du compteur de custom_sleep
custom_sleep = CustomSleep
# create a webdriver # create a webdriver
def firefox_driver(mobile=False, headless=False): def firefox_driver(mobile=False, headless=False):
@ -217,7 +215,7 @@ def do_poll():
# finds all task to do, and launch them # finds all task to do, and launch them
def all_cards(): def all_cards(): # return to the main page and closes all other tabs
def reset(part2=False): def reset(part2=False):
if len(driver.window_handles) == 1: if len(driver.window_handles) == 1:
driver.get("https://www.bing.com/rewardsapp/flyout") driver.get("https://www.bing.com/rewardsapp/flyout")
@ -232,14 +230,19 @@ def all_cards():
driver.switch_to.window(driver.window_handles[0]) driver.switch_to.window(driver.window_handles[0])
reset(part2) reset(part2)
def daily_cards(): def daily_cards(): # cartes de la premiere partie (renouvelées chaque jours).
try: try:
# make sure that the daily area is expanded
row_element = driver.find_element(By.XPATH, "/html/body/div/div/div[3]/div[2]/div[1]/div[1]")
expanded = row_element.get_attribute("aria-expanded")
if expanded != "true":
row_element.click()
for i in range(3): for i in range(3):
custom_sleep(uniform(3, 5)) custom_sleep(uniform(3, 5))
try: try:
titre = "erreur" titre = "Placeholder"
driver.find_element( driver.find_element(
By.XPATH,f"/html/body/div/div/div[3]/div[2]/div[1]/div[2]/div/div[{i+1}]/a/div/div[2]", By.XPATH,f"/html/body/div/div/div[3]/div[2]/div[1]/div[2]/div/div[{i+1}]/a",
).click() ).click()
sleep(1) sleep(1)
titre = driver.title titre = driver.title
@ -248,7 +251,7 @@ def all_cards():
reset() reset()
printf(f"DailyCard {titre} ok") printf(f"DailyCard {titre} ok")
except Exception as e: except Exception as e:
printf(f"all_cards card {titre} error ({e})") log_error(f"all_cards card {titre} error ({format_error(e)})")
try : # devrait renvoyer vrai si la carte i est faite ou pas, a l'aide su symbole en haut a droite de la carte try : # devrait renvoyer vrai si la carte i est faite ou pas, a l'aide su symbole en haut a droite de la carte
elm = driver.find_element(By.XPATH, f"/html/body/div/div/div[3]/div[2]/div[1]/div[2]/div/div[{i+1}]/a/div/div[2]/div[1]/div[2]/div") elm = driver.find_element(By.XPATH, f"/html/body/div/div/div[3]/div[2]/div[1]/div[2]/div/div[{i+1}]/a/div/div[2]/div[1]/div[2]/div")
@ -257,27 +260,21 @@ def all_cards():
try_play(titre) try_play(titre)
sleep(3) sleep(3)
reset() reset()
except : except Exception as e :
pass # if it fail, it's probably okay print(format_error(e) + "probablement ok - check card")
# if it fail, it's probably okay -> when all three card are done, the pannel fold
except Exception as e: except Exception as e:
log_error(e) log_error(e)
def weekly_cards(): def weekly_cards():
try: # make sure that the weekly area is expanded
driver.find_element( row_element = driver.find_element(By.XPATH, "/html/body/div/div/div[3]/div[2]/div[2]/div[2]")
By.XPATH, "/html/body/div/div/div[3]/div[2]/div[2]/div[2]/div[1]" expanded = row_element.get_attribute("aria-expanded")
).click() # declenche la premiere partie ? if expanded != "true":
except: row_element.click()
reset()
try:
driver.find_element(
By.XPATH, "/html/body/div/div/div[3]/div[2]/div[2]/div[2]/div[1]"
).click() # declenche la deuxieme partie ?
except:
pass
for i in range(20): for i in range(20): # Should raise an error whene there is no card left
printf("début de l'une des cartes") printf("début de l'une des cartes")
driver.find_element( driver.find_element(
By.XPATH, By.XPATH,
@ -301,7 +298,7 @@ def all_cards():
driver.find_element(By.XPATH, "/html/body/div/div/div[3]/div[1]/div/div[1]/div[2]").click() driver.find_element(By.XPATH, "/html/body/div/div/div[3]/div[1]/div/div[1]/div[2]").click()
close_tab(driver.window_handles[1]) close_tab(driver.window_handles[1])
except Exception as e: except Exception as e:
print(e) print(format_error(e))
break break
try : try :
@ -464,7 +461,7 @@ def login(ldriver):
log_error("Timeout error occurred. \"normal\"....., maybe because of mismatch date ?", ldriver, True) # TODO check this hypothesis log_error("Timeout error occurred. \"normal\"....., maybe because of mismatch date ?", ldriver, True) # TODO check this hypothesis
else: else:
log_error(e) log_error(e)
CustomSleep(10) custom_sleep(10)
if ("account.microsoft.com" in ldriver.current_url) : if ("account.microsoft.com" in ldriver.current_url) :
ldriver.get("https://bing.com") ldriver.get("https://bing.com")
custom_sleep(5) custom_sleep(5)

View File

@ -95,7 +95,7 @@ VNC_PORT = args.vnc
POINTS_FILE = args.points_file POINTS_FILE = args.points_file
# global variables used later in the code # global variables used later in the code
LINUX_HOST = platform == "linux" # if the computer running this programm is linux, it allow more things LINUX_HOST = platform == "linux" # if the computer running this program is Linux, it allow more things
START_TIME = time() START_TIME = time()
@ -148,7 +148,7 @@ sql_pwd = config["SQL"]["pwd"]
sql_host = config["SQL"]["host"] sql_host = config["SQL"]["host"]
sql_database = config["SQL"]["database"] sql_database = config["SQL"]["database"]
# Other seetings # Other settings
IPV6_CHECKED = config["OTHER"]["ipv6"] IPV6_CHECKED = config["OTHER"]["ipv6"]

View File

@ -8,9 +8,8 @@ def Timer(text: str, mail: str) -> str:
# replace the function print, with more options # replace the function print, with more options
# [txt] : string, [driver] : selenium wbdriver # [txt] : string, [driver] : selenium webdriver
def printf2(txt, mail, LOG = LOG): def printf2(txt, mail, LOG = LOG):
if LOG:
print(Timer(txt, mail)) print(Timer(txt, mail))
@ -18,6 +17,7 @@ def printf2(txt, mail, LOG = LOG):
# check if the user is using IPV4 using ipify.org # check if the user is using IPV4 using ipify.org
# [driver] : selenium webdriver # [driver] : selenium webdriver
# never used here # never used here
# can be useful as Ms had issues with IPV6 at some point
def check_ipv4(driver): def check_ipv4(driver):
driver.get("https://api64.ipify.org") driver.get("https://api64.ipify.org")
elm = driver.find_element(By.TAG_NAME, "body") elm = driver.find_element(By.TAG_NAME, "body")
@ -27,12 +27,11 @@ def check_ipv4(driver):
def CustomSleep(temps): def custom_sleep(temps):
try : try :
if FAST and temps > 50: if FAST and temps > 50:
sleep(temps/10) sleep(temps/10)
return() elif LOG: #only print sleep when user see it
if LOG: #only print sleep when user see it
points = ["", "", "", "", "", "", "", ""] points = ["", "", "", "", "", "", "", ""]
passe = 0 passe = 0
for i in range(int(temps)): for i in range(int(temps)):
@ -47,14 +46,13 @@ def CustomSleep(temps):
print("attente annulée") print("attente annulée")
def format_error(e): def format_error(e) -> str:
tb = e.__traceback__ tb = e.__traceback__
txt = "" txt = ""
while tb != None : while tb != None :
txt = txt + f" -> {tb.tb_frame.f_code.co_name} ({tb.tb_lineno})" txt = txt + f" ({tb.tb_lineno}) -> {tb.tb_frame.f_code.co_name}"
tb = tb.tb_next tb = tb.tb_next
#type(ex).__name__ # Type of the error. Useless here. return(txt + "\n" + str(e))
return(txt[4::] + "\n" + str(e))
def progressBar(current, total=30, barLength=20, name="Progress"): def progressBar(current, total=30, barLength=20, name="Progress"):