uéuéué

This commit is contained in:
piair 2023-04-13 22:22:06 +02:00
parent 024b556f5e
commit f8f3ff2382
4 changed files with 92 additions and 122 deletions

197
V5.py
View File

@ -210,115 +210,94 @@ def do_poll():
printf("do_poll : end") printf("do_poll : end")
# finds all task to do, and launch them def all_cards():
def all_cards(): # return to the main page and closes all other tabs driver.get("https://rewards.bing.com")
def reset(part2=False): liste = driver.find_elements(By.CLASS_NAME, "c-card-content")
if len(driver.window_handles) == 1: custom_sleep(2)
driver.get("https://www.bing.com/rewardsapp/flyout") try :
if part2: promo()
row_element = driver.find_elements(By.CSS_SELECTOR, f'[class="i-h rw-sh fp_row"]')[1] except Exception as e:
expanded = row_element.get_attribute("aria-expanded") #printf(format_error(e))
if expanded != "true": printf("no promo card")
row_element.click()
else: for i in range(len(liste)):
printf(f"carte {i}")
try :
checked = ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML"))
except StaleElementReferenceException :
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"))
if checked:
custom_sleep(3)
driver.execute_script("arguments[0].scrollIntoView();", liste[i])
liste[i].click()
if len(driver.window_handles) > 1 :
driver.switch_to.window(driver.window_handles[1]) driver.switch_to.window(driver.window_handles[1])
printf(f"fermeture : {driver.current_url}") try_play()
driver.close() close_tab(driver.window_handles[1])
driver.switch_to.window(driver.window_handles[0])
if driver.current_url != "https://www.bing.com/rewardsapp/flyout":
driver.get("https://www.bing.com/rewardsapp/flyout")
reset(part2)
def daily_cards(): # cartes de la premiere partie (renouvelée chaque jour).
try : try :
# make sure that the daily area is expanded driver.refresh()
row_element = driver.find_elements(By.CSS_SELECTOR, f'[class="i-h rw-sh fp_row"]')[0] liste = driver.find_elements(By.CLASS_NAME, "c-card-content")
expanded = row_element.get_attribute("aria-expanded") if ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML")) :
if expanded != "true": printf(f"carte {i} not okay. Retrying.")
row_element.click() liste[i].click()
for i in range(3): driver.switch_to.window(driver.window_handles[1])
custom_sleep(uniform(3, 5)) try_play()
try: close_tab(driver.window_handles[1])
titre = "Placeholder" except :
elm = driver.find_elements(By.CLASS_NAME, 'promo_cont') pass
elm[i].click()
sleep(1)
titre = driver.title
try_play(titre)
sleep(1)
reset()
printf(f"DailyCard {titre} ok")
except Exception as e:
log_error(f"all_cards card `{titre}` error ({format_error(e)})")
break
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_elements(By.CLASS_NAME, 'promo_cont')[i]
if not ("correctCircle" in elm.get_attribute("innerHTML")):
printf(f"missed card {i}")
elm.click()
try_play("recovery")
sleep(3)
reset()
else : else :
printf(f'carte OK')
except Exception as e :
printf(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:
log_error(e)
def weekly_cards():
# make sure that the weekly area is expanded
row_element = driver.find_elements(By.CSS_SELECTOR, f'[class="i-h rw-sh fp_row"]')[1]
expanded = row_element.get_attribute("aria-expanded")
if expanded != "true":
row_element.click()
for i in range(20): # Should raise an error whene there is no card left
elm = driver.find_elements(By.CLASS_NAME, 'promo_cont')
try : try :
elm[0].click() welcome_tour(liste[i])
printf(f"Carte {i+1} cliquée.")
except Exception as e: except Exception as e:
printf(f"Plus aucune carte.") print(format_error(e))
break 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")
while elm:
driver.execute_script("arguments[0].click();", elm)
custom_sleep(3)
if len(driver.window_handles) > 1 :
driver.switch_to.window(driver.window_handles[len(driver.window_handles)-1]) driver.switch_to.window(driver.window_handles[len(driver.window_handles)-1])
sleep(1) try_play()
titre = driver.title.split(" - Recherche")[0] close_tab(driver.window_handles[1])
printf(f"Carte `{titre}` en cours.") else :
try_play(titre)
reset(True)
sleep(1)
def top_cards():
for _ in range(2):
try : try :
driver.find_elements(By.CSS_SELECTOR, '[class="banner_cont single wpoints"]')[0].click() spotify()
reset() except :
except Exception as e: log_error("no new windows", driver)
printf(format_error(e)) custom_sleep(3)
break
try :
top_cards()
except Exception as e:
log_error(e)
try:
daily_cards()
except Exception as e:
log_error(e)
try :
weekly_cards()
except Exception as e:
log_error(e)
# Find out which type of action to do # Find out which type of action to do
def try_play(nom="inconnu"): def try_play(nom="inconnu"):
# rgpd_popup(driver) if (nom=="inconnu"):
nom = driver.title
def play(number): def play(number):
if number == 8 or number == 9: if number == 8 or number == 9:
try: try:
@ -349,10 +328,13 @@ def try_play(nom="inconnu"):
log_error("There is an error. rqAnswerOption present in page but no action to do. skipping.") log_error("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):
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 except Exception as e: # if there is no start button, an error is thrown
if "bt_PollRadio" in driver.page_source: if "bt_PollRadio" in driver.page_source:
try: try:
@ -444,19 +426,6 @@ def login_part_2(ldriver, cookies = False):
return(wait_until_visible(By.CSS_SELECTOR, '[data-bi-id="sh-sharedshell-home"]', 30, ldriver)) return(wait_until_visible(By.CSS_SELECTOR, '[data-bi-id="sh-sharedshell-home"]', 30, ldriver))
#going to MsRewards
def go_to_msrewards(ldriver):
for i in ["[h='ID=RewardsFlyout,2.1']", f'[title="Rejoindre maintenant"]', f'[title="Rejoindre"]', f'[title="Join now"]'] :
ldriver.get("https://www.bing.com/rewardsapp/flyout")
if ('>Tableau de bord' in ldriver.page_source) :
printf('On MsRewards flyout')
return(True)
try:
ldriver.find_element(By.CSS_SELECTOR, i).click() # depend of the language of the page
except:
printf(f"element {i} not found")
# 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
def login(ldriver): def login(ldriver):
@ -465,7 +434,7 @@ def login(ldriver):
if not success_cookies: if not success_cookies:
pwd_login(ldriver) pwd_login(ldriver)
login_part_2(ldriver, not success_cookies) login_part_2(ldriver, not success_cookies)
go_to_msrewards(ldriver) ldriver.get("https://rewards.bing.com/")
except Banned: except Banned:
raise Banned() raise Banned()
except Exception as e: except Exception as e:

View File

@ -1,5 +1,6 @@
from modules.imports import * from modules.imports import *
from modules.config import * from modules.config import *
from modules.tools import *
import modules.globals as g import modules.globals as g
def setup_proxy(ip, port, options, socks=False) : def setup_proxy(ip, port, options, socks=False) :
@ -54,6 +55,6 @@ def wait_until_visible(search_by: str, identifier: str, timeout = 20, browser =
WebDriverWait(browser, timeout).until(EC.visibility_of_element_located((search_by,identifier)), "element not found") WebDriverWait(browser, timeout).until(EC.visibility_of_element_located((search_by,identifier)), "element not found")
return(True) return(True)
except TimeoutException as e: except TimeoutException as e:
print(f"element not found after {timeout}s") printf(f"element not found after {timeout}s")
return(False) return(False)

View File

@ -14,7 +14,7 @@ from selenium.webdriver.firefox.options import Options
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import WebDriverException, TimeoutException, NoSuchElementException, ElementClickInterceptedException from selenium.common.exceptions import WebDriverException, TimeoutException, NoSuchElementException, ElementClickInterceptedException, StaleElementReferenceException
from pyotp import TOTP from pyotp import TOTP
from pyvirtualdisplay import Display from pyvirtualdisplay import Display

View File

@ -1 +1 @@
v5.7.1 v5.8.0