MsRewards/V5.py

913 lines
36 KiB
Python
Raw Normal View History

2023-01-29 00:51:30 +01:00
#!/usr/bin/python3.10
from modules.imports import *
2023-01-29 00:51:30 +01:00
from modules.db import add_to_database
from modules.config import *
from modules.tools import *
from modules.error import *
from modules.driver_tools import *
2023-01-29 00:51:30 +01:00
global driver
driver = None
2023-03-18 19:12:27 +01:00
global _mail, _password, _otp, display
2023-01-29 00:51:30 +01:00
2023-02-27 13:41:54 +01:00
# TODO : replace by a better print (with logging, cf https://realpython.com/python-logging/)
2023-04-04 12:55:00 +02:00
def printf(e):
printf2(str(e), _mail)
2023-02-08 15:14:13 +01:00
# TODO
2023-04-08 11:51:27 +02:00
# handle "panda"'s error: error while logging in preventing some task to be done SadPanda.svg
2023-03-19 10:17:28 +01:00
# check that each card worked (lot of misses lately) -- test that -- don't crash at least
2023-03-12 15:33:35 +01:00
2023-03-18 19:12:27 +01:00
2023-03-27 22:47:29 +02:00
# create a webdriver
def firefox_driver(mobile=False, headless=False):
PC_USER_AGENT = (
"Mozilla/5.0 (Windows NT 10.0; Win64; x64)"
"AppleWebKit/537.36 (KHTML, like Gecko)"
"Chrome/112.0.0.0 Safari/537.36 Edg/110.0.1587.56")
MOBILE_USER_AGENT = (
"Mozilla/5.0 (iPhone; CPU iPhone OS 15_5 like Mac OS X)"
2023-04-01 09:51:53 +02:00
"AppleWebKit/606.0.2 (KHTML, like Gecko)"
"CriOS/107.0.5060.64 Mobile/15E148 Safari/604.1"
2023-03-27 22:47:29 +02:00
)
options = Options()
options.set_preference('intl.accept_languages', 'fr-FR, fr')
if proxy_enabled :
setup_proxy(proxy_address,proxy_port, options)
options.set_preference("browser.link.open_newwindow", 3)
2023-04-02 12:32:21 +02:00
options.set_preference("dom.confirm_repost.testing.always_accept", True)
2023-03-27 22:47:29 +02:00
if FAST :
options.set_preference("permissions.default.image", 2) #disable image loading. You shouldn't use it except if really nessecary
if headless:
options.add_argument("-headless")
if mobile :
options.set_preference("general.useragent.override", MOBILE_USER_AGENT)
driver = webdriver.Firefox(options=options)
driver.set_window_size(1070 + hash(_mail)%20 , 1900 + hash(_password + "salt")%10) # mobile resolution are crazy high now, right ?
else :
options.set_preference("general.useragent.override", PC_USER_AGENT)
driver = webdriver.Firefox(options=options)
driver.set_window_size(1900 + hash(_mail)%20 , 1070 + hash(_password + "salt")%10)
return(driver)
2023-03-19 10:17:28 +01:00
def log_error(error, ldriver=driver, log=FULL_LOG):
2023-03-19 12:21:57 +01:00
global driver
if ldriver is None:
ldriver = driver
2023-03-18 19:12:27 +01:00
if type(error) != str :
error = format_error(error)
2023-04-04 12:55:00 +02:00
printf(f"\n\n\033[93m Erreur : {str(error)} \033[0m\n\n")
2023-03-18 19:12:27 +01:00
if DISCORD_ENABLED_ERROR:
with open("page.html", "w") as f:
2023-03-29 23:09:16 +02:00
try :
f.write(ldriver.page_source)
except :
f.write("the driver has closed or crashed. Can't access page content")
2023-03-26 22:56:57 +02:00
try :
img = display.waitgrab()
img.save("screenshot.png")
except :
ldriver.save_screenshot("screenshot.png")
2023-03-18 19:12:27 +01:00
if not log:
2023-03-27 22:47:29 +02:00
embed = Embed(
2023-03-18 19:12:27 +01:00
title="An Error has occured",
description=str(error),
colour=Colour.red(),
)
else:
2023-03-27 22:47:29 +02:00
embed = Embed(
2023-03-18 19:12:27 +01:00
title="Full log is enabled",
description=str(error),
colour=Colour.blue(),
)
2023-03-27 22:47:29 +02:00
file = File("screenshot.png")
2023-03-18 19:12:27 +01:00
embed.set_image(url="attachment://screenshot.png")
embed.set_footer(text=_mail)
webhookFailure.send(embed=embed, username="error", file=file, avatar_url = AVATAR_URL)
webhookFailure.send(username="error", file=File("page.html"), avatar_url = AVATAR_URL)
2023-02-25 19:05:47 +01:00
2023-01-29 00:51:30 +01:00
# close the tab currently on and go back to the one first, or the one specified
def close_tab(tab, SwitchTo=0) -> None:
driver.switch_to.window(tab)
driver.close()
driver.switch_to.window(driver.window_handles[SwitchTo])
# play_quiz[N]([int : override]) make the quiz with N choice each time. They usually have between 4 and 10 questions.
# override is the number of question, by default, it's the number of question in this specific quiz. Can be useful in some case, where the program crashes before finishing the quiz
def play_quiz2(override=10) -> None:
printf("starting play_quiz2")
for j in range(override):
try:
# rgpd_popup(driver)
2023-01-29 00:51:30 +01:00
custom_sleep(uniform(3, 5))
page_html = driver.page_source
secret_answer = search('IG:"([^"]+)"', page_html)[1] # variable used to calculate offset
answers_values = search('data-option="([^"]+)"', page_html)[1]
offset = int(secret_answer[-2:], 16) # the last two character converted to int are the offset
correct_answer_value = search('correctAnswer":"([0-9]+)', page_html)[1]
somme = 0
for answer in answers_values:
somme += ord(answer)
if somme + offset == int(correct_answer_value):
answer_elem = driver.find_element(By.ID, "rqAnswerOption0")
answer_elem.click()
progressBar(j, 10, name="quiz 2")
else:
answer_elem = driver.find_element(By.ID, "rqAnswerOption1")
answer_elem.click()
progressBar(j, 10, name="quiz 2")
except exceptions.ElementNotInteractableException as e:
driver.execute_script("arguments[0].click();", answer_elem)
except Exception as e:
2023-03-18 19:12:27 +01:00
log_error(e)
2023-01-29 00:51:30 +01:00
break
printf("play_quiz2 done")
2023-03-19 18:50:29 +01:00
def play_quiz8():
2023-01-29 00:51:30 +01:00
override = len(findall("<span id=\"rqQuestionState.\" class=\"emptyCircle\"></span>", driver.page_source))+1
printf(f"play_quiz8 : start, override : {override}")
try:
counter = 0
# rgpd_popup(driver)
2023-01-29 00:51:30 +01:00
for _ in range(override):
2023-04-12 00:01:24 +02:00
sleep(uniform(3, 5))
2023-03-12 11:22:49 +01:00
correct_answers = []
for i in range(1,9):
try :
element = driver.find_element(By.ID, f"rqAnswerOption{i-1}")
if 'iscorrectoption="True"' in element.get_attribute("outerHTML"):
correct_answers.append(f'rqAnswerOption{i-1}')
except Exception as e :
printf(f"can't find rqAnswerOption{i-1}. Probably already clicked" + str(e))
2023-01-29 00:51:30 +01:00
shuffle(correct_answers)
for answer_id in correct_answers:
2023-02-27 18:31:31 +01:00
wait_until_visible(By.ID, answer_id, timeout = 20, browser=driver)
2023-01-29 00:51:30 +01:00
counter += 1
progressBar(counter, 16, name="Quiz 8")
try:
answer_elem = driver.find_element(By.ID, answer_id)
answer_elem.click()
2023-04-12 00:01:24 +02:00
sleep(1)
2023-01-29 00:51:30 +01:00
except exceptions.NoSuchElementException :
driver.refresh()
2023-04-12 00:01:24 +02:00
sleep(10)
2023-01-29 00:51:30 +01:00
answer_elem = driver.find_element(By.ID, answer_id)
answer_elem.click()
except ElementClickInterceptedException :
rgpd_popup(driver)
2023-01-29 00:51:30 +01:00
correct_answers.append(answer_id)
except Exception as e:
2023-03-18 19:12:27 +01:00
log_error(f"{format_error(e)} \n Good answers : {' '.join(correct_answers)}")
2023-01-29 00:51:30 +01:00
printf("play_quiz8 : fin ")
def play_quiz4(override=None):
printf("play_quiz4 : start")
if not override:
try: # fidelity quiz are much longer than usual ones
override = int(findall('rqQuestionState([\d]{1,2})"', driver.page_source)[-1])
printf(f"Override : {override}")
except:
override = 3
try:
for i in range(override):
custom_sleep(uniform(3, 5))
txt = driver.page_source
# rgpd_popup(driver)
2023-01-29 00:51:30 +01:00
answer_option = search('correctAnswer":"([^"]+)', txt)[1]
answer_option = answer_option.replace("\\u0027", "'") # replace Unicode weird symbols
try:
answer_element = driver.find_element(By.CSS_SELECTOR, f'[data-option="{answer_option}"]')
answer_element.click()
except exceptions.ElementNotInteractableException:
driver.execute_script("arguments[0].click();", answer_element)
except Exception as e:
2023-03-18 19:12:27 +01:00
log_error(e)
2023-01-29 00:51:30 +01:00
raise ValueError(e)
printf("play_quiz4 : end")
# do_poll() answer a random thing to poll, on of daily activities
def do_poll():
printf("do_poll : start")
try:
try:
answer_elem = driver.find_element(By.ID, f"btoption{choice([0,1])}")
answer_elem.click()
except exceptions.ElementNotInteractableException:
driver.execute_script("arguments[0].click();", answer_elem)
custom_sleep(uniform(2, 2.5))
except Exception as error:
2023-03-18 19:12:27 +01:00
log_error(error)
2023-01-29 00:51:30 +01:00
raise ValueError(error)
printf("do_poll : end")
# finds all task to do, and launch them
def all_cards(): # return to the main page and closes all other tabs
2023-01-29 00:51:30 +01:00
def reset(part2=False):
if len(driver.window_handles) == 1:
driver.get("https://www.bing.com/rewardsapp/flyout")
if part2:
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()
2023-01-29 00:51:30 +01:00
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])
2023-04-02 12:32:21 +02:00
if driver.current_url != "https://www.bing.com/rewardsapp/flyout":
driver.get("https://www.bing.com/rewardsapp/flyout")
2023-01-29 00:51:30 +01:00
reset(part2)
2023-04-08 11:51:27 +02:00
def daily_cards(): # cartes de la premiere partie (renouvelée chaque jour).
2023-01-29 00:51:30 +01:00
try:
# make sure that the daily area is expanded
row_element = driver.find_elements(By.CSS_SELECTOR, f'[class="i-h rw-sh fp_row"]')[0]
expanded = row_element.get_attribute("aria-expanded")
if expanded != "true":
row_element.click()
2023-01-29 00:51:30 +01:00
for i in range(3):
custom_sleep(uniform(3, 5))
try:
titre = "Placeholder"
elm = driver.find_elements(By.CLASS_NAME, 'promo_cont')
elm[i].click()
2023-01-29 00:51:30 +01:00
sleep(1)
titre = driver.title
2023-03-19 18:50:29 +01:00
try_play(titre)
2023-01-29 00:51:30 +01:00
sleep(1)
reset()
printf(f"DailyCard {titre} ok")
except Exception as e:
2023-04-12 00:01:24 +02:00
log_error(f"all_cards card `{titre}` error ({format_error(e)})")
break
2023-03-18 19:12:27 +01:00
try : # devrait renvoyer vrai si la carte i est faite ou pas, a l'aide su symbole en haut a droite de la carte
2023-04-12 00:01:24 +02:00
elm = driver.find_elements(By.CLASS_NAME, 'promo_cont')[i]
2023-03-18 19:12:27 +01:00
if not ("correctCircle" in elm.get_attribute("innerHTML")):
2023-04-04 12:55:00 +02:00
printf(f"missed card {i}")
2023-04-12 00:01:24 +02:00
elm.click()
try_play("recovery")
2023-03-18 19:12:27 +01:00
sleep(3)
reset()
2023-04-12 00:01:24 +02:00
else :
printf(f'carte OK')
except Exception as e :
2023-04-04 12:55:00 +02:00
printf(format_error(e) + "probablement ok - check card")
# if it fail, it's probably okay -> when all three card are done, the pannel fold
2023-01-29 00:51:30 +01:00
except Exception as e:
2023-03-18 19:12:27 +01:00
log_error(e)
2023-01-29 00:51:30 +01:00
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()
2023-01-29 00:51:30 +01:00
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()
2023-04-12 00:01:24 +02:00
printf(f"Carte {i+1} cliquée.")
except Exception as e :
2023-04-12 00:01:24 +02:00
printf(f"Plus aucune carte.")
break
2023-01-29 00:51:30 +01:00
driver.switch_to.window(driver.window_handles[len(driver.window_handles) - 1])
sleep(1)
2023-04-12 00:01:24 +02:00
titre = driver.title.split(" - Recherche")[0]
printf(f"Carte `{titre}` en cours.")
2023-01-29 00:51:30 +01:00
try_play(titre)
reset(True)
sleep(1)
def top_cards():
2023-04-06 23:41:11 +02:00
for _ in range(2):
2023-03-29 23:24:14 +02:00
try :
2023-04-12 00:01:24 +02:00
driver.find_elements(By.CSS_SELECTOR, '[class="banner_cont single wpoints"]')[0].click()
2023-04-02 12:32:21 +02:00
reset()
2023-03-14 16:52:46 +01:00
except Exception as e:
2023-04-04 12:55:00 +02:00
printf(format_error(e))
2023-01-29 00:51:30 +01:00
break
try :
2023-04-12 00:01:24 +02:00
top_cards()
2023-01-29 00:51:30 +01:00
except Exception as e:
2023-03-18 19:12:27 +01:00
log_error(e)
2023-01-29 00:51:30 +01:00
try:
daily_cards()
except Exception as e:
2023-03-18 19:12:27 +01:00
log_error(e)
2023-01-29 00:51:30 +01:00
try :
weekly_cards()
except Exception as e:
2023-03-18 19:12:27 +01:00
log_error(e)
2023-01-29 00:51:30 +01:00
# Find out which type of action to do
2023-03-19 18:50:29 +01:00
def try_play(nom="inconnu"):
2023-04-12 00:01:24 +02:00
# rgpd_popup(driver)
2023-01-29 00:51:30 +01:00
def play(number):
if number == 8 or number == 9:
try:
2023-04-12 00:01:24 +02:00
printf(f"\033[96mQuiz 8 detected on `{nom}` \033[0m")
2023-03-19 18:50:29 +01:00
play_quiz8()
2023-04-12 00:01:24 +02:00
printf(f"\033[92mQuiz 8 succeeded on `{nom}` \033[0m")
2023-03-14 16:52:46 +01:00
custom_sleep(uniform(3, 5))
2023-01-29 00:51:30 +01:00
except Exception as e:
printf(f"fail of PlayQuiz 8. Aborted {e} \033[0m")
elif number == 5 or number == 4:
try:
2023-04-12 00:01:24 +02:00
printf(f"\033[96mQuiz 4 detected on `{nom}` \033[0m")
2023-01-29 00:51:30 +01:00
play_quiz4()
2023-04-12 00:01:24 +02:00
printf(f"\033[92mQuiz 4 succeeded on `{nom}` \033[0m")
2023-03-14 16:52:46 +01:00
custom_sleep(uniform(3, 5))
2023-01-29 00:51:30 +01:00
except Exception as e:
2023-04-12 00:01:24 +02:00
printf(f"Fail of PlayQuiz 4. Aborted {e} \033[0m")
2023-01-29 00:51:30 +01:00
elif number == 3 or number == 2:
try:
2023-04-12 00:01:24 +02:00
printf(f"\033[96mQuiz 2 detected on `{nom}`\033[0m")
2023-01-29 00:51:30 +01:00
play_quiz2()
2023-04-12 00:01:24 +02:00
printf(f"\033[92mQuiz 2 succeeded on `{nom}`\033[0m")
2023-01-29 00:51:30 +01:00
except Exception as e:
printf(f"fail of PlayQuiz 2. Aborted {e}")
else:
2023-03-18 19:12:27 +01:00
log_error("There is an error. rqAnswerOption present in page but no action to do. skipping.")
2023-01-29 00:51:30 +01:00
try:
driver.find_element(By.ID, "rqStartQuiz").click() # start the quiz
answer_number = driver.page_source.count("rqAnswerOption")
play(answer_number)
except Exception as e: # if there is no start button, an error is thrown
if "bt_PollRadio" in driver.page_source:
try:
printf("Poll detected")
do_poll()
printf("Poll succeeded")
except Exception as e:
printf(f"try_play - 1 - Poll aborted {e}")
elif "rqQuestionState" in driver.page_source:
try:
number = driver.page_source.count("rqAnswerOption")
printf(f"recovery détecté. quiz : {number}")
play(number-1)
except Exception as e:
printf(f"try_play - 2 - {e}")
elif search("([0-9]) de ([0-9]) finalisée", driver.page_source):
2023-04-04 12:55:00 +02:00
printf("fidélité")
2023-01-29 00:51:30 +01:00
fidelity()
else:
printf(f"rien à faire sur la page {nom}")
custom_sleep(uniform(3, 5))
# login() tries to login to your Microsoft account.
# it uses global variable _mail and _password to login
def login(ldriver):
def pwd_login():
printf("pwd_login : start")
ldriver.get("https://login.live.com")
2023-03-19 10:17:28 +01:00
custom_sleep(2)
wait_until_visible(By.ID, "i0116", browser = ldriver)
mail_elem = ldriver.find_element(By.ID, "i0116")
2023-01-29 00:51:30 +01:00
send_keys_wait(mail_elem, _mail)
mail_elem.send_keys(Keys.ENTER)
2023-03-19 10:17:28 +01:00
custom_sleep(2)
wait_until_visible(By.ID, "i0118", browser = ldriver)
pwd_elem = ldriver.find_element(By.ID, "i0118")
2023-01-29 00:51:30 +01:00
send_keys_wait(pwd_elem, _password)
pwd_elem.send_keys(Keys.ENTER)
2023-03-18 19:12:27 +01:00
custom_sleep(2)
if "Entrez le code de sécurité" in ldriver.page_source :
2023-03-18 19:12:27 +01:00
try :
a2f_elem = ldriver.find_element(By.ID, "idTxtBx_SAOTCC_OTC")
2023-03-18 19:12:27 +01:00
a2f_elem.send_keys(_otp.now())
a2f_elem.send_keys(Keys.ENTER)
except Exception as e :
log_error(e)
2023-01-29 00:51:30 +01:00
custom_sleep(5)
if ('Abuse' in ldriver.current_url) :
2023-03-18 19:12:27 +01:00
log_error("account suspended")
2023-01-29 00:51:30 +01:00
raise Banned()
2023-03-27 22:47:29 +02:00
save_cookies(driver, _mail)
2023-01-29 00:51:30 +01:00
for id in ["KmsiCheckboxField","iLooksGood", "idSIButton9", "iCancel"]:
try:
ldriver.find_element(By.ID, id).click()
2023-02-25 19:05:47 +01:00
restart = True
2023-01-29 00:51:30 +01:00
except Exception as e:
pass
2023-02-25 19:05:47 +01:00
2023-01-29 00:51:30 +01:00
try :
body_elem = ldriver.find_element(By.TAG_NAME, "body") # in case of any random popup
2023-01-29 00:51:30 +01:00
body_elem.send_keys(Keys.ENTER)
except :
pass
2023-02-27 18:31:31 +01:00
printf("login completed - going to MsRewards")
2023-01-29 00:51:30 +01:00
custom_sleep(uniform(3,5))
ldriver.get("https://www.bing.com/rewardsapp/flyout")
2023-01-29 00:51:30 +01:00
custom_sleep(uniform(3,5))
2023-02-25 19:05:47 +01:00
for i in [f'[title="Rejoindre maintenant"]', f'[title="Rejoindre"]', f'[title="Join now"]'] :
try:
ldriver.find_element(By.CSS_SELECTOR, i).click() # depend of the language of the page
2023-02-25 19:05:47 +01:00
except:
2023-04-04 12:55:00 +02:00
printf(f"element {i} not found")
rgpd_popup(ldriver)
2023-02-27 18:31:31 +01:00
custom_sleep(uniform(3,5))
ldriver.get("https://www.bing.com/rewardsapp/flyout")
try:
ldriver.find_element(By.CSS_SELECTOR, '[title="Rejoindre maintenant"]').click() # depend of the language of the page
except:
2023-04-04 12:55:00 +02:00
printf(f"unlock test: fail, probably normal")
2023-04-04 12:55:00 +02:00
printf('on MsRewards')
def cookie_login():
ldriver.get("https://login.live.com")
2023-01-29 00:51:30 +01:00
try :
2023-03-27 22:47:29 +02:00
load_cookies(ldriver, _mail)
except FileNotFoundError :
2023-04-04 12:55:00 +02:00
printf("Creating cookies file")
2023-03-26 22:56:57 +02:00
return(False)
2023-04-01 09:51:53 +02:00
try :
2023-03-26 22:56:57 +02:00
ldriver.refresh()
2023-04-01 09:51:53 +02:00
except WebDriverException as e: # This error occurs at random time. Don't really know why
2023-03-26 22:56:57 +02:00
if "Reached error page: about:neterror?e=netTimeout" in str(e):
2023-04-01 09:51:53 +02:00
log_error("Timeout error occurred. \"normal\"....., maybe because of mismatch date ?", ldriver, True) # TODO check this hypothesis
2023-03-26 22:56:57 +02:00
else:
log_error(e, ldriver)
wait_until_visible(By.CSS_SELECTOR, '[data-bi-id="sh-sharedshell-rewards"]', 20, ldriver)
if "Abuse" in ldriver.current_url:
log_error("banned", ldriver)
raise Banned()
if ("account.microsoft.com" in ldriver.current_url) :
if "notice" in ldriver.current_url:
ldriver.find_element(By.ID, "id__0").click()
wait_until_visible(By.CSS_SELECTOR, '[data-bi-id="sh-sharedshell-rewards"]', 20, ldriver)
ldriver.get("https://bing.com")
wait_until_visible(By.CSS_SELECTOR, '[id="bnp_btn_accept"]', 5, ldriver)
2023-03-26 23:24:59 +02:00
ldriver.refresh()
rgpd_popup(ldriver) # Ultra important
ldriver.get("https://www.bing.com/rewardsapp/flyout")
2023-04-12 14:40:32 +02:00
log_error("1", ldriver, True)
2023-04-09 23:41:31 +02:00
#if "SadPanda.svg" in ldriver.page_source :
# log_error('test SadPanda before', ldriver)
# driver.execute_script("location.reload(true);")
# log_error('test SadPanda after', ldriver)
2023-03-29 23:19:57 +02:00
if not('>Tableau de bord' in ldriver.page_source):
2023-04-12 14:40:32 +02:00
log_error("2", ldriver, True)
2023-03-31 10:00:45 +02:00
try :
ldriver.find_element(By.CSS_SELECTOR, "[h='ID=RewardsFlyout,2.1']").click()
custom_sleep(5)
2023-04-12 14:40:32 +02:00
log_error("3", ldriver, True)
2023-03-31 10:00:45 +02:00
if "bing.com" in ldriver.current_url :
rgpd_popup(ldriver)
ldriver.get("https://www.bing.com/rewardsapp/flyout")
if ('>Tableau de bord' in ldriver.page_source) :
return(True)
if "bing.com" in ldriver.current_url : # Mobile ONLY -> check that that is true
ldriver.get("https://www.bing.com/rewardsapp/flyout")
2023-04-12 14:40:32 +02:00
custom_sleep(2)
log_error("4", ldriver, True)
return(True)
else :
printf("error during the connection. Trying something else")
2023-03-31 10:00:45 +02:00
except Exception as e:
log_error(f"not connected 5 - error {e}", ldriver)
2023-03-29 23:19:57 +02:00
if not('>Tableau de bord' in ldriver.page_source):
2023-03-29 23:09:16 +02:00
try :
2023-04-12 14:40:32 +02:00
log_error("5", ldriver, True)
2023-03-31 10:00:45 +02:00
ldriver.find_element(By.XPATH, "/html/body/div/div/div/div/div[2]/a").click()
2023-04-04 12:55:00 +02:00
custom_sleep(5)
2023-03-29 23:09:16 +02:00
except Exception as e:
2023-03-31 10:00:45 +02:00
log_error(f"erreur not connected 6{e}", ldriver)
2023-04-04 12:55:00 +02:00
return(False)
if "bing.com" in ldriver.current_url :
rgpd_popup(ldriver)
ldriver.get("https://www.bing.com/rewardsapp/flyout")
if ('>Tableau de bord' in ldriver.page_source) :
2023-04-12 14:40:32 +02:00
log_error("7", ldriver, True)
2023-04-04 12:55:00 +02:00
return(True)
else :
log_error("not connected 6", ldriver)
return(False)
return(True)
2023-03-29 23:09:16 +02:00
2023-04-04 12:55:00 +02:00
if ('account.live.com' in ldriver.current_url):
log_error("error 1", ldriver, True)
ldriver.refresh()
log_error("error 2", ldriver, True)
ldriver.get("https://bing.com")
ldriver.refresh()
rgpd_popup(ldriver)
log_error("error 3", ldriver, True)
sleep(5)
2023-03-29 23:09:16 +02:00
return(True)
2023-04-04 12:55:00 +02:00
printf("cookies plus valides ?")
return(False)
try :
if cookie_login():
return (ldriver.current_window_handle)
2023-03-29 23:09:16 +02:00
pwd_login() #mobile login in never called. TODO : check if it's bad.
return(ldriver.current_window_handle)
except Banned:
raise Banned()
except Exception as e:
log_error(e)
ldriver.quit()
return(False)
2023-01-29 00:51:30 +01:00
# Makes 30 search as PC Edge
def bing_pc_search(override=randint(35, 40)):
mot = choice(Liste_de_mot).replace(" ","+")
driver.get(f"https://www.bing.com/search?q={mot}") # {choice(Liste_de_mot)}')
2023-01-29 00:51:30 +01:00
custom_sleep(uniform(1, 2))
rgpd_popup(driver)
2023-01-29 00:51:30 +01:00
send_keys_wait(
driver.find_element(By.ID, "sb_form_q"),
Keys.BACKSPACE + Keys.BACKSPACE + Keys.BACKSPACE + Keys.BACKSPACE + Keys.BACKSPACE + Keys.BACKSPACE
)
for _ in range(override):
word = choice(Liste_de_mot)
try:
send_keys_wait(driver.find_element(By.ID, "sb_form_q"), word)
driver.find_element(By.ID, "sb_form_q").send_keys(Keys.ENTER)
except Exception as e :
printf(e)
sleep(10)
driver.get(f'https://www.bing.com/search?q={word}')
sleep(3)
send_keys_wait(driver.find_element(By.ID, "sb_form_q"), word)
driver.find_element(By.ID, "sb_form_q").send_keys(Keys.ENTER)
custom_sleep(uniform(3, 7))
2023-01-29 00:51:30 +01:00
try:
driver.find_element(By.ID, "sb_form_q").clear()
except Exception as e:
printf(e)
try:
2023-02-25 19:05:47 +01:00
driver.get('https://www.bing.com/search?q=plans')
2023-01-29 00:51:30 +01:00
driver.find_element(By.ID, "sb_form_q").clear()
except Exception as e:
2023-03-18 19:12:27 +01:00
log_error(f"clear la barre de recherche - {format_error(e)}")
2023-03-19 18:50:29 +01:00
2023-01-29 00:51:30 +01:00
2023-02-27 13:41:54 +01:00
# Unban an account, called with -u parameter. You will need a phone number
2023-01-29 00:51:30 +01:00
def unban() -> None:
driver.find_element(By.ID, "StartAction").click()
custom_sleep(2)
txt = driver.page_source
uuid0 = findall('wlspispHIPCountrySelect([a-z0-9]+)', txt)[0]
uuid1 = findall('wlspispHIPPhoneInput([a-z0-9]+)', txt)[0]
uuid2 = findall('wlspispHipSendCode([a-z0-9]+)', txt)[0]
uuid3 = findall('wlspispSolutionElement([a-z0-9]+)', txt)[0]
country_code_select = Select(driver.find_element(By.ID, "wlspispHIPCountrySelect" + uuid0))
country_code_input = input("enter Country code (FR, ...) ")
country_code_select.select_by_value(country_code_input)
wait_until_visible(By.ID, "wlspispHIPPhoneInput" + uuid1, browser=driver)
phone_input = input("phone number : +33")
phone_elem = driver.find_element(By.ID, "wlspispHIPPhoneInput" + uuid1)
phone_elem.send_keys(phone_input)
wait_until_visible(By.ID, "wlspispHipSendCode" + uuid2, browser=driver)
send_sms_elem = driver.find_element(By.ID, "wlspispHipSendCode" + uuid2)
send_sms_elem.click()
wait_until_visible(By.ID, "wlspispSolutionElement" + uuid3, browser=driver)
sms_code_elem = driver.find_element(By.ID, "wlspispSolutionElement" + uuid3)
sms_code_input = input("entrez le contenu du msg : ")
sms_code_elem.send_keys(sms_code_input)
send_box = driver.find_element(By.ID, "ProofAction")
send_box.click()
wait_until_visible(By.ID, "FinishAction", browser=driver)
end_elem = driver.find_element(By.ID, "FinishAction")
end_elem.click()
2023-02-25 19:05:47 +01:00
# Sends points to database, discord and whatever service you want
2023-01-29 00:51:30 +01:00
def log_points(account="unknown"):
def get_points():
2023-04-12 00:01:24 +02:00
driver.get("https://rewards.bing.com")
custom_sleep(1)
if "/proofs/" in driver.current_url:
for id in ["KmsiCheckboxField","iLooksGood", "idSIButton9", "iCancel"]:
try:
driver.find_element(By.ID, id).click()
restart = True
except Exception as e:
pass
2023-04-12 00:01:24 +02:00
wait_until_visible(By.CSS_SELECTOR, 'span[mee-element-ready="$ctrl.loadCounterAnimation()"]', browser=driver)
try :
point = search('availablePoints\":([\d]+)', driver.page_source)[1]
2023-01-29 00:51:30 +01:00
except Exception as e:
2023-04-12 00:01:24 +02:00
sleep(5)
log_error(f"Dev error, checking why it doesn't work (waited a bit, is this still white ?) {format_error(e)}", driver, True)
driver.refresh()
sleep(5)
point = search('availablePoints\":([\d]+)', driver.page_source)[1]
2023-01-29 00:51:30 +01:00
return(point)
for _ in range (3):
try :
points = get_points()
break
except Exception as e:
custom_sleep(300)
2023-03-18 19:12:27 +01:00
log_error(e)
2023-01-29 00:51:30 +01:00
points = None
if not points :
2023-03-18 19:12:27 +01:00
log_error(f"impossible d'avoir les points")
2023-01-29 00:51:30 +01:00
custom_sleep(uniform(3, 20))
account_name = account.split("@")[0]
if DISCORD_ENABLED_SUCCESS:
if DISCORD_EMBED:
2023-03-27 22:47:29 +02:00
embed = Embed(
2023-01-29 00:51:30 +01:00
title=f"{account_name} actuellement à {str(points)} points", colour=Colour.green()
)
embed.set_footer(text=account_name)
webhookSuccess.send(embed=embed)
else:
webhookSuccess.send(f"{account_name} actuellement à {str(points)} points")
if sql_enabled :
add_to_database(account_name, points, sql_host, sql_usr, sql_pwd, sql_database)
def fidelity():
try:
while 1: #close all tabs
try:
close_tab(1)
except:
break
try :
fidelity_link_page = get(FidelityLink) #get the url of fidelity page
except Exception as e :
printf(e)
fidelity_link_page = False
if fidelity_link_page :
fidelity_link = fidelity_link_page.content.decode("UTF-8")
if (fidelity_link.split(":")[0] == "https") or (fidelity_link.split(":")[0] == "http") :
driver.get(fidelity_link)
wait_until_visible(By.CSS_SELECTOR, 'div[class="pull-left spacer-48-bottom punchcard-row"]', browser=driver)
2023-04-04 12:55:00 +02:00
try :
choix = driver.find_element(By.CSS_SELECTOR, 'div[class="pull-left spacer-48-bottom punchcard-row"]') # pull-left spacer-48-bottom punchcard-row? USELESS ?
except : # tentative de fix
2023-04-12 00:01:24 +02:00
driver.execute_script("location.reload(true);")
wait_until_visible(By.CSS_SELECTOR, 'div[class="pull-left spacer-48-bottom punchcard-row"]', browser=driver)
2023-04-04 12:55:00 +02:00
choix = driver.find_element(By.CSS_SELECTOR, 'div[class="pull-left spacer-48-bottom punchcard-row"]')
2023-01-29 00:51:30 +01:00
answer_number = search("([0-9]) of ([0-9]) completed", driver.page_source)
if answer_number is None:
answer_number = search("([0-9]) de ([0-9]) finalisé", driver.page_source)
if answer_number is None :
answer_number = search("([0-9]) licence\(s\) sur ([0-9]) disponible\(s\)", driver.page_source)
2023-04-06 23:41:11 +02:00
if answer_number is None :
answer_number = search("([0-9])&nbsp;défi\(s\) terminé\(s\) sur ([0-9])", driver.page_source)
2023-01-29 00:51:30 +01:00
if answer_number is None :
answer_number = [0,0,0]
for _ in range(int(answer_number[2]) - int(answer_number[1])):
driver.refresh()
custom_sleep(2)
card_elem = driver.find_element(By.CLASS_NAME, "spacer-48-bottom")
try :
button_text = search('<span class="pull-left margin-right-15">([^<^>]+)</span>',card_elem.get_attribute("innerHTML"))[1]
bouton_card = driver.find_element(By.XPATH, f'//span[text()="{button_text}"]')
bouton_card.click()
except Exception as e1 :
try :
recover_elem = driver.find_element(By.XPATH,'/html/body/div[1]/div[2]/main/div[2]/div[2]/div[7]/div[3]/div[1]/a')
recover_elem.click()
except Exception as e2 :
2023-03-18 19:12:27 +01:00
log_error(f"fidélité - double erreur - e1 : {format_error(e1)} - e2 {format_error(e2)}")
2023-01-29 00:51:30 +01:00
break
custom_sleep(uniform(3, 5))
driver.switch_to.window(driver.window_handles[1])
try_play(driver.title)
driver.get(fidelity_link) # USELESS ?
custom_sleep(uniform(3, 5))
try:
close_tab(driver.window_handles[1])
except Exception as e:
printf(e)
printf("fidelity - done")
else :
printf("invalid fidelity link.")
except Exception as e:
2023-03-18 19:12:27 +01:00
log_error(e)
2023-01-29 00:51:30 +01:00
def mobile_alert_popup():
try:
alert = mobile_driver.switch_to.alert
alert.dismiss()
except exceptions.NoAlertPresentException as e:
pass
except Exception as e:
2023-03-18 19:12:27 +01:00
log_error(e, mobile_driver)
2023-01-29 00:51:30 +01:00
def bing_mobile_search(override=randint(22, 25)):
global mobile_driver
mobile_driver = firefox_driver(mobile=True)
2023-01-29 00:51:30 +01:00
try:
login(mobile_driver)
mot = choice(Liste_de_mot).replace(" ","+")
mobile_driver.get(f"https://www.bing.com/search?q={mot}")
custom_sleep(uniform(1, 2))
rgpd_popup(mobile_driver)
custom_sleep(uniform(1, 1.5))
for i in range(override): # 20
try :
mot = choice(Liste_de_mot)
send_keys_wait(mobile_driver.find_element(By.ID, "sb_form_q"), mot)
mobile_driver.find_element(By.ID, "sb_form_q").send_keys(Keys.ENTER)
custom_sleep(uniform(3, 7))
mobile_alert_popup() # check for alert (asking for position or for allowing notifications)
mobile_driver.find_element(By.ID, "sb_form_q").clear()
except Exception as e:
2023-04-04 12:55:00 +02:00
printf(e)
mobile_driver.refresh()
custom_sleep(30)
i -= 1
mobile_driver.quit()
2023-01-29 00:51:30 +01:00
except Exception as e:
2023-03-18 19:12:27 +01:00
log_error(e, mobile_driver)
2023-01-29 00:51:30 +01:00
mobile_driver.quit()
def daily_routine(custom = False):
2023-01-29 00:51:30 +01:00
try :
if not custom: # custom already login
login(driver)
2023-01-29 00:51:30 +01:00
except Banned :
2023-03-18 19:12:27 +01:00
log_error("THIS ACCOUNT IS BANNED. FIX THIS ISSUE WITH -U")
2023-01-29 00:51:30 +01:00
return()
try:
all_cards()
except Exception as e:
2023-03-18 19:12:27 +01:00
log_error(e)
2023-01-29 00:51:30 +01:00
2023-04-02 12:32:21 +02:00
try:
fidelity()
except Exception as e:
log_error(e)
2023-01-29 00:51:30 +01:00
try:
bing_pc_search()
except Exception as e:
2023-03-18 19:12:27 +01:00
log_error(e)
2023-01-29 00:51:30 +01:00
try:
bing_mobile_search()
except Exception as e:
2023-03-18 19:12:27 +01:00
log_error(e)
2023-01-29 00:51:30 +01:00
try:
log_points(_mail)
except Exception as e:
2023-03-18 19:12:27 +01:00
log_error(e)
2023-01-29 00:51:30 +01:00
def dev():
log_error("test")
2023-01-29 00:51:30 +01:00
def CustomStart(Credentials):
global START_TIME
if not LINUX_HOST :
raise NameError('You need to be on linux to do that, due to the utilisation of a module named enquieries, sorry.')
2023-03-19 18:50:29 +01:00
global driver, _mail, _password, p, _otp
2023-01-29 00:51:30 +01:00
system("clear") # clear from previous command to allow a clean choice
actions = ["tout", "daily", "pc", "mobile", "log_points","fidelity", "dev"]
Actions = enquiries.choose("quels Actions ?", actions, multi=True)
liste = select_accounts()
START_TIME = time() # Reset timer to the start of the actions
2023-03-19 18:50:29 +01:00
for cred in liste:
_mail = cred[0]
_password = cred[1]
if len(cred) == 3:
_otp = TOTP(cred[2])
2023-01-29 00:51:30 +01:00
2023-03-19 18:50:29 +01:00
driver = firefox_driver()
driver.implicitly_wait(3)
2023-01-29 00:51:30 +01:00
if login(driver) != "STOP":
2023-03-19 18:50:29 +01:00
if "tout" in Actions:
daily_routine(True)
if "daily" in Actions:
try:
all_cards()
except Exception as e:
log_error(e)
if "pc" in Actions:
try:
bing_pc_search()
except Exception as e:
log_error(e)
if "mobile" in Actions:
try:
bing_mobile_search()
except Exception as e:
log_error(e)
if "fidelity" in Actions:
try :
fidelity()
except Exception as e :
log_error(e)
if "dev" in Actions:
try:
dev()
except Exception as e:
printf(e)
break
if not "tout" in Actions:
try:
log_points(_mail)
except Exception as e:
2023-04-04 12:55:00 +02:00
printf(f"CustomStart {e}")
2023-01-29 00:51:30 +01:00
driver.close()
2023-02-25 19:05:47 +01:00
if VNC_ENABLED :
2023-03-19 10:17:28 +01:00
display = SmartDisplay(backend="xvnc", size=(2160, 2160), rfbport=VNC_PORT, color_depth=24)
2023-02-25 19:05:47 +01:00
else :
2023-03-19 10:17:28 +01:00
display = SmartDisplay(size=(2160, 2160))
2023-01-29 00:51:30 +01:00
display.start()
if CUSTOM_START:
CustomStart(Credentials)
elif UNBAN:
_mail, _password = select_accounts(False)[0]
2023-02-25 19:05:47 +01:00
driver = firefox_driver()
2023-02-08 15:14:13 +01:00
try :
login(driver)
2023-02-08 15:14:13 +01:00
except Banned:
2023-01-29 00:51:30 +01:00
unban()
2023-02-08 15:14:13 +01:00
2023-01-29 00:51:30 +01:00
driver.quit()
elif POINTS_FILE != "":
save_points_from_file(POINTS_FILE)
2023-01-29 00:51:30 +01:00
else:
2023-04-07 10:04:59 +02:00
if UPDATE_VERSION != "None":
if DISCORD_ENABLED_ERROR:
webhookFailure.send(f"Updated to {UPDATE_VERSION}", username="UPDATE", avatar_url="https://cdn-icons-png.flaticon.com/512/1688/1688988.png")
2023-03-19 18:50:29 +01:00
for cred in Credentials:
_mail = cred[0]
_password = cred[1]
if len(cred) == 3:
_otp = TOTP(cred[2])
2023-04-04 12:55:00 +02:00
printf("\n\n")
printf(_mail)
2023-03-19 18:50:29 +01:00
custom_sleep(1)
2023-04-12 00:01:24 +02:00
printf("Début du driver.")
2023-03-19 18:50:29 +01:00
driver = firefox_driver()
2023-04-12 00:01:24 +02:00
printf("Driver demarré.")
2023-03-19 18:50:29 +01:00
driver.implicitly_wait(3)
try:
daily_routine()
driver.quit()
attente = uniform(1200, 3600)
printf(f"finis. attente de {round(attente/60)}min")
custom_sleep(attente)
except KeyboardInterrupt:
printf("Canceled. Closing driver and display.")
2023-03-19 18:50:29 +01:00
driver.quit()
display.stop()
except Exception as e:
printf(f"Error not catched. Skipping this account. {e}")
2023-03-19 18:50:29 +01:00
driver.quit()
2023-01-29 00:51:30 +01:00
2023-02-27 13:41:54 +01:00
display.stop()