improved try_play to use logger and to be a bit faster

This commit is contained in:
piair 2024-02-27 01:03:57 +01:00
parent 76acfb42c4
commit 6be44e829a
1 changed files with 40 additions and 56 deletions

88
V6.py
View File

@ -167,7 +167,6 @@ def play_quiz4(override: int = None):
override = int(findall('rqQuestionState([\d]{1,2})"', driver.page_source)[-1]) override = int(findall('rqQuestionState([\d]{1,2})"', driver.page_source)[-1])
except: except:
override = 3 override = 3
debug(f"Override : {override}") debug(f"Override : {override}")
try: try:
@ -206,8 +205,9 @@ def do_poll():
custom_sleep(3) custom_sleep(3)
# Find each playable card and tries to click on it to earn points
# todo : refactor
def all_cards(): def all_cards():
# input("1")
driver.get("https://rewards.bing.com") driver.get("https://rewards.bing.com")
wait_until_visible(By.CLASS_NAME, "c-card-content", 10, driver) wait_until_visible(By.CLASS_NAME, "c-card-content", 10, driver)
liste = driver.find_elements(By.CLASS_NAME, "c-card-content") liste = driver.find_elements(By.CLASS_NAME, "c-card-content")
@ -215,7 +215,7 @@ def all_cards():
try: try:
promo() promo()
except Exception as e: except Exception as e:
printf("no promo card") info("no promo card")
if (len(liste) < 10): # most likely an error during loading if (len(liste) < 10): # most likely an error during loading
if "suspendu" in driver.page_source: if "suspendu" in driver.page_source:
raise Banned() raise Banned()
@ -328,7 +328,7 @@ def promo():
try: try:
spotify(driver) spotify(driver)
except: except:
printf("no new windows", driver) warning("no new windows")
driver.get("https://rewards.bing.com") driver.get("https://rewards.bing.com")
driver.refresh() driver.refresh()
custom_sleep(3) custom_sleep(3)
@ -339,33 +339,30 @@ def try_play(nom="inconnu"):
rgpd_popup(driver) rgpd_popup(driver)
def play(number): def play(number):
if number == 8 or number == 9: if number in [8, 9]:
try: try:
printf(f"\033[96mQuiz 8 detected on `{nom}` \033[0m") debug(f"Quiz 8 detected on `{nom}`.")
play_quiz8() play_quiz8()
printf(f"\033[92mQuiz 8 succeeded on `{nom}` \033[0m") except Exception as err:
custom_sleep(uniform(3, 5)) error(f"fail of PlayQuiz 8. Aborted {err}")
except Exception as e:
printf(f"fail of PlayQuiz 8. Aborted {e} \033[0m")
elif number == 5 or number == 4: elif number in [4, 5]:
try: try:
printf(f"\033[96mQuiz 4 detected on `{nom}` \033[0m") debug(f"Quiz 4 detected on `{nom}`")
play_quiz4() play_quiz4()
printf(f"\033[92mQuiz 4 succeeded on `{nom}` \033[0m") except Exception as err:
custom_sleep(uniform(3, 5)) error(f"Fail of PlayQuiz 4. Aborted {err}.")
except Exception as e:
printf(f"Fail of PlayQuiz 4. Aborted {e} \033[0m")
elif number == 3 or number == 2: elif number in [2, 3]:
try: try:
printf(f"\033[96mQuiz 2 detected on `{nom}`\033[0m") debug(f"\033[96mQuiz 2 detected on `{nom}`\033[0m")
play_quiz2() play_quiz2()
printf(f"\033[92mQuiz 2 succeeded on `{nom}`\033[0m") except Exception as err:
except Exception as e: error(f"fail of PlayQuiz 2. Aborted {err}")
printf(f"fail of PlayQuiz 2. Aborted {e}")
else: else:
printf("There is an error. rqAnswerOption present in page but no action to do. skipping.") error("`rqAnswerOption` present in page but no action to do.")
custom_sleep(uniform(3, 5))
if "pas connecté à Microsoft Rewards" in driver.page_source: if "pas connecté à Microsoft Rewards" in driver.page_source:
custom_sleep(5) custom_sleep(5)
@ -373,42 +370,29 @@ def try_play(nom="inconnu"):
custom_sleep(5) custom_sleep(5)
rgpd_popup(driver) rgpd_popup(driver)
custom_sleep(5) custom_sleep(5)
printf("not connected, fixed") debug("Detected and fixed connection popup")
if "legaltextbox" in driver.current_url:
log_error("dev1") if "bt_PollRadio" in driver.page_source:
driver.find_element(By.CLASS_NAME, "actionLink").click() debug("Poll detected")
log_error("dev2") do_poll()
try:
if wait_until_visible(By.ID, "rqStartQuiz", 5, driver): elif "rqQuestionState" in driver.page_source:
number = driver.page_source.count("rqAnswerOption")
warning(f"recovery détecté. quiz : {number}")
play(number - 1)
elif search("([0-9]) de ([0-9]) finalisée", driver.page_source):
info("On fidelity page.")
fidelity()
elif wait_until_visible(By.ID, "rqStartQuiz", 5, driver):
custom_sleep(3) custom_sleep(3)
driver.find_element(By.ID, "rqStartQuiz").click() # start the quiz driver.find_element(By.ID, "rqStartQuiz").click() # start the quiz
answer_number = driver.page_source.count("rqAnswerOption") answer_number = driver.page_source.count("rqAnswerOption")
play(answer_number) play(answer_number)
else:
raise (NameError("going to next part"))
except Exception as e: # if there is no start button, an error is thrown
if "bt_PollRadio" in driver.page_source:
try:
printf("Poll detected")
do_poll()
printf("Poll succeeded")
except Exception as e:
printf(f"try_play - 1 - Poll aborted {e}")
elif "rqQuestionState" in driver.page_source:
try:
number = driver.page_source.count("rqAnswerOption")
printf(f"recovery détecté. quiz : {number}")
play(number - 1)
except Exception as e:
printf(f"try_play - 2 - {e}")
elif search("([0-9]) de ([0-9]) finalisée", driver.page_source):
printf("fidélité")
fidelity()
else: else:
printf(f"rien à faire sur la page {nom}") printf(f"Nothing to do on page `{nom}`")
custom_sleep(uniform(3, 5)) custom_sleep(uniform(3, 5))