4 Commits

Author SHA1 Message Date
2ca2779ec9 fixed a rare error occuring when the cookie creation isn't successful 2023-05-05 11:56:26 +02:00
5ef8d8b7ca some fixes. I believe it's stable. New release tomorrow 2023-05-05 11:40:38 +02:00
f2d08e9137 still dont know 2023-05-04 20:32:19 +02:00
d946298a38 don't know 2023-05-04 17:49:51 +02:00
3 changed files with 43 additions and 19 deletions

57
V5.py
View File

@ -221,9 +221,13 @@ def all_cards():
promo() promo()
except Exception as e: except Exception as e:
printf("no promo card") printf("no promo card")
if(len(liste) < 10): if(len(liste) < 10): #most likely an error during loading
log_error("moins de 10 cartes", driver) driver.refresh()
if (len(liste) < 20): liste = driver.find_elements(By.CLASS_NAME, "c-card-content")
if(len(liste) < 10):
log_error("moins de 10 cartes", driver)
return("PAS ASSEZ DE CARTES")
if (len(liste) < 20): # most likely not in france
if not g.norvege : if not g.norvege :
g.norvege = True g.norvege = True
printf("moins de 20 cartes, disabling fidelity") printf("moins de 20 cartes, disabling fidelity")
@ -234,17 +238,23 @@ def all_cards():
try : try :
checked = ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML")) checked = ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML"))
except StaleElementReferenceException : except StaleElementReferenceException :
driver.refresh()
liste = driver.find_elements(By.CLASS_NAME, "c-card-content") liste = driver.find_elements(By.CLASS_NAME, "c-card-content")
printf(f"staled, {len(liste)}") printf(f"staled, {len(liste)}")
checked = ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML")) checked = ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML"))
except IndexError: except IndexError:
log_error("IndexError ?", driver)
driver.refresh() driver.refresh()
custom_sleep(10) custom_sleep(10)
checked = ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML")) liste = driver.find_elements(By.CLASS_NAME, "c-card-content")
try :
checked = ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML"))
except :
log_error("IndexError", driver)
return("INDEX ERROR")
if checked: if checked:
custom_sleep(3) custom_sleep(1.5)
driver.execute_script("arguments[0].scrollIntoView();", liste[i]) driver.execute_script("arguments[0].scrollIntoView();", liste[i])
custom_sleep(1.5)
liste[i].click() liste[i].click()
if len(driver.window_handles) > 1 : if len(driver.window_handles) > 1 :
driver.switch_to.window(driver.window_handles[1]) driver.switch_to.window(driver.window_handles[1])
@ -255,11 +265,17 @@ def all_cards():
liste = driver.find_elements(By.CLASS_NAME, "c-card-content") liste = driver.find_elements(By.CLASS_NAME, "c-card-content")
if ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML")) : if ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML")) :
printf(f"carte {i} not okay. Retrying.") printf(f"carte {i} not okay. Retrying.")
liste[i].click() try :
log_error(f"Card {i} with issue. WTF ?", driver) liste[i].click()
except :
log_error("problème inconnu ? sauf si c'est un element obscure...", driver)
driver.get("https://rewards.bing.com")
checked = ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML"))
driver.switch_to.window(driver.window_handles[1]) driver.switch_to.window(driver.window_handles[1])
try_play(driver.title) try_play(driver.title)
close_tab(driver.window_handles[1]) close_tab(driver.window_handles[1])
if ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML")):
log_error(f"Card {i} Can't be completed. Why MS ?", driver)
except : except :
pass pass
else : else :
@ -288,7 +304,7 @@ def promo():
try : try :
spotify(driver) spotify(driver)
except : except :
log_error("no new windows", driver) printf("no new windows", driver)
driver.get("https://rewards.bing.com") driver.get("https://rewards.bing.com")
custom_sleep(3) custom_sleep(3)
@ -322,7 +338,7 @@ def try_play(nom="inconnu"):
except Exception as e: except Exception as e:
printf(f"fail of PlayQuiz 2. Aborted {e}") printf(f"fail of PlayQuiz 2. Aborted {e}")
else: else:
log_error("There is an error. rqAnswerOption present in page but no action to do. skipping.") printf("There is an error. rqAnswerOption present in page but no action to do. skipping.")
try: try:
if wait_until_visible(By.ID, "rqStartQuiz", 5, driver): if wait_until_visible(By.ID, "rqStartQuiz", 5, driver):
@ -390,6 +406,9 @@ def cookie_login(ldriver):
except FileNotFoundError : except FileNotFoundError :
printf("No cookies file Found.") printf("No cookies file Found.")
return(False) return(False)
except Exception as e:
log_error(f"error performing cookies login. Trying with password instead. {str(e)}", driver)
return(False)
try : try :
ldriver.refresh() ldriver.refresh()
except Exception as e: except Exception as e:
@ -404,6 +423,10 @@ def login_part_2(ldriver, cookies = False):
custom_sleep(5) custom_sleep(5)
if ('Abuse' in ldriver.current_url) : if ('Abuse' in ldriver.current_url) :
raise Banned() raise Banned()
if ('identity' in ldriver.current_url) :
raise Identity()
if ('notice' in ldriver.current_url) :
ldriver.find_element(By.ID, "id__0").click()
if cookies: if cookies:
save_cookies(ldriver) save_cookies(ldriver)
for id in ["KmsiCheckboxField", "id__0", "iLooksGood", "idSIButton9", "iCancel"]: for id in ["KmsiCheckboxField", "id__0", "iLooksGood", "idSIButton9", "iCancel"]:
@ -419,14 +442,7 @@ def login_part_2(ldriver, cookies = False):
rgpd_popup(ldriver) rgpd_popup(ldriver)
ldriver.refresh() ldriver.refresh()
rgpd_popup(ldriver) rgpd_popup(ldriver)
#ldriver.get("https://account.microsoft.com/")
#if wait_until_visible(By.CSS_SELECTOR, '[data-bi-id="sh-sharedshell-home"]', 30, ldriver) :
# return(True) #the account logging was successful
#else :
# log_error("Error during login. Trying to refresh")
# ldriver.refresh()
# return(wait_until_visible(By.CSS_SELECTOR, '[data-bi-id="sh-sharedshell-home"]', 30, ldriver))
# useless ?
# login() tries to login to your Microsoft account. # login() tries to login to your Microsoft account.
# it uses global variable g._mail and g._password to login # it uses global variable g._mail and g._password to login
@ -439,6 +455,8 @@ def login(ldriver):
ldriver.get("https://rewards.bing.com/") ldriver.get("https://rewards.bing.com/")
except Banned: except Banned:
raise Banned() raise Banned()
except Identity:
raise Banned()
except Exception as e: except Exception as e:
log_error(e) log_error(e)
ldriver.quit() ldriver.quit()
@ -674,6 +692,9 @@ def daily_routine(custom = False):
except Banned : except Banned :
log_error("This account is locked. Fix that. (-U ?)", driver) log_error("This account is locked. Fix that. (-U ?)", driver)
return() return()
except Identity :
log_error("This account has an issue. Fix that.", driver)
return()
try: try:
all_cards() all_cards()

View File

@ -2,4 +2,7 @@ class Banned(Exception):
pass pass
class NotBanned(Exception): class NotBanned(Exception):
pass
class Identity(Exception):
pass pass

View File

@ -1 +1 @@
v5.10.0 v5.10.4