uéuéué
This commit is contained in:
parent
024b556f5e
commit
f8f3ff2382
205
V5.py
205
V5.py
|
@ -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:
|
|
||||||
driver.switch_to.window(driver.window_handles[1])
|
|
||||||
printf(f"fermeture : {driver.current_url}")
|
|
||||||
driver.close()
|
|
||||||
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).
|
for i in range(len(liste)):
|
||||||
try:
|
printf(f"carte {i}")
|
||||||
# make sure that the daily area is expanded
|
try :
|
||||||
row_element = driver.find_elements(By.CSS_SELECTOR, f'[class="i-h rw-sh fp_row"]')[0]
|
checked = ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML"))
|
||||||
expanded = row_element.get_attribute("aria-expanded")
|
except StaleElementReferenceException :
|
||||||
if expanded != "true":
|
liste = driver.find_elements(By.CLASS_NAME, "c-card-content")
|
||||||
row_element.click()
|
printf(f"staled, {len(liste)}")
|
||||||
for i in range(3):
|
checked = ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML"))
|
||||||
custom_sleep(uniform(3, 5))
|
if checked:
|
||||||
try:
|
custom_sleep(3)
|
||||||
titre = "Placeholder"
|
driver.execute_script("arguments[0].scrollIntoView();", liste[i])
|
||||||
elm = driver.find_elements(By.CLASS_NAME, 'promo_cont')
|
liste[i].click()
|
||||||
elm[i].click()
|
if len(driver.window_handles) > 1 :
|
||||||
sleep(1)
|
driver.switch_to.window(driver.window_handles[1])
|
||||||
titre = driver.title
|
try_play()
|
||||||
try_play(titre)
|
close_tab(driver.window_handles[1])
|
||||||
sleep(1)
|
try :
|
||||||
reset()
|
driver.refresh()
|
||||||
printf(f"DailyCard {titre} ok")
|
liste = driver.find_elements(By.CLASS_NAME, "c-card-content")
|
||||||
|
if ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML")) :
|
||||||
|
printf(f"carte {i} not okay. Retrying.")
|
||||||
|
liste[i].click()
|
||||||
|
driver.switch_to.window(driver.window_handles[1])
|
||||||
|
try_play()
|
||||||
|
close_tab(driver.window_handles[1])
|
||||||
|
except :
|
||||||
|
pass
|
||||||
|
else :
|
||||||
|
try :
|
||||||
|
welcome_tour(liste[i])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log_error(f"all_cards card `{titre}` error ({format_error(e)})")
|
print(format_error(e))
|
||||||
break
|
log_error("no new windows", driver)
|
||||||
|
custom_sleep(3)
|
||||||
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 :
|
|
||||||
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 :
|
|
||||||
elm[0].click()
|
|
||||||
printf(f"Carte {i+1} cliquée.")
|
|
||||||
except Exception as e :
|
|
||||||
printf(f"Plus aucune carte.")
|
|
||||||
break
|
|
||||||
driver.switch_to.window(driver.window_handles[len(driver.window_handles) - 1])
|
|
||||||
sleep(1)
|
|
||||||
titre = driver.title.split(" - Recherche")[0]
|
|
||||||
printf(f"Carte `{titre}` en cours.")
|
|
||||||
try_play(titre)
|
|
||||||
reset(True)
|
|
||||||
sleep(1)
|
|
||||||
|
|
||||||
def top_cards():
|
|
||||||
for _ in range(2):
|
|
||||||
try :
|
|
||||||
driver.find_elements(By.CSS_SELECTOR, '[class="banner_cont single wpoints"]')[0].click()
|
|
||||||
reset()
|
|
||||||
except Exception as e:
|
|
||||||
printf(format_error(e))
|
|
||||||
break
|
|
||||||
|
|
||||||
|
def welcome_tour(elm):
|
||||||
try :
|
try :
|
||||||
top_cards()
|
driver.find_element(By.CSS_SELECTOR, '[class="welcome-tour-next-button c-call-to-action c-glyph"]').click()
|
||||||
except Exception as e:
|
except :
|
||||||
log_error(e)
|
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()
|
||||||
|
|
||||||
try:
|
def spotify():
|
||||||
daily_cards()
|
custom_sleep(5)
|
||||||
except Exception as e:
|
driver.find_element(By.CSS_SELECTOR, '[data-bi-id="spotify-premium gratuit"]').click()
|
||||||
log_error(e)
|
custom_sleep(5)
|
||||||
|
close_tab(driver.window_handles[1])
|
||||||
try :
|
|
||||||
weekly_cards()
|
|
||||||
except Exception as e:
|
|
||||||
log_error(e)
|
|
||||||
|
|
||||||
|
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])
|
||||||
|
try_play()
|
||||||
|
close_tab(driver.window_handles[1])
|
||||||
|
else :
|
||||||
|
try :
|
||||||
|
spotify()
|
||||||
|
except :
|
||||||
|
log_error("no new windows", driver)
|
||||||
|
custom_sleep(3)
|
||||||
|
|
||||||
# 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:
|
||||||
driver.find_element(By.ID, "rqStartQuiz").click() # start the quiz
|
if wait_until_visible(By.ID, "rqStartQuiz", 5, driver):
|
||||||
answer_number = driver.page_source.count("rqAnswerOption")
|
custom_sleep(3)
|
||||||
play(answer_number)
|
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
|
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:
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue