3 Commits

Author SHA1 Message Date
550e36b954 less errors 2023-05-31 10:52:45 +02:00
4814dfed46 hotfix, but a nice one 2023-05-30 20:21:25 +02:00
67aad7921f useful untested update 2023-05-12 14:53:52 +02:00
3 changed files with 53 additions and 24 deletions

59
V5.py
View File

@ -224,16 +224,15 @@ def all_cards():
except Exception as e: except Exception as e:
printf("no promo card") printf("no promo card")
if(len(liste) < 10): #most likely an error during loading if(len(liste) < 10): #most likely an error during loading
if "suspendu" in driver.page_source:
raise Banned()
driver.refresh() driver.refresh()
liste = driver.find_elements(By.CLASS_NAME, "c-card-content") liste = driver.find_elements(By.CLASS_NAME, "c-card-content")
if(len(liste) < 10): if(len(liste) < 10):
log_error("Less than 10 cards. Most likely an error with login.", driver) log_error("Less than 10 cards. Most likely an error with login.", driver)
return("PAS ASSEZ DE CARTES") return("PAS ASSEZ DE CARTES")
if (len(liste) < 20): # most likely not in france if (len(liste) < 20): # most likely not in france
if not g.norvege : # TODO : rename norvege to not_france or smth like that printf("moins de 20 cartes. Probablement pas en France.")
g.norvege = True
printf("Most likely not in France, thus disabling France specific action")
# TODO : check country for fidelity
for i in range(len(liste)): for i in range(len(liste)):
printf(f"carte {i}") printf(f"carte {i}")
try : try :
@ -249,9 +248,9 @@ def all_cards():
liste = driver.find_elements(By.CLASS_NAME, "c-card-content") liste = driver.find_elements(By.CLASS_NAME, "c-card-content")
try : try :
checked = ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML")) checked = ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML"))
except : except IndexError :
log_error("IndexError", driver) if i == len(liste) & i > 15 :
return("INDEX ERROR") checked = False
if checked: if checked:
custom_sleep(1.5) custom_sleep(1.5)
driver.execute_script("arguments[0].scrollIntoView();", liste[i]) driver.execute_script("arguments[0].scrollIntoView();", liste[i])
@ -276,7 +275,17 @@ def all_cards():
try_play(driver.title) try_play(driver.title)
close_tab(driver.window_handles[1]) close_tab(driver.window_handles[1])
if ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML")): 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) 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 : except :
pass pass
else : else :
@ -289,17 +298,20 @@ def all_cards():
def promo(): def promo():
elm = driver.find_element(By.ID, "promo-item") for i in range(5):
for i in range(10): elm = driver.find_element(By.ID, "promo-item")
wait_until_visible(By.ID, "promo-item", 5, driver)
if not elm: if not elm:
break break
if i > 8 : if i > 3 :
log_error("chelou, plus de 8 truc", driver) log_error("plus de 3 promo cards, probablement une pa skipable", driver)
try : try :
elm.click() elm.click()
except : except Exception as e:
#log_error(e, driver)
driver.execute_script("arguments[0].click();", elm) 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) custom_sleep(3)
if len(driver.window_handles) > 1 : 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])
@ -346,6 +358,11 @@ def try_play(nom="inconnu"):
else: else:
printf("There is an error. rqAnswerOption present in page but no action to do. skipping.") 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: try:
if wait_until_visible(By.ID, "rqStartQuiz", 5, driver): if wait_until_visible(By.ID, "rqStartQuiz", 5, driver):
custom_sleep(3) custom_sleep(3)
@ -353,7 +370,7 @@ def try_play(nom="inconnu"):
answer_number = driver.page_source.count("rqAnswerOption") answer_number = driver.page_source.count("rqAnswerOption")
play(answer_number) play(answer_number)
else : else :
raise (NameError("going to next part")) 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:
@ -446,7 +463,7 @@ def login_part_2(ldriver, cookies = False):
except Exception as e: except Exception as e:
pass pass
wait_until_visible(By.CSS_SELECTOR, '[data-bi-id="sh-sharedshell-home"]', 20, ldriver) 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) rgpd_popup(ldriver)
ldriver.refresh() ldriver.refresh()
rgpd_popup(ldriver) rgpd_popup(ldriver)
@ -635,8 +652,12 @@ def fidelity():
log_error(e) log_error(e)
if driver.current_url != "https://rewards.bing.com": if driver.current_url != "https://rewards.bing.com":
driver.get("https://rewards.bing.com") driver.get("https://rewards.bing.com")
pause = driver.find_element(By.CSS_SELECTOR, f'[class="c-action-toggle c-glyph f-toggle glyph-pause"]') # mettre le truc en pause try :
pause.click() 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"]') cartes = driver.find_elements(By.CSS_SELECTOR, f'[ng-repeat="item in $ctrl.transcludedItems"]')
nb_cartes = len(cartes) nb_cartes = len(cartes)
checked_list_all = driver.find_elements(By.CSS_SELECTOR, f'[ng-if="$ctrl.complete"]') checked_list_all = driver.find_elements(By.CSS_SELECTOR, f'[ng-if="$ctrl.complete"]')
@ -709,6 +730,9 @@ def daily_routine(custom = False):
try: try:
all_cards() all_cards()
except Banned:
log_error("banned", driver)
return("BANNED")
except Exception as e: except Exception as e:
log_error(e) log_error(e)
@ -838,6 +862,7 @@ else:
driver.quit() driver.quit()
display.stop() display.stop()
except Exception as e: 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}") printf(f"Error not catched. Skipping this account. {e}")
driver.quit() driver.quit()

View File

@ -3,7 +3,8 @@ from modules.config import *
from modules.tools import * from modules.tools import *
import modules.globals as g import modules.globals as g
def setup_proxy(ip, port) :
def setup_proxy(ip: str, port: str) -> None:
PROXY = f"{ip}:{port}" PROXY = f"{ip}:{port}"
webdriver.DesiredCapabilities.FIREFOX['proxy'] = { webdriver.DesiredCapabilities.FIREFOX['proxy'] = {
"httpProxy": PROXY, "httpProxy": PROXY,
@ -11,7 +12,8 @@ def setup_proxy(ip, port) :
"proxyType": "MANUAL", "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: def rgpd_popup(driver) -> None:
for i in ["bnp_btn_accept", "bnp_hfly_cta2", "bnp_hfly_close"] : for i in ["bnp_btn_accept", "bnp_hfly_cta2", "bnp_hfly_close"] :
try: try:
@ -19,8 +21,9 @@ def rgpd_popup(driver) -> None:
except: except:
pass pass
# save webdriver cookies # save webdriver cookies
def save_cookies(driver): def save_cookies(driver) -> None:
if g.dev: if g.dev:
f = open(f"{'/'.join(__file__.split('/')[:-2])}/user_data/cookies/{g._mail}_unsafe.pkl", "w") f = open(f"{'/'.join(__file__.split('/')[:-2])}/user_data/cookies/{g._mail}_unsafe.pkl", "w")
for i in driver.get_cookies(): for i in driver.get_cookies():
@ -29,8 +32,9 @@ def save_cookies(driver):
else : else :
pickle.dump(driver.get_cookies(), open(f"{'/'.join(__file__.split('/')[:-2])}/user_data/cookies/{g._mail}.pkl", "wb")) 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 # load cookies previously saved to the driver
def load_cookies(driver): def load_cookies(driver) -> None:
if g.dev: if g.dev:
f = open(f"{'/'.join(__file__.split('/')[:-2])}/user_data/cookies/{g._mail}_unsafe.pkl", "r") f = open(f"{'/'.join(__file__.split('/')[:-2])}/user_data/cookies/{g._mail}_unsafe.pkl", "r")
lines = f.readlines() 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. 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 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: for i in keys:
element.send_keys(i) element.send_keys(i)
sleep(uniform(0.1, 0.3)) 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") 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:
printf(f"element not found after {timeout}s") printf(f"element {identifier} not found after {timeout}s")
return(False) return(False)

View File

@ -1 +1 @@
v5.10.8 v5.10.11