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.Config import Config
from modules.Classes.DiscordLogger import DiscordLogger from modules.Classes.DiscordLogger import DiscordLogger
from modules.Classes.UserCredentials import UserCredentials 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.cards import *
from modules.config import * from modules.config import *
from modules.db import add_to_database from modules.db import add_to_database
@ -265,8 +265,11 @@ def all_cards():
if not checked: if not checked:
continue continue
info(card_list[i].get_attribute("innerHTML")) try:
info(findall("data-bi-id=\"([^\"]+)\"", card_list[i].get_attribute("innerHTML"))) activity = findall("data-bi-id=\"([^\"]+)\"", card_list[i].get_attribute("innerHTML"))[0]
except:
activity = ""
custom_sleep(1.5) custom_sleep(1.5)
check_welcome_tour() check_welcome_tour()
driver.execute_script("arguments[0].scrollIntoView();", card_list[i]) driver.execute_script("arguments[0].scrollIntoView();", card_list[i])
@ -275,7 +278,7 @@ def all_cards():
if len(driver.window_handles) > 1: if len(driver.window_handles) > 1:
driver.switch_to.window(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]) close_tab(driver.window_handles[1])
try: try:
@ -342,8 +345,29 @@ def promo():
custom_sleep(3) 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 # Find out which type of action to do
def try_play(nom="unknown"): def try_play(nom="unknown", activity=""):
driver = config.WebDriver.driver driver = config.WebDriver.driver
rgpd_popup(config) rgpd_popup(config)
@ -389,7 +413,7 @@ def try_play(nom="unknown"):
info("On fidelity page.") info("On fidelity page.")
fidelity() 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) custom_sleep(3)
driver.find_element(By.ID, "rqStartQuiz").click() # start the quiz driver.find_element(By.ID, "rqStartQuiz").click() # start the quiz
answer_number = driver.page_source.count("rqAnswerOption") answer_number = driver.page_source.count("rqAnswerOption")
@ -399,9 +423,12 @@ def try_play(nom="unknown"):
number = driver.page_source.count("rqAnswerOption") number = driver.page_source.count("rqAnswerOption")
warning(f"recovery detected. quiz : {number}") warning(f"recovery detected. quiz : {number}")
play(number - 1) play(number - 1)
elif "exploreonbing" in activity:
info("Explore on bing")
explore_on_bing(activity, config)
custom_sleep(uniform(3, 5))
else: 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)) custom_sleep(uniform(3, 5))

View File

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