OMG I tested before commiting. (btw cookies login is now implemented)

This commit is contained in:
piair 2023-03-25 18:14:41 +01:00
parent 6fefaca00a
commit db4ab3bf90
1 changed files with 96 additions and 98 deletions

194
V5.py
View File

@ -18,7 +18,7 @@ from selenium.webdriver.support.ui import Select
from pyotp import TOTP from pyotp import TOTP
from pyvirtualdisplay import Display from pyvirtualdisplay import Display
from pyvirtualdisplay.smartdisplay import SmartDisplay from pyvirtualdisplay.smartdisplay import SmartDisplay
import pickle
from modules.db import add_to_database from modules.db import add_to_database
from modules.config import * from modules.config import *
@ -37,10 +37,17 @@ def printf(e, f = ""):
# TODO # TODO
# handle "panda"'s error: error while logging in preventing some task to be done # handle "panda"'s error: error while logging in preventing some task to be done
# check that each card worked (lot of misses lately) -- test that -- don't crash at least # check that each card worked (lot of misses lately) -- test that -- don't crash at least
# add date and account before print
custom_sleep = CustomSleep custom_sleep = CustomSleep
def save_cookies():
pickle.dump(driver.get_cookies(), open(f"{'/'.join(__file__.split('/')[:-1])}/user_data/cookies/{_mail}.pkl", "wb"))
def load_cookies(driver):
cookies = pickle.load(open(f"{'/'.join(__file__.split('/')[:-1])}/user_data/cookies/{_mail}.pkl", "rb"))
for cookie in cookies:
driver.add_cookie(cookie)
def log_error(error, ldriver=driver, log=FULL_LOG): def log_error(error, ldriver=driver, log=FULL_LOG):
global driver global driver
@ -73,6 +80,7 @@ def log_error(error, ldriver=driver, log=FULL_LOG):
webhookFailure.send(embed=embed, file=file) webhookFailure.send(embed=embed, file=file)
webhookFailure.send(file=discord.File("page.html")) webhookFailure.send(file=discord.File("page.html"))
# Wait for the presence of the element identifier or [timeout]s # Wait for the presence of the element identifier or [timeout]s
def wait_until_visible(search_by: str, identifier: str, timeout = 20, browser = driver) -> None: def wait_until_visible(search_by: str, identifier: str, timeout = 20, browser = driver) -> None:
try : try :
@ -123,11 +131,9 @@ def firefox_driver(mobile=False, Headless=False):
options.set_preference("general.useragent.override", PC_USER_AGENT) options.set_preference("general.useragent.override", PC_USER_AGENT)
driver = webdriver.Firefox(options=options) driver = webdriver.Firefox(options=options)
driver.set_window_size(1900 + hash(_mail)%20 , 1070 + hash(_password + "salt")%10) driver.set_window_size(1900 + hash(_mail)%20 , 1070 + hash(_password + "salt")%10)
return(driver) return(driver)
# close the tab currently on and go back to the one first, or the one specified # close the tab currently on and go back to the one first, or the one specified
def close_tab(tab, SwitchTo=0) -> None: def close_tab(tab, SwitchTo=0) -> None:
driver.switch_to.window(tab) driver.switch_to.window(tab)
@ -136,7 +142,7 @@ def close_tab(tab, SwitchTo=0) -> None:
#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() -> 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:
driver.find_element(By.ID, i).click() driver.find_element(By.ID, i).click()
@ -150,7 +156,7 @@ def play_quiz2(override=10) -> None:
printf("starting play_quiz2") printf("starting play_quiz2")
for j in range(override): for j in range(override):
try: try:
rgpd_popup() rgpd_popup(driver)
custom_sleep(uniform(3, 5)) custom_sleep(uniform(3, 5))
page_html = driver.page_source page_html = driver.page_source
secret_answer = search('IG:"([^"]+)"', page_html)[1] # variable used to calculate offset secret_answer = search('IG:"([^"]+)"', page_html)[1] # variable used to calculate offset
@ -184,7 +190,7 @@ def play_quiz8():
printf(f"play_quiz8 : start, override : {override}") printf(f"play_quiz8 : start, override : {override}")
try: try:
counter = 0 counter = 0
rgpd_popup() rgpd_popup(driver)
for _ in range(override): for _ in range(override):
custom_sleep(uniform(3, 5)) custom_sleep(uniform(3, 5))
correct_answers = [] correct_answers = []
@ -210,7 +216,7 @@ def play_quiz8():
answer_elem = driver.find_element(By.ID, answer_id) answer_elem = driver.find_element(By.ID, answer_id)
answer_elem.click() answer_elem.click()
except ElementClickInterceptedException : except ElementClickInterceptedException :
rgpd_popup() rgpd_popup(driver)
correct_answers.append(answer_id) correct_answers.append(answer_id)
except Exception as e: except Exception as e:
@ -231,7 +237,7 @@ def play_quiz4(override=None):
for i in range(override): for i in range(override):
custom_sleep(uniform(3, 5)) custom_sleep(uniform(3, 5))
txt = driver.page_source txt = driver.page_source
rgpd_popup() rgpd_popup(driver)
answer_option = search('correctAnswer":"([^"]+)', txt)[1] answer_option = search('correctAnswer":"([^"]+)', txt)[1]
answer_option = answer_option.replace("\\u0027", "'") # replace Unicode weird symbols answer_option = answer_option.replace("\\u0027", "'") # replace Unicode weird symbols
try: try:
@ -309,7 +315,6 @@ def all_cards():
except Exception as e: except Exception as e:
log_error(e) log_error(e)
def weekly_cards(): def weekly_cards():
try: try:
driver.find_element( driver.find_element(
@ -342,7 +347,6 @@ def all_cards():
except: except:
break break
def top_cards(): def top_cards():
for _ in range(10): for _ in range(10):
try : try :
@ -370,7 +374,7 @@ def all_cards():
# 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() rgpd_popup(driver)
printf("try_play en cours") printf("try_play en cours")
def play(number): def play(number):
@ -411,7 +415,7 @@ def try_play(nom="inconnu"):
if "bt_PollRadio" in driver.page_source: if "bt_PollRadio" in driver.page_source:
try: try:
printf("Poll detected") printf("Poll detected")
rgpd_popup() rgpd_popup(driver)
do_poll() do_poll()
printf("Poll succeeded") printf("Poll succeeded")
except Exception as e: except Exception as e:
@ -427,92 +431,104 @@ def try_play(nom="inconnu"):
elif search("([0-9]) de ([0-9]) finalisée", driver.page_source): elif search("([0-9]) de ([0-9]) finalisée", driver.page_source):
print("fidélité") print("fidélité")
rgpd_popup() rgpd_popup(driver)
fidelity() fidelity()
else: else:
printf(f"rien à faire sur la page {nom}") printf(f"rien à faire sur la page {nom}")
rgpd_popup() rgpd_popup(driver)
custom_sleep(uniform(3, 5)) custom_sleep(uniform(3, 5))
# login() tries to login to your Microsoft account. # login() tries to login to your Microsoft account.
# it uses global variable _mail and _password to login # it uses global variable _mail and _password to login
def login(): def login(ldriver):
global driver def pwd_login():
def sub_login(): printf("pwd_login : start")
printf("sub_login : start") ldriver.get("https://login.live.com")
driver.get("https://login.live.com")
custom_sleep(2) custom_sleep(2)
wait_until_visible(By.ID, "i0116", browser = driver) wait_until_visible(By.ID, "i0116", browser = ldriver)
mail_elem = driver.find_element(By.ID, "i0116") mail_elem = ldriver.find_element(By.ID, "i0116")
send_keys_wait(mail_elem, _mail) send_keys_wait(mail_elem, _mail)
mail_elem.send_keys(Keys.ENTER) mail_elem.send_keys(Keys.ENTER)
custom_sleep(2) custom_sleep(2)
wait_until_visible(By.ID, "i0118", browser = driver) wait_until_visible(By.ID, "i0118", browser = ldriver)
pwd_elem = driver.find_element(By.ID, "i0118") pwd_elem = ldriver.find_element(By.ID, "i0118")
send_keys_wait(pwd_elem, _password) send_keys_wait(pwd_elem, _password)
pwd_elem.send_keys(Keys.ENTER) pwd_elem.send_keys(Keys.ENTER)
custom_sleep(2) custom_sleep(2)
if "Entrez le code de sécurité" in driver.page_source : if "Entrez le code de sécurité" in ldriver.page_source :
try : try :
a2f_elem = driver.find_element(By.ID, "idTxtBx_SAOTCC_OTC") a2f_elem = ldriver.find_element(By.ID, "idTxtBx_SAOTCC_OTC")
a2f_elem.send_keys(_otp.now()) a2f_elem.send_keys(_otp.now())
a2f_elem.send_keys(Keys.ENTER) a2f_elem.send_keys(Keys.ENTER)
except Exception as e : except Exception as e :
log_error(e) log_error(e)
custom_sleep(5) custom_sleep(5)
if ('Abuse' in ldriver.current_url) :
if ('Abuse' in driver.current_url) :
log_error("account suspended") log_error("account suspended")
raise Banned() raise Banned()
save_cookies()
for id in ["KmsiCheckboxField","iLooksGood", "idSIButton9", "iCancel"]: for id in ["KmsiCheckboxField","iLooksGood", "idSIButton9", "iCancel"]:
try: try:
driver.find_element(By.ID, id).click() ldriver.find_element(By.ID, id).click()
restart = True restart = True
except Exception as e: except Exception as e:
pass pass
try : try :
body_elem = driver.find_element(By.TAG_NAME, "body") # in case of any random popup body_elem = ldriver.find_element(By.TAG_NAME, "body") # in case of any random popup
body_elem.send_keys(Keys.ENTER) body_elem.send_keys(Keys.ENTER)
except : except :
pass pass
printf("login completed - going to MsRewards") printf("login completed - going to MsRewards")
custom_sleep(uniform(3,5)) custom_sleep(uniform(3,5))
driver.get("https://www.bing.com/rewardsapp/flyout") ldriver.get("https://www.bing.com/rewardsapp/flyout")
custom_sleep(uniform(3,5)) custom_sleep(uniform(3,5))
for i in [f'[title="Rejoindre maintenant"]', f'[title="Rejoindre"]', f'[title="Join now"]'] : for i in [f'[title="Rejoindre maintenant"]', f'[title="Rejoindre"]', f'[title="Join now"]'] :
try: try:
driver.find_element(By.CSS_SELECTOR, i).click() # depend of the language of the page ldriver.find_element(By.CSS_SELECTOR, i).click() # depend of the language of the page
except: except:
print(f"element {i} not found") print(f"element {i} not found")
rgpd_popup() rgpd_popup(ldriver)
custom_sleep(uniform(3,5)) custom_sleep(uniform(3,5))
ldriver.get("https://www.bing.com/rewardsapp/flyout")
driver.get("https://www.bing.com/rewardsapp/flyout")
try: try:
driver.find_element(By.CSS_SELECTOR, '[title="Rejoindre maintenant"]').click() # depend of the language of the page ldriver.find_element(By.CSS_SELECTOR, '[title="Rejoindre maintenant"]').click() # depend of the language of the page
except: except:
print(f"unlock test: fail, probably normal") print(f"unlock test: fail, probably normal")
print('on MsRewards') print('on MsRewards')
for _ in range(3) : def cookie_login():
ldriver.get("https://login.live.com")
try : try :
sub_login() load_cookies(ldriver)
return (driver.current_window_handle) except FileNotFoundError :
except Banned: print("Creating cookies file")
raise Banned()
except Exception as e: ldriver.refresh()
log_error(e) CustomSleep(10)
driver.quit() if ("account.microsoft.com" in ldriver.current_url) :
custom_sleep(1200) ldriver.get("https://bing.com")
driver = firefox_driver() rgpd_popup(ldriver)
return("STOP") ldriver.get("https://www.bing.com/rewardsapp/flyout")
return(True)
return(False)
try :
if cookie_login():
return (ldriver.current_window_handle)
pwd_login()
return(ldriver.current_window_handle)
except Banned:
raise Banned()
except Exception as e:
log_error(e)
ldriver.quit()
# Makes 30 search as PC Edge # Makes 30 search as PC Edge
@ -520,7 +536,7 @@ def bing_pc_search(override=randint(35, 40)):
mot = choice(Liste_de_mot).replace(" ","+") mot = choice(Liste_de_mot).replace(" ","+")
driver.get(f"https://www.bing.com/search?q={mot}") # {choice(Liste_de_mot)}') driver.get(f"https://www.bing.com/search?q={mot}") # {choice(Liste_de_mot)}')
custom_sleep(uniform(1, 2)) custom_sleep(uniform(1, 2))
rgpd_popup() rgpd_popup(driver)
send_keys_wait( send_keys_wait(
driver.find_element(By.ID, "sb_form_q"), driver.find_element(By.ID, "sb_form_q"),
Keys.BACKSPACE + Keys.BACKSPACE + Keys.BACKSPACE + Keys.BACKSPACE + Keys.BACKSPACE + Keys.BACKSPACE Keys.BACKSPACE + Keys.BACKSPACE + Keys.BACKSPACE + Keys.BACKSPACE + Keys.BACKSPACE + Keys.BACKSPACE
@ -695,13 +711,13 @@ def fidelity():
log_error(e) log_error(e)
def mobile_login(error): def mobile_login_pwd(error):
try: try:
# TODO # TODO
# seems fine, check if there are no issues # seems fine, check if there are no issues NO
mot = choice(Liste_de_mot).replace(" ","+") mot = choice(Liste_de_mot).replace(" ","+")
mobile_driver.get(f"https://www.bing.com/search?q={mot}") mobile_driver.get(f"https://www.bing.com/search?q={mot}")
mobile_rgpd() rgpd_popup(mobile_driver)
printf("start of Mobile login") printf("start of Mobile login")
try : try :
mobile_driver.find_element(By.ID, "mHamburger").click() mobile_driver.find_element(By.ID, "mHamburger").click()
@ -742,21 +758,13 @@ def mobile_login(error):
if error <= 3: if error <= 3:
printf(f"failure on mobile_login. Retrying({error}/3), {e}") printf(f"failure on mobile_login. Retrying({error}/3), {e}")
custom_sleep(uniform(5, 10)) custom_sleep(uniform(5, 10))
mobile_login(error) mobile_login_pwd(error)
else: else:
log_error(f"login impossible 3 fois de suite. {e}", mobile_driver) log_error(f"login impossible 3 fois de suite. {e}", mobile_driver)
mobile_driver.quit() mobile_driver.quit()
return(True) return(True)
def mobile_rgpd():
for id in ["bnp_btn_accept", "bnp_hfly_cta2"]:
try:
mobile_driver.find_element(By.ID, id).click()
except Exception:
pass
def mobile_alert_popup(): def mobile_alert_popup():
try: try:
alert = mobile_driver.switch_to.alert alert = mobile_driver.switch_to.alert
@ -768,27 +776,30 @@ def mobile_alert_popup():
def bing_mobile_search(override=randint(22, 25)): def bing_mobile_search(override=randint(22, 25)):
print(1)
global mobile_driver global mobile_driver
mobile_driver = firefox_driver(mobile=True) mobile_driver = firefox_driver(mobile=True)
try: try:
if not mobile_login(0): login(mobile_driver)
custom_sleep(uniform(1, 2)) mot = choice(Liste_de_mot).replace(" ","+")
mobile_rgpd() mobile_driver.get(f"https://www.bing.com/search?q={mot}")
custom_sleep(uniform(1, 1.5)) custom_sleep(uniform(1, 2))
rgpd_popup(mobile_driver)
for i in range(override): # 20 custom_sleep(uniform(1, 1.5))
try : for i in range(override): # 20
mot = choice(Liste_de_mot) try :
send_keys_wait(mobile_driver.find_element(By.ID, "sb_form_q"), mot) mot = choice(Liste_de_mot)
mobile_driver.find_element(By.ID, "sb_form_q").send_keys(Keys.ENTER) send_keys_wait(mobile_driver.find_element(By.ID, "sb_form_q"), mot)
custom_sleep(uniform(5, 20)) mobile_driver.find_element(By.ID, "sb_form_q").send_keys(Keys.ENTER)
mobile_alert_popup() # check for alert (asking for position or for allowing notifications) custom_sleep(uniform(5, 20))
mobile_driver.find_element(By.ID, "sb_form_q").clear() mobile_alert_popup() # check for alert (asking for position or for allowing notifications)
except : mobile_driver.find_element(By.ID, "sb_form_q").clear()
driver.refresh() except Exception as e:
custom_sleep(30) print(e)
i -= 1 mobile_driver.refresh()
mobile_driver.quit() custom_sleep(30)
i -= 1
mobile_driver.quit()
except Exception as e: except Exception as e:
log_error(e, mobile_driver) log_error(e, mobile_driver)
@ -798,7 +809,7 @@ def bing_mobile_search(override=randint(22, 25)):
def daily_routine(custom = False): def daily_routine(custom = False):
try : try :
if not custom: # custom already login if not custom: # custom already login
login() login(driver)
except Banned : except Banned :
log_error("THIS ACCOUNT IS BANNED. FIX THIS ISSUE WITH -U") log_error("THIS ACCOUNT IS BANNED. FIX THIS ISSUE WITH -U")
return() return()
@ -854,41 +865,35 @@ def CustomStart(Credentials):
driver = firefox_driver() driver = firefox_driver()
driver.implicitly_wait(3) driver.implicitly_wait(3)
if login() != "STOP": if login(driver) != "STOP":
if "tout" in Actions: if "tout" in Actions:
daily_routine(True) daily_routine(True)
if "daily" in Actions: if "daily" in Actions:
try: try:
all_cards() all_cards()
except Exception as e: except Exception as e:
log_error(e) log_error(e)
if "pc" in Actions: if "pc" in Actions:
try: try:
bing_pc_search() bing_pc_search()
except Exception as e: except Exception as e:
log_error(e) log_error(e)
if "mobile" in Actions: if "mobile" in Actions:
try: try:
bing_mobile_search() bing_mobile_search()
except Exception as e: except Exception as e:
log_error(e) log_error(e)
if "fidelity" in Actions: if "fidelity" in Actions:
try : try :
fidelity() fidelity()
except Exception as e : except Exception as e :
log_error(e) log_error(e)
if "dev" in Actions: if "dev" in Actions:
try: try:
dev() dev()
except Exception as e: except Exception as e:
printf(e) printf(e)
break break
if not "tout" in Actions: if not "tout" in Actions:
try: try:
log_points(_mail) log_points(_mail)
@ -912,13 +917,11 @@ def SavePointsFromFile(file):
for item in points_list: for item in points_list:
compte, points = item[0], item[1] compte, points = item[0], item[1]
add_to_database(compte, points, sql_host,sql_usr,sql_pwd,sql_database, save_if_fail=False) add_to_database(compte, points, sql_host,sql_usr,sql_pwd,sql_database, save_if_fail=False)
with open(file, "w") as f: with open(file, "w") as f:
f.write("") f.write("")
if VNC_ENABLED : if VNC_ENABLED :
display = SmartDisplay(backend="xvnc", size=(2160, 2160), rfbport=VNC_PORT, color_depth=24) display = SmartDisplay(backend="xvnc", size=(2160, 2160), rfbport=VNC_PORT, color_depth=24)
else : else :
@ -932,12 +935,11 @@ elif UNBAN:
_mail, _password = select_accounts(False)[0] _mail, _password = select_accounts(False)[0]
driver = firefox_driver() driver = firefox_driver()
try : try :
login() login(driver)
except Banned: except Banned:
unban() unban()
driver.quit() driver.quit()
elif POINTS_FILE != "": elif POINTS_FILE != "":
SavePointsFromFile(POINTS_FILE) SavePointsFromFile(POINTS_FILE)
else: else:
@ -946,7 +948,6 @@ else:
_password = cred[1] _password = cred[1]
if len(cred) == 3: if len(cred) == 3:
_otp = TOTP(cred[2]) _otp = TOTP(cred[2])
print("\n\n") print("\n\n")
print(_mail) print(_mail)
custom_sleep(1) custom_sleep(1)
@ -954,14 +955,12 @@ else:
driver = firefox_driver() driver = firefox_driver()
printf("driver demarré") printf("driver demarré")
driver.implicitly_wait(3) driver.implicitly_wait(3)
try: try:
daily_routine() daily_routine()
driver.quit() driver.quit()
attente = uniform(1200, 3600) attente = uniform(1200, 3600)
printf(f"finis. attente de {round(attente/60)}min") printf(f"finis. attente de {round(attente/60)}min")
custom_sleep(attente) custom_sleep(attente)
except KeyboardInterrupt: except KeyboardInterrupt:
print("canceled. Closing driver and display.") print("canceled. Closing driver and display.")
driver.quit() driver.quit()
@ -970,5 +969,4 @@ else:
print(f"error not catch. skipping this account. {e}") print(f"error not catch. skipping this account. {e}")
driver.quit() driver.quit()
display.stop() display.stop()