just a little bit of formatting, with black

This commit is contained in:
piair 2022-04-14 23:03:16 +02:00
parent 219a05bdd5
commit 930c70db41
1 changed files with 514 additions and 414 deletions

370
V4.py
View File

@ -12,7 +12,11 @@ from time import sleep, time
from requests import get from requests import get
import discord import discord
from discord import ( # Importing discord.Webhook and discord.RequestsWebhookAdapter from discord import ( # Importing discord.Webhook and discord.RequestsWebhookAdapter
Colour, Embed, RequestsWebhookAdapter, Webhook) Colour,
Embed,
RequestsWebhookAdapter,
Webhook,
)
from selenium import webdriver from selenium import webdriver
from selenium.common import exceptions from selenium.common import exceptions
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
@ -24,9 +28,19 @@ import argparse
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("-o" , "--override", help="override", dest="override", action = "store_true") parser.add_argument(
parser.add_argument("-l", "--log",dest="log",help="enable logging in terminal", action ="store_true") "-o", "--override", help="override", dest="override", action="store_true"
parser.add_argument("-fl", "--fulllog",dest="fulllog",help="enable full logging in terminal", action ="store_true") )
parser.add_argument(
"-l", "--log", dest="log", help="enable logging in terminal", action="store_true"
)
parser.add_argument(
"-fl",
"--fulllog",
dest="fulllog",
help="enable full logging in terminal",
action="store_true",
)
args = parser.parse_args() args = parser.parse_args()
override = args.override override = args.override
@ -36,11 +50,14 @@ FullLog = args.fulllog
IsLinux = platform == "linux" IsLinux = platform == "linux"
start_time = time() start_time = time()
def Timer(text="undefined"): def Timer(text="undefined"):
print(f"-- Temps {time() - start_time} fonction : {text} --") print(f"-- Temps {time() - start_time} fonction : {text} --")
if IsLinux: if IsLinux:
import enquiries import enquiries
Timer() Timer()
else: else:
system("") # enable colors in cmd system("") # enable colors in cmd
@ -59,14 +76,16 @@ Headless = config["DEFAULT"]["headless"] == "True"
g = open(MotPath, "r", encoding="utf-8") g = open(MotPath, "r", encoding="utf-8")
Liste_de_mot=(list(g.readline().split(','))) Liste_de_mot = list(g.readline().split(","))
g.close() g.close()
webhookSuccess = Webhook.from_url(SuccessLink, adapter=RequestsWebhookAdapter()) webhookSuccess = Webhook.from_url(SuccessLink, adapter=RequestsWebhookAdapter())
webhookFailure = Webhook.from_url(ErrorLink, adapter=RequestsWebhookAdapter()) webhookFailure = Webhook.from_url(ErrorLink, adapter=RequestsWebhookAdapter())
def resource_path(relative_path): #permet de recuperer l'emplacement de chaque fichier, sur linux et windows def resource_path(
relative_path
): # permet de recuperer l'emplacement de chaque fichier, sur linux et windows
try: try:
base_path = sys._MEIPASS base_path = sys._MEIPASS
except Exception: except Exception:
@ -75,19 +94,21 @@ def resource_path(relative_path): #permet de recuperer l'emplacement de chaque f
def FirefoxMobile(Headless=Headless): def FirefoxMobile(Headless=Headless):
MOBILE_USER_AGENT = ('Mozilla/5.0 (iPhone; CPU iPhone OS 14_8_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Mobile/15E148 Safari/604.1') MOBILE_USER_AGENT = "Mozilla/5.0 (iPhone; CPU iPhone OS 14_8_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Mobile/15E148 Safari/604.1"
options = Options() options = Options()
options.set_preference("browser.link.open_newwindow", 3) options.set_preference("browser.link.open_newwindow", 3)
if Headless: if Headless:
options.add_argument("-headless") options.add_argument("-headless")
options.set_preference("general.useragent.override", MOBILE_USER_AGENT) options.set_preference("general.useragent.override", MOBILE_USER_AGENT)
return(webdriver.Firefox(options=options)) return webdriver.Firefox(options=options)
def FirefoxPC(Headless=Headless): def FirefoxPC(Headless=Headless):
PC_USER_AGENT = ('Mozilla/5.0 (Windows NT 10.0; Win64; x64) ' PC_USER_AGENT = (
'AppleWebKit/537.36 (KHTML, like Gecko) ' "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
'Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134') "AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134"
)
options = Options() options = Options()
options.set_preference("general.useragent.override", PC_USER_AGENT) options.set_preference("general.useragent.override", PC_USER_AGENT)
@ -96,10 +117,12 @@ def FirefoxPC(Headless = Headless):
if Headless: if Headless:
options.add_argument("-headless") options.add_argument("-headless")
return webdriver.Firefox(options=options)
return(webdriver.Firefox(options=options))
driver = "" driver = ""
def printf(txt, end="", Mobdriver=driver): def printf(txt, end="", Mobdriver=driver):
if Log: if Log:
Timer(txt) Timer(txt)
@ -110,15 +133,24 @@ def printf(txt, end="", Mobdriver = driver):
def CustomSleep(temps): def CustomSleep(temps):
if Log or not IsLinux: if Log or not IsLinux:
c = False c = False
points = [" . ", " . ", " . ", " .", " .", " . ", " . "," . "] points = [
" . ",
" . ",
" . ",
" .",
" .",
" . ",
" . ",
" . ",
]
for i in range(int(temps)): for i in range(int(temps)):
c = True c = True
for i in range(8): for i in range(8):
sleep(0.125) sleep(0.125)
print(points[i], end='\r') print(points[i], end="\r")
if c: if c:
print('. ', end="\r") print(". ", end="\r")
sleep(temps - int(temps)) sleep(temps - int(temps))
print("\n") print("\n")
else: else:
@ -134,7 +166,7 @@ def ListTabs(Mdriver = None):
for i in ldriver.window_handles: for i in ldriver.window_handles:
ldriver.switch_to.window(i) ldriver.switch_to.window(i)
tabs.append(ldriver.current_url) tabs.append(ldriver.current_url)
return(tabs) return tabs
def LogError(message, log=FullLog, Mobdriver=None): def LogError(message, log=FullLog, Mobdriver=None):
@ -143,9 +175,9 @@ def LogError(message,log = FullLog, Mobdriver = None):
else: else:
gdriver = driver gdriver = driver
if not log: if not log:
print(f'\n\n\033[93m Erreur : {str(message)} \033[0m\n\n') print(f"\n\n\033[93m Erreur : {str(message)} \033[0m\n\n")
if IsLinux: if IsLinux:
with open('page.html', 'w') as f: with open("page.html", "w") as f:
f.write(gdriver.page_source) f.write(gdriver.page_source)
gdriver.save_screenshot("screenshot.png") gdriver.save_screenshot("screenshot.png")
@ -154,28 +186,28 @@ def LogError(message,log = FullLog, Mobdriver = None):
title="An Error has occured", title="An Error has occured",
description=str(message), description=str(message),
url=ListTabs(Mdriver=Mobdriver)[0], url=ListTabs(Mdriver=Mobdriver)[0],
colour = Colour.red() colour=Colour.red(),
) )
else: else:
embed = discord.Embed( embed = discord.Embed(
title="Full log is enabled", title="Full log is enabled",
description=str(message), description=str(message),
url=ListTabs(Mdriver=Mobdriver)[0], url=ListTabs(Mdriver=Mobdriver)[0],
colour = Colour.blue() colour=Colour.blue(),
) )
file = discord.File("screenshot.png") file = discord.File("screenshot.png")
embed.set_image(url="attachment://screenshot.png") embed.set_image(url="attachment://screenshot.png")
embed.set_footer(text=_mail) embed.set_footer(text=_mail)
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"))
def progressBar(current, total=30, barLength=20, name="Progress"): def progressBar(current, total=30, barLength=20, name="Progress"):
percent = float(current + 1) * 100 / total percent = float(current + 1) * 100 / total
arrow = '-' * int(percent/100 * barLength - 1) + '>' arrow = "-" * int(percent / 100 * barLength - 1) + ">"
spaces = ' ' * (barLength - len(arrow)) spaces = " " * (barLength - len(arrow))
print(name + ': [%s%s] %d %%' % (arrow, spaces, percent), end='\r') print(name + ": [%s%s] %d %%" % (arrow, spaces, percent), end="\r")
def Close(fenetre, SwitchTo=0): def Close(fenetre, SwitchTo=0):
@ -186,11 +218,11 @@ def Close(fenetre, SwitchTo = 0):
def RGPD(): def RGPD():
try: try:
driver.find_element(By.ID, 'bnp_btn_accept').click() driver.find_element(By.ID, "bnp_btn_accept").click()
except: except:
pass pass
try: try:
driver.find_element(By.ID, 'bnp_hfly_cta2').click() driver.find_element(By.ID, "bnp_hfly_cta2").click()
except: except:
pass pass
@ -204,22 +236,22 @@ def PlayQuiz2(override= None):
RGPD() RGPD()
CustomSleep(uniform(3, 5)) CustomSleep(uniform(3, 5))
txt = driver.page_source txt = driver.page_source
secret = search('IG:\"([^\"]+)\"', txt)[1] #variable dans la page, pour calculer le offset secret = search('IG:"([^"]+)"', txt)[1] # variable dans la page, pour calculer le offset
reponse1 = search("data-option=\"([^\"]+)\"", txt)[1] reponse1 = search('data-option="([^"]+)"', txt)[1]
offset = int(secret[-2:], 16) # la conversion ec decimal des deux dernier caracteres de IG offset = int(secret[-2:], 16) # la conversion ec decimal des deux dernier caracteres de IG
reponse = search("correctAnswer\":\"([0-9]+)", txt)[1] reponse = search('correctAnswer":"([0-9]+)', txt)[1]
somme = 0 somme = 0
for i in reponse1: for i in reponse1:
somme += ord(i) somme += ord(i)
if somme + offset == int(reponse): if somme + offset == int(reponse):
elem = driver.find_element(By.ID, 'rqAnswerOption0') elem = driver.find_element(By.ID, "rqAnswerOption0")
elem.click() elem.click()
progressBar(j, 10, name="quiz 2") progressBar(j, 10, name="quiz 2")
else: else:
elem = driver.find_element(By.ID, 'rqAnswerOption1') elem = driver.find_element(By.ID, "rqAnswerOption1")
elem.click() elem.click()
progressBar(j, 10, name="quiz 2") progressBar(j, 10, name="quiz 2")
@ -242,9 +274,9 @@ def PlayQuiz8(override = 3):
ListeOfGood = [] ListeOfGood = []
for i in range(1, 9): for i in range(1, 9):
try: try:
Card= driver.find_element(By.ID, f'rqAnswerOption{i-1}') Card = driver.find_element(By.ID, f"rqAnswerOption{i-1}")
if 'iscorrectoption="True" 'in Card.get_attribute('outerHTML') : if 'iscorrectoption="True" ' in Card.get_attribute("outerHTML"):
ListeOfGood.append(f'rqAnswerOption{i-1}') #premier div = 3 ? ListeOfGood.append(f"rqAnswerOption{i-1}") # premier div = 3 ?
except Exception as e: except Exception as e:
LogError("playquiz8 - 1 - " + e) LogError("playquiz8 - 1 - " + e)
shuffle(ListeOfGood) shuffle(ListeOfGood)
@ -277,7 +309,7 @@ def PlayQuiz4(override = None):
printf("PlayQuiz4 : start") printf("PlayQuiz4 : start")
if not override: if not override:
try: # permet de gerer les truc de fidélité, qui sont plus long try: # permet de gerer les truc de fidélité, qui sont plus long
override = int(findall("rqQuestionState([\d]{1,2})\"", driver.page_source)[-1]) override = int(findall('rqQuestionState([\d]{1,2})"', driver.page_source)[-1])
printf(f"Override : {override}") printf(f"Override : {override}")
except: except:
override = 3 override = 3
@ -287,12 +319,14 @@ def PlayQuiz4(override = None):
CustomSleep(uniform(3, 5)) CustomSleep(uniform(3, 5))
txt = driver.page_source txt = driver.page_source
RGPD() RGPD()
reponse = search("correctAnswer\":\"([^\"]+)", txt)[1] #je suis pas sur qu'il y ait un espace reponse = search('correctAnswer":"([^"]+)', txt)[1] # je suis pas sur qu'il y ait un espace
reponse = reponse.replace('\\u0027',"'") #il faut cancel l'unicode avec un double \ (on replacer les caracteres en unicode en caracteres utf-8) reponse = reponse.replace("\\u0027", "'") # il faut cancel l'unicode avec un double \ (on replacer les caracteres en unicode en caracteres utf-8)
printf(f"validation de la reponse " , end="\r") printf(f"validation de la reponse ",end="\r",)
printf(f"validation de la reponse {i+1}/{override} {reponse}", end="\r") printf(f"validation de la reponse {i+1}/{override} {reponse}", end="\r")
try: try:
elem = driver.find_element(By.CSS_SELECTOR, f'[data-option="{reponse}"]') elem = driver.find_element(
By.CSS_SELECTOR, f'[data-option="{reponse}"]'
)
elem.click() elem.click()
except exceptions.ElementNotInteractableException: except exceptions.ElementNotInteractableException:
driver.execute_script("arguments[0].click();", elem) driver.execute_script("arguments[0].click();", elem)
@ -307,7 +341,7 @@ def PlayPoll():
printf("PlayPoll : start") printf("PlayPoll : start")
try: try:
try: try:
elem = driver.find_element(By.ID, f'btoption{choice([0,1])}') elem = driver.find_element(By.ID, f"btoption{choice([0,1])}")
elem.click() elem.click()
except exceptions.ElementNotInteractableException as e: except exceptions.ElementNotInteractableException as e:
driver.execute_script("arguments[0].click();", elem) driver.execute_script("arguments[0].click();", elem)
@ -319,12 +353,13 @@ def PlayPoll():
def AllCard(): # fonction qui clique sur les cartes def AllCard(): # fonction qui clique sur les cartes
def reset(Partie2=False): # retourne sur la page de depart apres avoir finis def reset(Partie2=False): # retourne sur la page de depart apres avoir finis
if len(driver.window_handles) == 1: if len(driver.window_handles) == 1:
driver.get('https://www.bing.com/rewardsapp/flyout') driver.get("https://www.bing.com/rewardsapp/flyout")
if Partie2: if Partie2:
driver.find_element(By.XPATH, '/html/body/div/div/div[3]/div[2]/div[2]/div[2]/div[1]').click() driver.find_element(
By.XPATH, "/html/body/div/div/div[3]/div[2]/div[2]/div[2]/div[1]"
).click()
else: else:
driver.switch_to.window(driver.window_handles[1]) driver.switch_to.window(driver.window_handles[1])
printf(f"fermeture : {driver.current_url}") printf(f"fermeture : {driver.current_url}")
@ -338,7 +373,9 @@ def AllCard(): #fonction qui clique sur les cartes
sleep(1) sleep(1)
try: try:
titre = "erreur" titre = "erreur"
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]').click() 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]",
).click()
sleep(1) sleep(1)
titre = driver.title titre = driver.title
TryPlay(titre) TryPlay(titre)
@ -348,24 +385,32 @@ def AllCard(): #fonction qui clique sur les cartes
except Exception as e: except Exception as e:
printf(f"Allcard card {titre} error ({e})") printf(f"Allcard card {titre} error ({e})")
except Exception as e: except Exception as e:
LogError(f'Dailycards {e}') LogError(f"Dailycards {e}")
try: try:
dailyCards() dailyCards()
except: except:
printf("erreur ici") printf("erreur ici")
try: try:
try: try:
driver.find_element(By.XPATH, '/html/body/div/div/div[3]/div[2]/div[2]/div[2]/div[1]').click() #declenche la premiere partie ? driver.find_element(
By.XPATH, "/html/body/div/div/div[3]/div[2]/div[2]/div[2]/div[1]"
).click() # declenche la premiere partie ?
except: except:
reset() reset()
try: try:
driver.find_element(By.XPATH, '/html/body/div/div/div[3]/div[2]/div[2]/div[2]/div[1]').click()#declenche la deuxieme partie ? driver.find_element(
By.XPATH, "/html/body/div/div/div[3]/div[2]/div[2]/div[2]/div[1]"
).click() # declenche la deuxieme partie ?
except: except:
pass pass
for i in range(20): for i in range(20):
printf("debut de l'une des cartes") printf("debut de l'une des cartes")
driver.find_element(By.XPATH, '/html/body/div/div/div[3]/div[2]/div[2]/div[3]/div/div[1]/a/div/div[2]').click() driver.find_element(
By.XPATH,
"/html/body/div/div/div[3]/div[2]/div[2]/div[3]/div/div[1]/a/div/div[2]",
).click()
printf("carte cliqué") printf("carte cliqué")
driver.switch_to.window(driver.window_handles[len(driver.window_handles) - 1]) driver.switch_to.window(driver.window_handles[len(driver.window_handles) - 1])
sleep(1) sleep(1)
@ -375,11 +420,13 @@ def AllCard(): #fonction qui clique sur les cartes
reset(True) reset(True)
sleep(1) sleep(1)
try: try:
link = findall('href="([^<]+)" title=""',driver.page_source)[3] #verifie si on a toujours des cartes link = findall('href="([^<]+)" title=""', driver.page_source)[
3
] # verifie si on a toujours des cartes
except: except:
break break
except Exception as e: except Exception as e:
LogError(f'2eme partie de AllCard (weekly card)\n {e}') LogError(f"2eme partie de AllCard (weekly card)\n {e}")
def send_keys_wait(element, keys): def send_keys_wait(element, keys):
@ -392,108 +439,128 @@ def login() :
printf("login : start") printf("login : start")
try: try:
driver.get('https://www.bing.com/rewardsapp/flyout') driver.get("https://www.bing.com/rewardsapp/flyout")
try: try:
driver.find_element(By.CSS_SELECTOR, f'[title="Rejoindre"]').click() #depend of the language of the page driver.find_element(
By.CSS_SELECTOR, f'[title="Rejoindre"]'
).click() # depend of the language of the page
except: except:
driver.find_element(By.CSS_SELECTOR, f'[title="Join now"]').click() #depend of the language of the page driver.find_element(
By.CSS_SELECTOR, f'[title="Join now"]'
).click() # depend of the language of the page
mail = driver.find_element(By.ID, 'i0116') mail = driver.find_element(By.ID, "i0116")
send_keys_wait(mail, _mail) send_keys_wait(mail, _mail)
mail.send_keys(Keys.ENTER) mail.send_keys(Keys.ENTER)
CustomSleep(5) CustomSleep(5)
pwd = driver.find_element(By.ID, 'i0118') pwd = driver.find_element(By.ID, "i0118")
send_keys_wait(pwd, _password) send_keys_wait(pwd, _password)
pwd.send_keys(Keys.ENTER) pwd.send_keys(Keys.ENTER)
CustomSleep(5) CustomSleep(5)
printf("pwd envoyé") printf("pwd envoyé")
try: try:
driver.find_element(By.ID, 'KmsiCheckboxField').click() driver.find_element(By.ID, "KmsiCheckboxField").click()
except Exception as e: except Exception as e:
printf(f"login - 1 - erreur validation bouton KmsiCheckboxField. pas forcement grave {e}") printf(
f"login - 1 - erreur validation bouton KmsiCheckboxField. pas forcement grave {e}"
)
try: try:
driver.find_element(By.ID, 'idSIButton9').click() driver.find_element(By.ID, "idSIButton9").click()
except Exception as e: except Exception as e:
printf(f"login - 2 - erreur validation bouton idSIButton9. pas forcement grave {e}") printf(
f"login - 2 - erreur validation bouton idSIButton9. pas forcement grave {e}"
)
printf("login completed") printf("login completed")
RGPD() RGPD()
driver.get('https://www.bing.com/rewardsapp/flyout') driver.get("https://www.bing.com/rewardsapp/flyout")
MainWindows = driver.current_window_handle MainWindows = driver.current_window_handle
return(MainWindows) return MainWindows
except Exception as e: except Exception as e:
LogError("login - 3 - " + str(e)) LogError("login - 3 - " + str(e))
def BingPcSearch(override=randint(35, 40)): def BingPcSearch(override=randint(35, 40)):
driver.get(f'https://www.bing.com/search?q=test')#{choice(Liste_de_mot)}') driver.get(f"https://www.bing.com/search?q=test") # {choice(Liste_de_mot)}')
CustomSleep(uniform(1, 2)) CustomSleep(uniform(1, 2))
RGPD() RGPD()
send_keys_wait( driver.find_element(By.ID, 'sb_form_q'),Keys.BACKSPACE+Keys.BACKSPACE+Keys.BACKSPACE+Keys.BACKSPACE+Keys.BACKSPACE+Keys.BACKSPACE) send_keys_wait(
driver.find_element(By.ID, "sb_form_q"),
Keys.BACKSPACE
+ Keys.BACKSPACE
+ Keys.BACKSPACE
+ Keys.BACKSPACE
+ Keys.BACKSPACE
+ Keys.BACKSPACE,
)
for i in range(override): for i in range(override):
mot = choice(Liste_de_mot) mot = choice(Liste_de_mot)
try: try:
send_keys_wait( driver.find_element(By.ID, 'sb_form_q'),mot) send_keys_wait(driver.find_element(By.ID, "sb_form_q"), mot)
driver.find_element(By.ID, 'sb_form_q').send_keys(Keys.ENTER) driver.find_element(By.ID, "sb_form_q").send_keys(Keys.ENTER)
except: except:
sleep(10) sleep(10)
driver.refresh() driver.refresh()
sleep(10) sleep(10)
send_keys_wait( driver.find_element(By.ID, 'sb_form_q'),mot) send_keys_wait(driver.find_element(By.ID, "sb_form_q"), mot)
driver.find_element(By.ID, 'sb_form_q').send_keys(Keys.ENTER) driver.find_element(By.ID, "sb_form_q").send_keys(Keys.ENTER)
progressBar(i, override, name="PC") progressBar(i, override, name="PC")
sleep(uniform(5, 20)) sleep(uniform(5, 20))
try: try:
driver.find_element(By.ID, 'sb_form_q').clear() driver.find_element(By.ID, "sb_form_q").clear()
except: except:
try: try:
driver.refresh() driver.refresh()
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:
LogError(f"BingPcSearch - clear la barre de recherche - {e}") LogError(f"BingPcSearch - clear la barre de recherche - {e}")
print('\n\n') print("\n\n")
def BingMobileSearch(override=randint(22, 25)): def BingMobileSearch(override=randint(22, 25)):
MobileDriver = "si il y a ca dans les logs, c'est que Mobiledriver n'a pas demarrer " MobileDriver = (
"si il y a ca dans les logs, c'est que Mobiledriver n'a pas demarrer "
)
try: try:
try: try:
MobileDriver = FirefoxMobile() MobileDriver = FirefoxMobile()
except Exception as e: except Exception as e:
sleep(30) sleep(30)
LogError('BingMobileSearch - 1 - echec de la creation du driver mobile') LogError("BingMobileSearch - 1 - echec de la creation du driver mobile")
MobileDriver = FirefoxMobile() MobileDriver = FirefoxMobile()
echec = 0 echec = 0
def Mlogin(echec): def Mlogin(echec):
try: try:
MobileDriver.get('https://www.bing.com/search?q=test+speed&qs=LS&pq=test+s&sk=PRES1&sc=8-6&cvid=19&FORM=QBRE&sp=1') MobileDriver.get(
"https://www.bing.com/search?q=test+speed&qs=LS&pq=test+s&sk=PRES1&sc=8-6&cvid=19&FORM=QBRE&sp=1"
)
CustomSleep(uniform(3, 5)) CustomSleep(uniform(3, 5))
printf("debut du login", Mobdriver=MobileDriver) printf("debut du login", Mobdriver=MobileDriver)
MobileDriver.find_element(By.ID, 'mHamburger').click() MobileDriver.find_element(By.ID, "mHamburger").click()
CustomSleep(uniform(1, 2)) CustomSleep(uniform(1, 2))
printf("login - 1", Mobdriver=MobileDriver) printf("login - 1", Mobdriver=MobileDriver)
MobileDriver.find_element(By.ID, 'hb_s').click() MobileDriver.find_element(By.ID, "hb_s").click()
CustomSleep(uniform(1, 2)) CustomSleep(uniform(1, 2))
printf("login - 2", Mobdriver=MobileDriver) printf("login - 2", Mobdriver=MobileDriver)
mail = MobileDriver.find_element(By.ID, 'i0116') mail = MobileDriver.find_element(By.ID, "i0116")
send_keys_wait(mail, _mail) send_keys_wait(mail, _mail)
printf("login - 3", Mobdriver=MobileDriver) printf("login - 3", Mobdriver=MobileDriver)
mail.send_keys(Keys.ENTER) mail.send_keys(Keys.ENTER)
CustomSleep(uniform(1, 2)) CustomSleep(uniform(1, 2))
printf("login - 4", Mobdriver=MobileDriver) printf("login - 4", Mobdriver=MobileDriver)
pwd = MobileDriver.find_element(By.ID, 'i0118') pwd = MobileDriver.find_element(By.ID, "i0118")
printf("login - 5", Mobdriver=MobileDriver) printf("login - 5", Mobdriver=MobileDriver)
send_keys_wait(pwd, _password) send_keys_wait(pwd, _password)
printf("login - 6", Mobdriver=MobileDriver) printf("login - 6", Mobdriver=MobileDriver)
@ -501,25 +568,28 @@ def BingMobileSearch(override = randint(22,25)):
CustomSleep(uniform(1, 2)) CustomSleep(uniform(1, 2))
printf("fin du login", Mobdriver=MobileDriver) printf("fin du login", Mobdriver=MobileDriver)
except Exception as e: except Exception as e:
echec += 1 echec += 1
if echec <= 3: if echec <= 3:
printf(f'echec du login sur la version mobile. on reesaye ({echec}/3), {e}') printf(
f"echec du login sur la version mobile. on reesaye ({echec}/3), {e}"
)
CustomSleep(uniform(5, 10)) CustomSleep(uniform(5, 10))
Mlogin(echec) Mlogin(echec)
else: else:
LogError(f"login impossible 3 fois de suite. {e}",Mobdriver=MobileDriver) LogError(
f"login impossible 3 fois de suite. {e}", Mobdriver=MobileDriver
)
MobileDriver.quit() MobileDriver.quit()
return(True) return True
def MRGPD(): def MRGPD():
try: try:
MobileDriver.find_element(By.ID, 'bnp_btn_accept').click() MobileDriver.find_element(By.ID, "bnp_btn_accept").click()
except: except:
pass pass
try: try:
MobileDriver.find_element(By.ID, 'bnp_hfly_cta2').click() MobileDriver.find_element(By.ID, "bnp_hfly_cta2").click()
except: except:
pass pass
@ -530,20 +600,31 @@ def BingMobileSearch(override = randint(22,25)):
except exceptions.NoAlertPresentException as e: except exceptions.NoAlertPresentException as e:
pass pass
except Exception as e: except Exception as e:
LogError(f"error sur une alerte dans le driver mobile. {e}",Mobdriver=MobileDriver) LogError(
f"error sur une alerte dans le driver mobile. {e}",
Mobdriver=MobileDriver,
)
if not Mlogin(echec): if not Mlogin(echec):
CustomSleep(uniform(1, 2)) CustomSleep(uniform(1, 2))
MRGPD() MRGPD()
CustomSleep(uniform(1, 1.5)) CustomSleep(uniform(1, 1.5))
send_keys_wait( MobileDriver.find_element(By.ID, 'sb_form_q'),Keys.BACKSPACE+Keys.BACKSPACE+Keys.BACKSPACE+Keys.BACKSPACE+Keys.BACKSPACE+Keys.BACKSPACE) send_keys_wait(
MobileDriver.find_element(By.ID, "sb_form_q"),
Keys.BACKSPACE
+ Keys.BACKSPACE
+ Keys.BACKSPACE
+ Keys.BACKSPACE
+ Keys.BACKSPACE
+ Keys.BACKSPACE,
)
for i in range(override): # 20 for i in range(override): # 20
mot = choice(Liste_de_mot) mot = choice(Liste_de_mot)
send_keys_wait( MobileDriver.find_element(By.ID, 'sb_form_q'),mot) send_keys_wait(MobileDriver.find_element(By.ID, "sb_form_q"), mot)
MobileDriver.find_element(By.ID, 'sb_form_q').send_keys(Keys.ENTER) MobileDriver.find_element(By.ID, "sb_form_q").send_keys(Keys.ENTER)
progressBar(i, override, name="Mobile") progressBar(i, override, name="Mobile")
printf(MobileDriver.current_url, Mobdriver=MobileDriver) printf(MobileDriver.current_url, Mobdriver=MobileDriver)
sleep(uniform(5, 20)) sleep(uniform(5, 20))
@ -551,12 +632,10 @@ def BingMobileSearch(override = randint(22,25)):
Alerte() # verifie si il y a des alertes (demande de positions ....) Alerte() # verifie si il y a des alertes (demande de positions ....)
for i in range(len(mot)): for i in range(len(mot)):
MobileDriver.find_element(By.ID, 'sb_form_q').clear() MobileDriver.find_element(By.ID, "sb_form_q").clear()
MobileDriver.quit() MobileDriver.quit()
except Exception as e: except Exception as e:
LogError("BingMobileSearch" + str(e), Mobdriver=MobileDriver) LogError("BingMobileSearch" + str(e), Mobdriver=MobileDriver)
try: try:
@ -568,78 +647,88 @@ def BingMobileSearch(override = randint(22,25)):
def TryPlay(nom="inconnu"): def TryPlay(nom="inconnu"):
RGPD() RGPD()
printf("TryPlay en cours") printf("TryPlay en cours")
def play(number, override=None): def play(number, override=None):
if number == 8 or number == 9: if number == 8 or number == 9:
try: try:
printf(f'\033[96m Quiz 8 détécté sur la page {nom} \033[0m') printf(f"\033[96m Quiz 8 détécté sur la page {nom} \033[0m")
PlayQuiz8() PlayQuiz8()
printf(f'\033[92m Quiz 8 reussit sur {nom} \033[0m') printf(f"\033[92m Quiz 8 reussit sur {nom} \033[0m")
except Exception as e: except Exception as e:
printf(f'echec de PlayQuiz 8. Aborted {e} \033[0m') printf(f"echec de PlayQuiz 8. Aborted {e} \033[0m")
elif number == 5 or number == 4: elif number == 5 or number == 4:
try: try:
printf(f'\033[96m Quiz 4 détécté sur la page {nom} \033[0m') printf(f"\033[96m Quiz 4 détécté sur la page {nom} \033[0m")
PlayQuiz4() PlayQuiz4()
print(f'\033[92m Quiz 4 reussit sur {nom} \033[0m') print(f"\033[92m Quiz 4 reussit sur {nom} \033[0m")
except Exception as e: except Exception as e:
printf(f'echec de PlayQuiz 4. Aborted {e} \033[0m') printf(f"echec de PlayQuiz 4. Aborted {e} \033[0m")
elif number == 3 or number == 2: elif number == 3 or number == 2:
try: try:
printf(f'\033[96m Quiz 2 détécté sur la page {nom}\033[0m') printf(f"\033[96m Quiz 2 détécté sur la page {nom}\033[0m")
PlayQuiz2() PlayQuiz2()
print(f'\033[92m Quiz 2 reussit sur la page {nom}\033[0m') print(f"\033[92m Quiz 2 reussit sur la page {nom}\033[0m")
except Exception as e: except Exception as e:
printf(f'echec de PlayQuiz 2. Aborted {e}') printf(f"echec de PlayQuiz 2. Aborted {e}")
else: else:
LogError('probleme dans la carte : il y a un bouton play et aucun quiz detecté') LogError(
"probleme dans la carte : il y a un bouton play et aucun quiz detecté"
)
try: try:
driver.find_element(By.ID, 'rqStartQuiz').click() #start the quiz driver.find_element(By.ID, "rqStartQuiz").click() # start the quiz
number = driver.page_source.count('rqAnswerOption') number = driver.page_source.count("rqAnswerOption")
play(number) play(number)
except Exception as e: except Exception as e:
# printf(e) normal erreor here # printf(e) normal erreor here
if "bt_PollRadio" in driver.page_source: if "bt_PollRadio" in driver.page_source:
try: try:
print('Poll détected', end ="\r") print("Poll détected", end="\r")
RGPD() RGPD()
PlayPoll() PlayPoll()
print('Poll reussit ') print("Poll reussit ")
except Exception as e: except Exception as e:
printf(f'TryPlay - 1 - Poll aborted {e}') printf(f"TryPlay - 1 - Poll aborted {e}")
elif "rqQuestionState" in driver.page_source: elif "rqQuestionState" in driver.page_source:
try: try:
number = driver.page_source.count('rqAnswerOption') number = driver.page_source.count("rqAnswerOption")
restant = len(findall("\"rqQuestionState.?.\" class=", driver.page_source)) - len(findall("\"rqQuestionState.?.\" class=\"filledCircle\"", driver.page_source)) restant = len(
findall('"rqQuestionState.?." class=', driver.page_source)
) - len(
findall(
'"rqQuestionState.?." class="filledCircle"', driver.page_source
)
)
printf(f"recovery détécté. quiz : {number}, restant : {restant +1}") printf(f"recovery détécté. quiz : {number}, restant : {restant +1}")
play(number, override=restant + 1) play(number, override=restant + 1)
except Exception as e: except Exception as e:
printf("TryPlay - 2 - " + e) printf("TryPlay - 2 - " + e)
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() RGPD()
Fidelite() Fidelite()
else: else:
print(f'rien a faire sur la page {nom}') print(f"rien a faire sur la page {nom}")
RGPD() RGPD()
CustomSleep(uniform(3, 5)) CustomSleep(uniform(3, 5))
def LogPoint(account="unknown"): # log des points sur discord def LogPoint(account="unknown"): # log des points sur discord
driver.get('https://www.bing.com/rewardsapp/flyout') driver.get("https://www.bing.com/rewardsapp/flyout")
if not IsLinux: if not IsLinux:
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
else: else:
asyncio.set_event_loop(asyncio.new_event_loop()) asyncio.set_event_loop(asyncio.new_event_loop())
regex1 = "<a href=\"https://rewards\.bing\.com/\" title=\"((.{1,3}),(.{1,3})) points\" target=\"_blank\"" regex1 = '<a href="https://rewards\.bing\.com/" title="((.{1,3}),(.{1,3})) points" target="_blank"'
try: try:
point = search(regex1, driver.page_source)[1].replace(',', '') point = search(regex1, driver.page_source)[1].replace(",", "")
except Exception as e: except Exception as e:
elem = driver.find_element(By.CSS_SELECTOR, '[title="Microsoft Rewards"]') elem = driver.find_element(By.CSS_SELECTOR, '[title="Microsoft Rewards"]')
@ -648,24 +737,23 @@ def LogPoint(account="unknown"): #log des points sur discord
driver.switch_to.window(driver.window_handles[len(driver.window_handles) - 1]) driver.switch_to.window(driver.window_handles[len(driver.window_handles) - 1])
CustomSleep(uniform(10, 20)) CustomSleep(uniform(10, 20))
try: try:
point = search("availablePoints\":([\d]+)",driver.page_source)[1] point = search('availablePoints":([\d]+)', driver.page_source)[1]
except Exception as e: except Exception as e:
LogError(f"LogPoint - 2 - {e}") LogError(f"LogPoint - 2 - {e}")
point = "erreur" point = "erreur"
CustomSleep(uniform(3, 20)) CustomSleep(uniform(3, 20))
account = account.split('@')[0] account = account.split("@")[0]
if embeds: if embeds:
embed = discord.Embed( embed = discord.Embed(
title=f"{account} actuellement à {str(point)} points", title=f"{account} actuellement à {str(point)} points", colour=Colour.green()
colour = Colour.green()
) )
embed.set_footer(text=account) embed.set_footer(text=account)
webhookSuccess.send(embed=embed) webhookSuccess.send(embed=embed)
else: else:
webhookSuccess.send(f'{account} actuellement à {str(point)} points') webhookSuccess.send(f"{account} actuellement à {str(point)} points")
def Fidelite(lien): def Fidelite(lien):
@ -678,15 +766,20 @@ def Fidelite(lien):
driver.get(lien) driver.get(lien)
sleep(2) sleep(2)
choix = driver.find_element(By.CSS_SELECTOR,'div[class="pull-left spacer-48-bottom punchcard-row"]') #pull-left spacer-48-bottom punchcard-row choix = driver.find_element(
By.CSS_SELECTOR, 'div[class="pull-left spacer-48-bottom punchcard-row"]'
) # pull-left spacer-48-bottom punchcard-row
nb = search("([0-9]) of ([0-9]) completed", driver.page_source) nb = search("([0-9]) of ([0-9]) completed", driver.page_source)
if not nb: if not nb:
nb = search("([0-9]) de ([0-9]) finalisé", driver.page_source) nb = search("([0-9]) de ([0-9]) finalisé", driver.page_source)
for i in range(int(nb[2]) - int(nb[1])): for i in range(int(nb[2]) - int(nb[1])):
driver.refresh() driver.refresh()
CustomSleep(2) CustomSleep(2)
choix = driver.find_element(By.CLASS_NAME,'spacer-48-bottom') choix = driver.find_element(By.CLASS_NAME, "spacer-48-bottom")
ButtonText = search('<span class=\"pull-left margin-right-15\">([^<^>]+)</span>',choix.get_attribute("innerHTML"))[1] ButtonText = search(
'<span class="pull-left margin-right-15">([^<^>]+)</span>',
choix.get_attribute("innerHTML"),
)[1]
bouton = driver.find_element(By.XPATH, f'//span[text()="{ButtonText}"]') bouton = driver.find_element(By.XPATH, f'//span[text()="{ButtonText}"]')
bouton.click() bouton.click()
CustomSleep(uniform(3, 5)) CustomSleep(uniform(3, 5))
@ -699,7 +792,7 @@ def Fidelite(lien):
except Exception as e: except Exception as e:
printf(e) printf(e)
printf('on a reussit la partie fidélité') printf("on a reussit la partie fidélité")
except Exception as e: except Exception as e:
LogError("Fidélité" + str(e)) LogError("Fidélité" + str(e))
@ -707,8 +800,8 @@ def Fidelite(lien):
def CheckPoint(): # a fix, ne marche pas dans 80% des cas, pas appelé aujourd'hui def CheckPoint(): # a fix, ne marche pas dans 80% des cas, pas appelé aujourd'hui
driver.get("https://rewards.microsoft.com/pointsbreakdown") driver.get("https://rewards.microsoft.com/pointsbreakdown")
txt = driver.page_source txt = driver.page_source
pc = search('([0-9][0-9]|[0-9])</b> / 90',txt) pc = search("([0-9][0-9]|[0-9])</b> / 90", txt)
mobile = search('([0-9][0-9]|[0-9])</b> / 60',txt) mobile = search("([0-9][0-9]|[0-9])</b> / 60", txt)
if mobile: if mobile:
if mobile[1] != 60: if mobile[1] != 60:
BingMobileSearch(22 - (int(mobile[1]) / 3)) BingMobileSearch(22 - (int(mobile[1]) / 3))
@ -724,7 +817,9 @@ def DailyRoutine():
try: try:
AllCard() AllCard()
except Exception as e: except Exception as e:
LogError(f'pas normal sauf si relancer a la main, juste pour les recherches bing (DalyRoutine -> AllCard) \n {e}') LogError(
f"pas normal sauf si relancer a la main, juste pour les recherches bing (DalyRoutine -> AllCard) \n {e}"
)
try: try:
BingPcSearch() BingPcSearch()
@ -735,8 +830,8 @@ def DailyRoutine():
try: try:
BingMobileSearch() BingMobileSearch()
except Exception as e: except Exception as e:
LogError(f'BingMobileSearch - {e}') LogError(f"BingMobileSearch - {e}")
print('\n') print("\n")
CustomSleep(uniform(3, 20)) CustomSleep(uniform(3, 20))
try: try:
FidelityTest() FidelityTest()
@ -746,13 +841,14 @@ def DailyRoutine():
try: try:
LogPoint(_mail) LogPoint(_mail)
except Exception as e: except Exception as e:
LogError(f'LogPoint : {e}') LogError(f"LogPoint : {e}")
def close(): def close():
driver.quit() driver.quit()
quit() quit()
def FidelityTest(): def FidelityTest():
try: try:
result = get(fidelity) result = get(fidelity)
@ -762,9 +858,11 @@ def FidelityTest():
except Exception as e: except Exception as e:
print(f"erreur dans la partie dev : {e}") print(f"erreur dans la partie dev : {e}")
def dev(): def dev():
FidelityTest() FidelityTest()
def CustomStart(Credentials): def CustomStart(Credentials):
global driver global driver
global _mail global _mail
@ -774,9 +872,8 @@ def CustomStart(Credentials):
actions = ["tout", "daily", "pc", "mobile", "LogPoint", "dev"] actions = ["tout", "daily", "pc", "mobile", "LogPoint", "dev"]
system("clear") # clear from previous command to allow a clean choice system("clear") # clear from previous command to allow a clean choice
Comptes = enquiries.choose('quels comptes ?', ids, multi=True) Comptes = enquiries.choose("quels comptes ?", ids, multi=True)
Actions = enquiries.choose('quels Actions ?', actions, multi=True) Actions = enquiries.choose("quels Actions ?", actions, multi=True)
for i in Comptes: for i in Comptes:
@ -793,7 +890,9 @@ def CustomStart(Credentials):
try: try:
AllCard() AllCard()
except Exception as e: except Exception as e:
LogError(f'pas normal sauf si relancer a la main, juste pour les recherches bing (DalyRoutine -> AllCard) \n {str(e)}. -- override') LogError(
f"pas normal sauf si relancer a la main, juste pour les recherches bing (DalyRoutine -> AllCard) \n {str(e)}. -- override"
)
if "pc" in Actions: if "pc" in Actions:
try: try:
@ -805,7 +904,7 @@ def CustomStart(Credentials):
try: try:
BingMobileSearch() BingMobileSearch()
except Exception as e: except Exception as e:
LogError(f'BingMobileSearch - {e} -- override') LogError(f"BingMobileSearch - {e} -- override")
if "dev" in Actions: if "dev" in Actions:
try: try:
@ -820,6 +919,7 @@ def CustomStart(Credentials):
print("CustomStart " + str(e)) print("CustomStart " + str(e))
driver.close() driver.close()
with open(LogPath) as f: with open(LogPath) as f:
reader = reader(f) reader = reader(f)
Credentials = list(reader) Credentials = list(reader)
@ -834,7 +934,7 @@ else :
_mail = i[0] _mail = i[0]
_password = i[1] _password = i[1]
print('\n\n') print("\n\n")
print(_mail) print(_mail)
CustomSleep(1) CustomSleep(1)
printf("debut du driver") printf("debut du driver")
@ -850,7 +950,7 @@ else :
CustomSleep(timer) CustomSleep(timer)
except KeyboardInterrupt: except KeyboardInterrupt:
print('canceled') print("canceled")
close() close()
if IsLinux: if IsLinux: