oh, f*ck, what have I done

This commit is contained in:
piair 2023-03-18 19:12:27 +01:00
parent 27237354b2
commit 66de4dbbd2
4 changed files with 96 additions and 83 deletions

139
V5.py
View File

@ -15,7 +15,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 pyotp import TOTP
from pyvirtualdisplay import Display from pyvirtualdisplay import Display
from pyvirtualdisplay.smartdisplay import SmartDisplay from pyvirtualdisplay.smartdisplay import SmartDisplay
@ -29,7 +29,7 @@ import modules.progress
global driver global driver
driver = None driver = None
global _mail, _password global _mail, _password, _otp, display
# TODO : replace by a better print (with logging, cf https://realpython.com/python-logging/) # TODO : replace by a better print (with logging, cf https://realpython.com/python-logging/)
def printf(e, f = ""): def printf(e, f = ""):
@ -37,13 +37,40 @@ 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
# replace driver's screenshot by Display's one # check that each card worked (lot of misses lately) -- test that
# test PlayQuiz8 fix
# check that each card worked (lot of misses lately)
# add date and account before print # add date and account before print
custom_sleep = CustomSleep custom_sleep = CustomSleep
def log_error(error, driver=driver log=FULL_LOG):
if type(error) != str :
error = format_error(error)
print(f"\n\n\033[93m Erreur : {str(error)} \033[0m\n\n")
if DISCORD_ENABLED_ERROR:
with open("page.html", "w") as f:
f.write(driver.page_source)
img = display.waitgrab()
img.save("screenshot.png")
if not log:
embed = discord.Embed(
title="An Error has occured",
description=str(error),
colour=Colour.red(),
)
else:
embed = discord.Embed(
title="Full log is enabled",
description=str(error),
colour=Colour.blue(),
)
file = discord.File("screenshot.png")
embed.set_image(url="attachment://screenshot.png")
embed.set_footer(text=_mail)
webhookFailure.send(embed=embed, file=file)
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 :
@ -145,7 +172,7 @@ def play_quiz2(override=10) -> None:
except exceptions.ElementNotInteractableException as e: except exceptions.ElementNotInteractableException as e:
driver.execute_script("arguments[0].click();", answer_elem) driver.execute_script("arguments[0].click();", answer_elem)
except Exception as e: except Exception as e:
log_error(e, driver, _mail) log_error(e)
break break
printf("play_quiz2 done") printf("play_quiz2 done")
@ -187,7 +214,7 @@ def play_quiz8(task = None):
correct_answers.append(answer_id) correct_answers.append(answer_id)
except Exception as e: except Exception as e:
log_error(f"{format_error(e)} \n Good answers : {' '.join(correct_answers)}", driver, _mail) log_error(f"{format_error(e)} \n Good answers : {' '.join(correct_answers)}")
printf("play_quiz8 : fin ") printf("play_quiz8 : fin ")
@ -214,7 +241,7 @@ def play_quiz4(override=None):
driver.execute_script("arguments[0].click();", answer_element) driver.execute_script("arguments[0].click();", answer_element)
except Exception as e: except Exception as e:
log_error(e, driver, _mail) log_error(e)
raise ValueError(e) raise ValueError(e)
printf("play_quiz4 : end") printf("play_quiz4 : end")
@ -230,7 +257,7 @@ def do_poll():
driver.execute_script("arguments[0].click();", answer_elem) driver.execute_script("arguments[0].click();", answer_elem)
custom_sleep(uniform(2, 2.5)) custom_sleep(uniform(2, 2.5))
except Exception as error: except Exception as error:
log_error(error , driver, _mail) log_error(error)
raise ValueError(error) raise ValueError(error)
printf("do_poll : end") printf("do_poll : end")
@ -272,15 +299,19 @@ def all_cards():
printf(f"DailyCard {titre} ok") printf(f"DailyCard {titre} ok")
except Exception as e: except Exception as e:
printf(f"all_cards card {titre} error ({e})") printf(f"all_cards card {titre} error ({e})")
""" Check if everything worked fine TODO
try : # devrait renvoyer vrai si la carte i est faite ou pas, a l'aide su symbole en haut a droite de la carte 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.get(By.XPATH, f"/html/body/div/div/div[3]/div[2]/div[1]/div[2]/div/div[{i+1}]/a/div/div[2]/div[1]/div[2]/div") elm = driver.find_element(By.XPATH, f"/html/body/div/div/div[3]/div[2]/div[1]/div[2]/div/div[{i+1}]/a/div/div[2]/div[1]/div[2]/div")
print("complete" in elm.get_attribute("innerHTML")) if not ("correctCircle" in elm.get_attribute("innerHTML")):
print(f"missed card {i}")
try_play(titre, task=task["daily"][f"carte{i}"])
sleep(3)
reset()
except : except :
pass pass # if it fail, it's probably okay
"""
except Exception as e: except Exception as e:
log_error(e, driver, _mail) log_error(e)
def weekly_cards(): def weekly_cards():
@ -328,17 +359,17 @@ def all_cards():
try : try :
top_cards() top_cards()
except Exception as e: except Exception as e:
log_error(e, driver, _mail) log_error(e)
try: try:
daily_cards() daily_cards()
except Exception as e: except Exception as e:
log_error(e, driver, _mail) log_error(e)
try : try :
weekly_cards() weekly_cards()
except Exception as e: except Exception as e:
log_error(e, driver, _mail) log_error(e)
# Find out which type of action to do # Find out which type of action to do
@ -373,7 +404,7 @@ def try_play(nom="inconnu", task = None):
except Exception as e: except Exception as e:
printf(f"fail of PlayQuiz 2. Aborted {e}") printf(f"fail of PlayQuiz 2. Aborted {e}")
else: else:
log_error("There is an error. rqAnswerOption present in page but no action to do. skipping.", driver, _mail) 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 driver.find_element(By.ID, "rqStartQuiz").click() # start the quiz
@ -424,10 +455,19 @@ def login():
pwd_elem = driver.find_element(By.ID, "i0118") pwd_elem = driver.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)
if "Entrez le code de sécurité" in driver.page_source :
try :
a2f_elem = driver.find_element(By.ID, "idTxtBx_SAOTCC_OTC")
a2f_elem.send_keys(_otp.now())
a2f_elem.send_keys(Keys.ENTER)
except Exception as e :
log_error(e)
custom_sleep(5) custom_sleep(5)
if ('Abuse' in driver.current_url) : if ('Abuse' in driver.current_url) :
log_error("account suspended", driver, _mail) log_error("account suspended")
raise Banned() raise Banned()
for id in ["KmsiCheckboxField","iLooksGood", "idSIButton9", "iCancel"]: for id in ["KmsiCheckboxField","iLooksGood", "idSIButton9", "iCancel"]:
@ -438,10 +478,11 @@ def login():
pass pass
try : try :
body_elem = driver.find_element(By.TAG_NAME, "body") body_elem = driver.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") driver.get("https://www.bing.com/rewardsapp/flyout")
@ -469,7 +510,7 @@ def login():
except Banned: except Banned:
raise Banned() raise Banned()
except Exception as e: except Exception as e:
log_error(e, driver, _mail) log_error(e)
driver.quit() driver.quit()
custom_sleep(1200) custom_sleep(1200)
driver = firefox_driver() driver = firefox_driver()
@ -511,7 +552,7 @@ def bing_pc_search(override=randint(35, 40)):
driver.get('https://www.bing.com/search?q=plans') driver.get('https://www.bing.com/search?q=plans')
driver.find_element(By.ID, "sb_form_q").clear() driver.find_element(By.ID, "sb_form_q").clear()
except Exception as e: except Exception as e:
log_error(f"clear la barre de recherche - {format_error(e)}", driver, _mail) log_error(f"clear la barre de recherche - {format_error(e)}")
AdvanceTask(task["PC"], 100 ) AdvanceTask(task["PC"], 100 )
ChangeColor(task["PC"], "green") ChangeColor(task["PC"], "green")
@ -570,11 +611,11 @@ def log_points(account="unknown"):
break break
except Exception as e: except Exception as e:
custom_sleep(300) custom_sleep(300)
log_error(e, driver, _mail) log_error(e)
points = None points = None
if not points : if not points :
log_error(f"impossible d'avoir les points", driver, _mail) log_error(f"impossible d'avoir les points")
custom_sleep(uniform(3, 20)) custom_sleep(uniform(3, 20))
account_name = account.split("@")[0] account_name = account.split("@")[0]
@ -636,7 +677,7 @@ def fidelity():
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 = 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() recover_elem.click()
except Exception as e2 : except Exception as e2 :
log_error(f"fidélité - double erreur - e1 : {format_error(e1)} - e2 {format_error(e2)}", driver, _mail) log_error(f"fidélité - double erreur - e1 : {format_error(e1)} - e2 {format_error(e2)}")
break break
custom_sleep(uniform(3, 5)) custom_sleep(uniform(3, 5))
driver.switch_to.window(driver.window_handles[1]) driver.switch_to.window(driver.window_handles[1])
@ -651,24 +692,24 @@ def fidelity():
else : else :
printf("invalid fidelity link.") printf("invalid fidelity link.")
except Exception as e: except Exception as e:
log_error(e, driver, _mail) log_error(e)
def mobile_login(error): def mobile_login(error):
try: try:
# TODO # TODO
# aller direct sur bin pour ne pas avoir a utiliser le menu hamburger # seems fine, check if there are no issues
mobile_driver.get("https://www.bing.com/search?q=test+speed") mobile_driver.get(f"https://www.bing.com/search?q={choice(Liste_de_mot).replace(" ","+")}")
mobile_rgpd() mobile_rgpd()
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()
except Exception as e : except Exception as e :
log_error(f"trying something. 1 {e}", mobile_driver, _mail) log_error(f"trying something. 1 {e}", mobile_driver)
elm = mobile_driver.find_element(By.ID, "mHamburger") elm = mobile_driver.find_element(By.ID, "mHamburger")
mobile_driver.execute_script("arguments[0].scrollIntoView();", elm) mobile_driver.execute_script("arguments[0].scrollIntoView();", elm)
mobile_driver.find_element(By.ID, "mHamburger").click() mobile_driver.find_element(By.ID, "mHamburger").click()
log_error(f"trying something. 2 {e}", mobile_driver, _mail) log_error(f"trying something. 2 {e}", mobile_driver)
wait_until_visible(By.ID, "hb_s", browser=mobile_driver) wait_until_visible(By.ID, "hb_s", browser=mobile_driver)
mobile_driver.find_element(By.ID, "hb_s").click() mobile_driver.find_element(By.ID, "hb_s").click()
@ -696,9 +737,7 @@ def mobile_login(error):
custom_sleep(uniform(5, 10)) custom_sleep(uniform(5, 10))
mobile_login(error) mobile_login(error)
else: else:
log_error( log_error(f"login impossible 3 fois de suite. {e}", mobile_driver)
f"login impossible 3 fois de suite. {e}", mobile_driver, _mail
)
mobile_driver.quit() mobile_driver.quit()
return(True) return(True)
@ -718,7 +757,7 @@ def mobile_alert_popup():
except exceptions.NoAlertPresentException as e: except exceptions.NoAlertPresentException as e:
pass pass
except Exception as e: except Exception as e:
log_error(e, mobile_driver, _mail) log_error(e, mobile_driver)
def bing_mobile_search(override=randint(22, 25)): def bing_mobile_search(override=randint(22, 25)):
@ -748,7 +787,7 @@ def bing_mobile_search(override=randint(22, 25)):
ChangeColor(task["Mobile"], "green") ChangeColor(task["Mobile"], "green")
except Exception as e: except Exception as e:
log_error(e, mobile_driver, _mail) log_error(e, mobile_driver)
mobile_driver.quit() mobile_driver.quit()
@ -758,33 +797,33 @@ def daily_routine(custom = False):
if not custom: # custom already login if not custom: # custom already login
login() login()
except Banned : except Banned :
log_error("THIS ACCOUNT IS BANNED. FIX THIS ISSUE WITH -U", driver, _mail) log_error("THIS ACCOUNT IS BANNED. FIX THIS ISSUE WITH -U")
return() return()
try: try:
all_cards() all_cards()
except Exception as e: except Exception as e:
log_error(e, driver, _mail) log_error(e)
try: try:
bing_pc_search() bing_pc_search()
except Exception as e: except Exception as e:
log_error(e, driver, _mail) log_error(e)
try: try:
bing_mobile_search() bing_mobile_search()
except Exception as e: except Exception as e:
log_error(e, driver, _mail) log_error(e)
try: try:
fidelity() fidelity()
except Exception as e: except Exception as e:
log_error(e, driver, _mail) log_error(e)
try: try:
log_points(_mail) log_points(_mail)
except Exception as e: except Exception as e:
log_error(e, driver, _mail) log_error(e)
def dev(): def dev():
@ -823,27 +862,27 @@ def CustomStart(Credentials):
try: try:
all_cards() all_cards()
except Exception as e: except Exception as e:
log_error(e, driver, _mail) log_error(e)
if "pc" in Actions: if "pc" in Actions:
try: try:
ShowTask(task["PC"]) ShowTask(task["PC"])
bing_pc_search() bing_pc_search()
except Exception as e: except Exception as e:
log_error(e, driver, _mail) log_error(e)
if "mobile" in Actions: if "mobile" in Actions:
try: try:
ShowTask(task["Mobile"]) ShowTask(task["Mobile"])
bing_mobile_search() bing_mobile_search()
except Exception as e: except Exception as e:
log_error(e, driver, _mail) 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, driver, _mail) log_error(e)
if "dev" in Actions: if "dev" in Actions:
try: try:
@ -937,8 +976,12 @@ else:
) as p: ) as p:
task = modules.progress.dico(p) task = modules.progress.dico(p)
for _mail, _password in Credentials: for cred in Credentials:
#system("pkill -9 firefox") _mail = cred[0]
_password = cred[1]
if len(cred) == 3:
_otp = TOTP(cred[2])
print("\n\n") print("\n\n")
print(_mail) print(_mail)
custom_sleep(1) custom_sleep(1)

View File

@ -7,7 +7,9 @@ import argparse
from discord import ( # Importing discord.Webhook and discord.RequestsWebhookAdapter from discord import ( # Importing discord.Webhook and discord.RequestsWebhookAdapter
RequestsWebhookAdapter, RequestsWebhookAdapter,
Webhook, Webhook,
Colour,
) )
from time import time from time import time
from random import shuffle from random import shuffle

View File

@ -2,10 +2,6 @@ from time import sleep
from datetime import timedelta, datetime from datetime import timedelta, datetime
from random import uniform from random import uniform
import discord import discord
from discord import ( # Importing discord.Webhook and discord.RequestsWebhookAdapter
Colour,
Webhook,
)
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
from modules.config import * from modules.config import *
@ -23,35 +19,6 @@ def send_keys_wait(element, keys):
sleep(uniform(0.1, 0.3)) sleep(uniform(0.1, 0.3))
def log_error(error, driver, mail, log=FULL_LOG):
if type(error) != str :
error = format_error(error)
print(f"\n\n\033[93m Erreur : {str(error)} \033[0m\n\n")
if DISCORD_ENABLED_ERROR:
with open("page.html", "w") as f:
f.write(driver.page_source)
driver.save_screenshot("screenshot.png")
if not log:
embed = discord.Embed(
title="An Error has occured",
description=str(error),
colour=Colour.red(),
)
else:
embed = discord.Embed(
title="Full log is enabled",
description=str(error),
colour=Colour.blue(),
)
file = discord.File("screenshot.png")
embed.set_image(url="attachment://screenshot.png")
embed.set_footer(text=mail)
webhookFailure.send(embed=embed, file=file)
webhookFailure.send(file=discord.File("page.html"))
# add the time arround the text given in [text]& # add the time arround the text given in [text]&
def Timer(text: str, mail: str) -> str: def Timer(text: str, mail: str) -> str:

View File

@ -8,3 +8,4 @@ requests
pyvirtualdisplay pyvirtualdisplay
pillow pillow
EasyProcess EasyProcess
pyotp