mirror of
https://gitea.augustin64.fr/piair/MsRewards-Reborn.git
synced 2025-06-25 10:53:58 +02:00
Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
550e36b954 | |||
4814dfed46 | |||
67aad7921f |
51
V5.py
51
V5.py
@ -224,16 +224,15 @@ def all_cards():
|
||||
except Exception as e:
|
||||
printf("no promo card")
|
||||
if(len(liste) < 10): #most likely an error during loading
|
||||
if "suspendu" in driver.page_source:
|
||||
raise Banned()
|
||||
driver.refresh()
|
||||
liste = driver.find_elements(By.CLASS_NAME, "c-card-content")
|
||||
if(len(liste) < 10):
|
||||
log_error("Less than 10 cards. Most likely an error with login.", driver)
|
||||
return("PAS ASSEZ DE CARTES")
|
||||
if (len(liste) < 20): # most likely not in france
|
||||
if not g.norvege : # TODO : rename norvege to not_france or smth like that
|
||||
g.norvege = True
|
||||
printf("Most likely not in France, thus disabling France specific action")
|
||||
# TODO : check country for fidelity
|
||||
printf("moins de 20 cartes. Probablement pas en France.")
|
||||
for i in range(len(liste)):
|
||||
printf(f"carte {i}")
|
||||
try :
|
||||
@ -249,9 +248,9 @@ def all_cards():
|
||||
liste = driver.find_elements(By.CLASS_NAME, "c-card-content")
|
||||
try :
|
||||
checked = ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML"))
|
||||
except :
|
||||
log_error("IndexError", driver)
|
||||
return("INDEX ERROR")
|
||||
except IndexError :
|
||||
if i == len(liste) & i > 15 :
|
||||
checked = False
|
||||
if checked:
|
||||
custom_sleep(1.5)
|
||||
driver.execute_script("arguments[0].scrollIntoView();", liste[i])
|
||||
@ -276,7 +275,17 @@ def all_cards():
|
||||
try_play(driver.title)
|
||||
close_tab(driver.window_handles[1])
|
||||
if ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML")):
|
||||
driver.execute_script("arguments[0].scrollIntoView();", liste[i])
|
||||
log_error(f"Card {i} Can't be completed. Why MS ?", driver)
|
||||
liste[i].click()
|
||||
driver.switch_to.window(driver.window_handles[1])
|
||||
log_error(f"Cart completion - log - 2", driver)
|
||||
custom_sleep(10)
|
||||
log_error(f"Cart completion - log - 3 - after 10 sec", driver)
|
||||
try:
|
||||
try_play(driver.title) # go back to the main page
|
||||
except :
|
||||
driver.get("https://rewards.bing.com")
|
||||
except :
|
||||
pass
|
||||
else :
|
||||
@ -289,17 +298,20 @@ def all_cards():
|
||||
|
||||
|
||||
def promo():
|
||||
for i in range(5):
|
||||
elm = driver.find_element(By.ID, "promo-item")
|
||||
for i in range(10):
|
||||
wait_until_visible(By.ID, "promo-item", 5, driver)
|
||||
if not elm:
|
||||
break
|
||||
if i > 8 :
|
||||
log_error("chelou, plus de 8 truc", driver)
|
||||
if i > 3 :
|
||||
log_error("plus de 3 promo cards, probablement une pa skipable", driver)
|
||||
try :
|
||||
elm.click()
|
||||
except :
|
||||
except Exception as e:
|
||||
#log_error(e, driver)
|
||||
driver.execute_script("arguments[0].click();", elm)
|
||||
printf("that should't be there (promo)")
|
||||
#log_error(e, driver)
|
||||
printf(f"that should't be there (promo), but the workarround seemed to work {e}")
|
||||
custom_sleep(3)
|
||||
if len(driver.window_handles) > 1 :
|
||||
driver.switch_to.window(driver.window_handles[len(driver.window_handles)-1])
|
||||
@ -346,6 +358,11 @@ def try_play(nom="inconnu"):
|
||||
else:
|
||||
printf("There is an error. rqAnswerOption present in page but no action to do. skipping.")
|
||||
|
||||
if "pas connecté à Microsoft Rewards" in driver.page_source:
|
||||
driver.find_element(By.CSS_SELECTOR, '[onclick="setsrchusr()"]').click()
|
||||
custom_sleep(5)
|
||||
printf("not connected, fixed")
|
||||
|
||||
try:
|
||||
if wait_until_visible(By.ID, "rqStartQuiz", 5, driver):
|
||||
custom_sleep(3)
|
||||
@ -446,7 +463,7 @@ def login_part_2(ldriver, cookies = False):
|
||||
except Exception as e:
|
||||
pass
|
||||
wait_until_visible(By.CSS_SELECTOR, '[data-bi-id="sh-sharedshell-home"]', 20, ldriver)
|
||||
ldriver.get("https://www.bing.com/?setlang=fr&cc=fr&cc=FR")
|
||||
ldriver.get("https://www.bing.com/")
|
||||
rgpd_popup(ldriver)
|
||||
ldriver.refresh()
|
||||
rgpd_popup(ldriver)
|
||||
@ -635,8 +652,12 @@ def fidelity():
|
||||
log_error(e)
|
||||
if driver.current_url != "https://rewards.bing.com":
|
||||
driver.get("https://rewards.bing.com")
|
||||
try :
|
||||
pause = driver.find_element(By.CSS_SELECTOR, f'[class="c-action-toggle c-glyph f-toggle glyph-pause"]') # mettre le truc en pause
|
||||
pause.click()
|
||||
except Exception as e:
|
||||
printf(f"erreur : probablement pas de cartes {e}")
|
||||
return("no cards")
|
||||
cartes = driver.find_elements(By.CSS_SELECTOR, f'[ng-repeat="item in $ctrl.transcludedItems"]')
|
||||
nb_cartes = len(cartes)
|
||||
checked_list_all = driver.find_elements(By.CSS_SELECTOR, f'[ng-if="$ctrl.complete"]')
|
||||
@ -709,6 +730,9 @@ def daily_routine(custom = False):
|
||||
|
||||
try:
|
||||
all_cards()
|
||||
except Banned:
|
||||
log_error("banned", driver)
|
||||
return("BANNED")
|
||||
except Exception as e:
|
||||
log_error(e)
|
||||
|
||||
@ -838,6 +862,7 @@ else:
|
||||
driver.quit()
|
||||
display.stop()
|
||||
except Exception as e:
|
||||
log_error(f"Error not catched. Skipping this account. " + format_error(e), driver)
|
||||
printf(f"Error not catched. Skipping this account. {e}")
|
||||
driver.quit()
|
||||
|
||||
|
@ -3,7 +3,8 @@ from modules.config import *
|
||||
from modules.tools import *
|
||||
import modules.globals as g
|
||||
|
||||
def setup_proxy(ip, port) :
|
||||
|
||||
def setup_proxy(ip: str, port: str) -> None:
|
||||
PROXY = f"{ip}:{port}"
|
||||
webdriver.DesiredCapabilities.FIREFOX['proxy'] = {
|
||||
"httpProxy": PROXY,
|
||||
@ -11,7 +12,8 @@ def setup_proxy(ip, port) :
|
||||
"proxyType": "MANUAL",
|
||||
}
|
||||
|
||||
#Deal with rgpd popup as well as some random popup like 'are you satisfied' one
|
||||
|
||||
#Deal with RGPD popup as well as some random popup like 'are you satisfied' one
|
||||
def rgpd_popup(driver) -> None:
|
||||
for i in ["bnp_btn_accept", "bnp_hfly_cta2", "bnp_hfly_close"] :
|
||||
try:
|
||||
@ -19,8 +21,9 @@ def rgpd_popup(driver) -> None:
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
# save webdriver cookies
|
||||
def save_cookies(driver):
|
||||
def save_cookies(driver) -> None:
|
||||
if g.dev:
|
||||
f = open(f"{'/'.join(__file__.split('/')[:-2])}/user_data/cookies/{g._mail}_unsafe.pkl", "w")
|
||||
for i in driver.get_cookies():
|
||||
@ -29,8 +32,9 @@ def save_cookies(driver):
|
||||
else :
|
||||
pickle.dump(driver.get_cookies(), open(f"{'/'.join(__file__.split('/')[:-2])}/user_data/cookies/{g._mail}.pkl", "wb"))
|
||||
|
||||
|
||||
# load cookies previously saved to the driver
|
||||
def load_cookies(driver):
|
||||
def load_cookies(driver) -> None:
|
||||
if g.dev:
|
||||
f = open(f"{'/'.join(__file__.split('/')[:-2])}/user_data/cookies/{g._mail}_unsafe.pkl", "r")
|
||||
lines = f.readlines()
|
||||
@ -45,7 +49,7 @@ def load_cookies(driver):
|
||||
send_keys_wait([selenium element:element, str:keys]) send the different keys to the field element, with a random time between each press to simulate human action.
|
||||
keys can be an string, but also selenium keys
|
||||
"""
|
||||
def send_keys_wait(element, keys):
|
||||
def send_keys_wait(element, keys: str) -> None:
|
||||
for i in keys:
|
||||
element.send_keys(i)
|
||||
sleep(uniform(0.1, 0.3))
|
||||
@ -58,6 +62,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")
|
||||
return(True)
|
||||
except TimeoutException as e:
|
||||
printf(f"element not found after {timeout}s")
|
||||
printf(f"element {identifier} not found after {timeout}s")
|
||||
return(False)
|
||||
|
||||
|
Reference in New Issue
Block a user