This commit is contained in:
piair 2024-04-26 13:55:20 +02:00
parent 05a1fd8557
commit 22ea727c47
2 changed files with 44 additions and 16 deletions

43
V6.py
View File

@ -4,7 +4,7 @@ import random
from modules.Classes.Config import Config
from modules.Classes.DiscordLogger import DiscordLogger
from modules.Classes.UserCredentials import UserCredentials
from modules.Tools.logger import warning, critical
from modules.Tools.logger import critical
from modules.cards import *
from modules.config import *
from modules.db import add_to_database
@ -265,8 +265,11 @@ def all_cards():
if not checked:
continue
info(card_list[i].get_attribute("innerHTML"))
info(findall("data-bi-id=\"([^\"]+)\"", card_list[i].get_attribute("innerHTML")))
try:
activity = findall("data-bi-id=\"([^\"]+)\"", card_list[i].get_attribute("innerHTML"))[0]
except:
activity = ""
custom_sleep(1.5)
check_welcome_tour()
driver.execute_script("arguments[0].scrollIntoView();", card_list[i])
@ -275,7 +278,7 @@ def all_cards():
if len(driver.window_handles) > 1:
driver.switch_to.window(driver.window_handles[1])
try_play(driver.title)
try_play(driver.title, activity)
close_tab(driver.window_handles[1])
try:
@ -342,8 +345,29 @@ def promo():
custom_sleep(3)
def explore_on_bing(activity: str, config: Config):
driver = config.WebDriver.driver
def search_bing(txt):
search_elm = driver.get_element(By.ID, "sb_form_q")
send_keys_wait(search_elm, txt)
send_keys_wait(search_elm, Keys.ENTER)
if "lyrics" in activity:
search_bing(
f"paroles de {['The Black Dog', 'The Alchemy', 'The Albatross', 'The Bolter', 'Imgonnagetyouback'][randint(0, 4)]}")
elif "flight" in activity:
search_bing(
f"vol {['Paris - New York', 'Londres Amsterdam', 'Bora-Bora Miami', 'Los Angeles Toulouse', 'Rome Dubai'][randint(0, 4)]}")
elif "shopping" in activity:
search_bing(f"idée cadeau {['Noel', 'Anniversaire'][randint(0, 1)]}")
elif "movie" in activity:
search_bing(
f"Distribution {['Code 8 part 2', 'The Hunger Games: The ballad of Songbirds & Snakes', 'Rebel Moon: Part Two', 'Dune II', 'Wonka'][randint(0, 4)]}")
# Find out which type of action to do
def try_play(nom="unknown"):
def try_play(nom="unknown", activity=""):
driver = config.WebDriver.driver
rgpd_popup(config)
@ -389,7 +413,7 @@ def try_play(nom="unknown"):
info("On fidelity page.")
fidelity()
elif wait_until_visible(By.ID, "rqStartQuiz", 5, driver):
elif wait_until_visible(By.ID, "rqStartQuiz", 5, driver, raise_error=False):
custom_sleep(3)
driver.find_element(By.ID, "rqStartQuiz").click() # start the quiz
answer_number = driver.page_source.count("rqAnswerOption")
@ -399,9 +423,12 @@ def try_play(nom="unknown"):
number = driver.page_source.count("rqAnswerOption")
warning(f"recovery detected. quiz : {number}")
play(number - 1)
elif "exploreonbing" in activity:
info("Explore on bing")
explore_on_bing(activity, config)
custom_sleep(uniform(3, 5))
else:
info(f"Nothing to do on page `{nom}`")
info(f"Nothing obvious to do on page `{nom}`. Activity: {activity}")
custom_sleep(uniform(3, 5))

View File

@ -1,9 +1,9 @@
import os
import json
import os
from random import uniform
from selenium.common import TimeoutException
from selenium.webdriver import ActionChains, Keys
from selenium.webdriver import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
@ -14,9 +14,9 @@ from modules.Tools.tools import *
def init_profile(mail, mobile=False):
if not mobile:
chrome_profile_dir = "/app/MsRewards-Reborn/user_data/profile/"+mail
chrome_profile_dir = "/app/MsRewards-Reborn/user_data/profile/" + mail
else:
chrome_profile_dir = "/app/MsRewards-Reborn/user_data/profile/mobile-"+mail
chrome_profile_dir = "/app/MsRewards-Reborn/user_data/profile/mobile-" + mail
os.makedirs(chrome_profile_dir, exist_ok=True)
@ -30,12 +30,12 @@ def init_profile(mail, mobile=False):
"accept_languages": "fr-FR,en-US,en",
"selected_languages": "fr-FR,en-US,en"
}
}, f
}, f
)
else:
with open(preferences_file, "r") as f:
settings = json.load(f)
if "intl" not in settings:
settings["intl"] = {}
@ -69,6 +69,7 @@ def send_keys_wait(element, keys: str) -> None:
element.send_keys(i)
sleep(uniform(0.1, 0.3))
def send_wait_and_confirm(element, keys: str) -> None:
send_keys_wait(element, keys)
element.send_keys(Keys.ENTER)
@ -81,6 +82,6 @@ def wait_until_visible(search_by: str, identifier: str, timeout: int = 20, brows
expected_conditions.visibility_of_element_located((search_by, identifier)), "element not found")
return True
except TimeoutException as e:
if raise_error:
error(f"element {identifier} not found after {timeout}s")
f = error if raise_error else debug
f(f"element {identifier} not found after {timeout}s")
return False