diff --git a/V5.py b/V5.py index d30d524..32ef39e 100755 --- a/V5.py +++ b/V5.py @@ -5,6 +5,7 @@ from modules.db import add_to_database from modules.tools import * from modules.error import * from modules.driver_tools import * +from modules.cards import * import modules.globals as g @@ -12,10 +13,6 @@ driver = g.driver display = g.display -# TODO -# handle "panda"'s error: error while logging in preventing some task to be done SadPanda.svg: - - # create a webdriver def firefox_driver(mobile=False, headless=False): PC_USER_AGENT = ( @@ -221,6 +218,8 @@ def all_cards(): printf("no promo card") for i in range(len(liste)): + if(len(liste) < 20): + log_error("moins de 20 cartes", driver) printf(f"carte {i}") try : checked = ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML")) @@ -228,6 +227,11 @@ def all_cards(): liste = driver.find_elements(By.CLASS_NAME, "c-card-content") printf(f"staled, {len(liste)}") checked = ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML")) + except IndexError: + log_error("IndexError ?", driver) + driver.refresh() + custom_sleep(10) + checked = ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML")) if checked: custom_sleep(3) driver.execute_script("arguments[0].scrollIntoView();", liste[i]) @@ -249,38 +253,13 @@ def all_cards(): pass else : try : - welcome_tour(liste[i]) + welcome_tour(liste[i], driver) except Exception as e: print(format_error(e)) log_error("no new windows", driver) custom_sleep(3) -def welcome_tour(elm): - try : - driver.find_element(By.CSS_SELECTOR, '[class="welcome-tour-next-button c-call-to-action c-glyph"]').click() - except : - pass - driver.find_element(By.CSS_SELECTOR, '[class="quiz-link gray-button c-call-to-action c-glyph f-lightweight"]').click() - sleep(5) - driver.find_element(By.CSS_SELECTOR, '[class="c-glyph glyph-cancel"]').click() - elm.click() - driver.find_element(By.CSS_SELECTOR, '[class="quiz-link gray-button c-call-to-action c-glyph f-lightweight"]').click() - sleep(5) - driver.find_element(By.CSS_SELECTOR, '[class="c-glyph glyph-cancel"]').click() - elm.click() - driver.find_element(By.CSS_SELECTOR, '[class="quiz-link gray-button c-call-to-action c-glyph f-lightweight"]').click() - sleep(5) - driver.find_element(By.CSS_SELECTOR, '[class="c-glyph glyph-cancel"]').click() - - -def spotify(): - custom_sleep(5) - driver.find_element(By.CSS_SELECTOR, '[data-bi-id="spotify-premium gratuit"]').click() - custom_sleep(5) - close_tab(driver.window_handles[1]) - - def promo(): elm = driver.find_element(By.ID, "promo-item") for i in range(10): @@ -296,12 +275,13 @@ def promo(): close_tab(driver.window_handles[1]) else : try : - spotify() + spotify(driver) except : log_error("no new windows", driver) driver.get("https://rewards.bing.com") custom_sleep(3) + # Find out which type of action to do def try_play(nom="inconnu"): def play(number): diff --git a/modules/cards.py b/modules/cards.py new file mode 100644 index 0000000..d280ae7 --- /dev/null +++ b/modules/cards.py @@ -0,0 +1,26 @@ +from modules.imports import * + + +def welcome_tour(elm, driver): + try : + driver.find_element(By.CSS_SELECTOR, '[class="welcome-tour-next-button c-call-to-action c-glyph"]').click() + except : + pass + driver.find_element(By.CSS_SELECTOR, '[class="quiz-link gray-button c-call-to-action c-glyph f-lightweight"]').click() + sleep(5) + driver.find_element(By.CSS_SELECTOR, '[class="c-glyph glyph-cancel"]').click() + elm.click() + driver.find_element(By.CSS_SELECTOR, '[class="quiz-link gray-button c-call-to-action c-glyph f-lightweight"]').click() + sleep(5) + driver.find_element(By.CSS_SELECTOR, '[class="c-glyph glyph-cancel"]').click() + elm.click() + driver.find_element(By.CSS_SELECTOR, '[class="quiz-link gray-button c-call-to-action c-glyph f-lightweight"]').click() + sleep(5) + driver.find_element(By.CSS_SELECTOR, '[class="c-glyph glyph-cancel"]').click() + + +def spotify(driver): + sleep(5) + driver.find_element(By.CSS_SELECTOR, '[data-bi-id="spotify-premium gratuit"]').click() + sleep(5) + close_tab(driver.window_handles[1]) \ No newline at end of file diff --git a/version b/version index e6a6003..d883496 100644 --- a/version +++ b/version @@ -1 +1 @@ -v5.9.2 +v5.9.3