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