mirror of
https://gitea.augustin64.fr/piair/MsRewards-Reborn.git
synced 2025-06-23 18:33:56 +02:00
je suis ptet en train de tout refaire mais chut
This commit is contained in:
83
V7/V7.py
Normal file
83
V7/V7.py
Normal file
@ -0,0 +1,83 @@
|
||||
from playwright.sync_api import sync_playwright, expect, Page
|
||||
from playwright_stealth import stealth_sync
|
||||
from logging import *
|
||||
|
||||
from actions.checks import check_logged_in
|
||||
from actions.quiz import play_quiz_2, play_quiz_4, play_quiz_8, play_poll, detect_quiz_type, play
|
||||
from actions.login import login
|
||||
from actions.websearch import pc_search
|
||||
|
||||
basicConfig(encoding='utf-8', level=DEBUG)
|
||||
|
||||
|
||||
def daily_cards(page: Page):
|
||||
for i in range(1, 4):
|
||||
card = page.locator(f'#daily-sets > mee-card-group:nth-child(7) > div > mee-card:nth-child({i}) > div')
|
||||
with page.expect_popup() as page1_info:
|
||||
card.click()
|
||||
page1 = page1_info.value
|
||||
stealth_sync(page1)
|
||||
page1.wait_for_load_state('load')
|
||||
try:
|
||||
selector = page1.get_by_role("button", name="Accepter")
|
||||
expect(selector).to_be_visible(timeout=10_000)
|
||||
selector.click()
|
||||
except AssertionError as e:
|
||||
pass # The RGPD button should not be there in the first place
|
||||
play(page1)
|
||||
page1.close()
|
||||
page.reload()
|
||||
info(f'Carte {i} : {not "mee-icon-AddMedium" in card.inner_html()}')
|
||||
|
||||
|
||||
def more_cards(page: Page):
|
||||
c = 1
|
||||
while c < 15: # todo I don't really know why it stops without raising any errors, but I guess it's fine
|
||||
card = page.locator(f"#more-activities > div > mee-card:nth-child({c})")
|
||||
try:
|
||||
"mee-icon-AddMedium" in card.inner_html()
|
||||
except AssertionError as e:
|
||||
break
|
||||
if "mee-icon-AddMedium" in card.inner_html():
|
||||
info(f"Playing more cards {c}.")
|
||||
with page.expect_popup() as page1_info:
|
||||
card.click()
|
||||
page1 = page1_info.value
|
||||
stealth_sync(page1)
|
||||
page1.wait_for_load_state('load')
|
||||
play(page1)
|
||||
page1.close()
|
||||
page.reload()
|
||||
info(f'Carte {c} : {not "mee-icon-AddMedium" in card.inner_html()}')
|
||||
c += 1
|
||||
|
||||
|
||||
def all_cards(page: Page):
|
||||
# input("1")
|
||||
page.goto("https://rewards.bing.com")
|
||||
page.wait_for_load_state('load')
|
||||
daily_cards(page)
|
||||
more_cards(page)
|
||||
|
||||
|
||||
def routine(page: Page) -> None:
|
||||
all_cards(page)
|
||||
pc_search(page)
|
||||
|
||||
|
||||
with sync_playwright() as p:
|
||||
browser = p.firefox.launch_persistent_context("./data/", headless=False)
|
||||
page = browser.new_page()
|
||||
stealth_sync(page)
|
||||
login(page, input("mail ? "), input("password ? "))
|
||||
all_cards(page)
|
||||
browser.close()
|
||||
|
||||
"""
|
||||
TODO :
|
||||
Fidelity management.
|
||||
Daily search
|
||||
custom start
|
||||
vnc
|
||||
mobile search
|
||||
"""
|
10
V7/actions/checks.py
Normal file
10
V7/actions/checks.py
Normal file
@ -0,0 +1,10 @@
|
||||
from playwright.sync_api import Playwright, sync_playwright, expect, Page
|
||||
from playwright_stealth import stealth_sync
|
||||
from logging import *
|
||||
|
||||
|
||||
def check_logged_in(page: Page):
|
||||
if "pas connecté à Microsoft Rewards" in page.content():
|
||||
page.locator('css=[onclick="setsrchusr()"]').click()
|
||||
page.wait_for_load_state('load')
|
||||
info('Fixed logging in in card.')
|
30
V7/actions/login.py
Normal file
30
V7/actions/login.py
Normal file
@ -0,0 +1,30 @@
|
||||
from playwright.sync_api import Playwright, sync_playwright, expect, Page
|
||||
from logging import *
|
||||
|
||||
|
||||
def login(page: Page, mail: str, pwd: str) -> None:
|
||||
page.goto("https://rewards.bing.com")
|
||||
page.wait_for_load_state('load')
|
||||
if page.url == "https://rewards.bing.com/":
|
||||
info("Logged in via cookies")
|
||||
return
|
||||
else:
|
||||
info("logging in")
|
||||
page.get_by_placeholder("Email, phone, or Skype").click()
|
||||
page.get_by_placeholder("Email, phone, or Skype").fill(mail)
|
||||
page.get_by_placeholder("Email, phone, or Skype").press("Enter")
|
||||
page.get_by_placeholder("Password").click()
|
||||
page.get_by_placeholder("Password").fill(pwd)
|
||||
page.get_by_placeholder("Password").press("Enter")
|
||||
page.get_by_label("Don't show this again").check()
|
||||
page.get_by_role("button", name="Yes").click()
|
||||
page.wait_for_url("https://rewards.bing.com/")
|
||||
page.wait_for_load_state('load')
|
||||
page.goto("https://bing.com")
|
||||
page.get_by_role("link", name="Sign in").click()
|
||||
page.get_by_role("link", name="Accept").click()
|
||||
page.wait_for_load_state('load')
|
||||
page.wait_for_timeout(3000)
|
||||
page.goto("https://rewards.bing.com")
|
||||
page.wait_for_load_state('load')
|
||||
info("Logged in via password.")
|
115
V7/actions/quiz.py
Normal file
115
V7/actions/quiz.py
Normal file
@ -0,0 +1,115 @@
|
||||
from random import choice, shuffle
|
||||
|
||||
from playwright.sync_api import Playwright, sync_playwright, expect, Page
|
||||
from playwright_stealth import stealth_sync
|
||||
from logging import *
|
||||
from re import findall, search
|
||||
from actions.checks import check_logged_in
|
||||
|
||||
|
||||
def play(page: Page):
|
||||
check_logged_in(page)
|
||||
quiz_type = detect_quiz_type(page)
|
||||
match quiz_type:
|
||||
case 8 | 9:
|
||||
info('Detected quiz_8.')
|
||||
play_quiz_8(page)
|
||||
case 5 | 4:
|
||||
info('Detected quiz_4.')
|
||||
play_quiz_4(page)
|
||||
case 3 | 2:
|
||||
info('Detected quiz_2.')
|
||||
play_quiz_2(page)
|
||||
case 1:
|
||||
info('Detected poll.')
|
||||
play_poll(page)
|
||||
case 0:
|
||||
info('Detected empty page.')
|
||||
|
||||
|
||||
def detect_quiz_type(page: Page) -> int:
|
||||
info("Detecting quiz type.")
|
||||
if "bt_PollRadio" in page.content():
|
||||
return 1
|
||||
elif "rqQuestionState" in page.content():
|
||||
# The quiz is already started
|
||||
return page.content().count("rqAnswerOption") - 1
|
||||
else:
|
||||
try:
|
||||
# RGPD
|
||||
selector = page.locator("rqStartQuiz")
|
||||
expect(selector).to_be_visible(timeout=10_000)
|
||||
selector.click()
|
||||
return page.content().count("rqAnswerOption") - 1
|
||||
except AssertionError as e:
|
||||
return 0
|
||||
|
||||
|
||||
def play_quiz_8(page: Page):
|
||||
info("Playing quiz 8.")
|
||||
num_question = len(findall("<span id=\"rqQuestionState.\" class=\"emptyCircle\"></span>", page.content())) + 1
|
||||
info(f"Looping on {num_question} questions.")
|
||||
|
||||
counter = 0
|
||||
# rgpd_popup(driver)
|
||||
for _ in range(num_question):
|
||||
correct_answers = []
|
||||
for i in range(1, 9):
|
||||
|
||||
element = page.locator(f'#rqAnswerOption{i - 1}')
|
||||
# todo can probably be optimised using filter and has_text
|
||||
if 'iscorrectoption="True"' in element.evaluate("el => el.outerHTML"):
|
||||
correct_answers.append(f'rqAnswerOption{i - 1}')
|
||||
shuffle(correct_answers)
|
||||
|
||||
for answer_id in correct_answers:
|
||||
page.locator(answer_id).click()
|
||||
page.wait_for_timeout(1000)
|
||||
page.wait_for_timeout(3000) # todo check if there is a better method than hardcoded timout
|
||||
|
||||
|
||||
def play_quiz_4(page: Page):
|
||||
info("Playing quiz 4.")
|
||||
num_question = len(findall("<span id=\"rqQuestionState.\" class=\"emptyCircle\"></span>", page.content())) + 1
|
||||
info(f"Looping on {num_question} questions.")
|
||||
|
||||
for i in range(num_question):
|
||||
txt = page.content()
|
||||
answer_option = search('correctAnswer":"([^"]+)', txt)[1]
|
||||
answer_option = answer_option.replace("\\u0027", "'") # replace Unicode weird symbols
|
||||
page.locator(f'css=[data-option="{answer_option}"]').click()
|
||||
info(f'Validated answer n°{i + 1}.')
|
||||
page.wait_for_load_state('load')
|
||||
debug(f'Next page loaded.')
|
||||
info("Quiz 4 successful.")
|
||||
|
||||
|
||||
def play_quiz_2(page: Page):
|
||||
info("Playing quiz 2.")
|
||||
for j in range(10): # todo de-hardcode the value
|
||||
js_function = """
|
||||
function get_correct_answer(){
|
||||
function br(n) { for (var r, t = 0, i = 0; i < n.length; i++)t += n.charCodeAt(i); return r = parseInt(_G.IG.substr(_G.IG.length - 2), 16), t += r, t.toString() } // Ms check function
|
||||
function namedRAValue() { //allow calls to getRAvalue
|
||||
return _w.getRAValue()
|
||||
};
|
||||
if (br(document.getElementById("rqAnswerOption0").attributes["data-option"].value) == namedRAValue()){
|
||||
return(0);
|
||||
}
|
||||
else {
|
||||
return(1);
|
||||
}
|
||||
};
|
||||
return(get_correct_answer())
|
||||
"""
|
||||
correct_answer_value = page.evaluate(js_function)
|
||||
page.locator(f"#rqAnswerOption{correct_answer_value}").click()
|
||||
page.wait_for_timeout(2000)
|
||||
info("Quiz 2 successful.")
|
||||
|
||||
|
||||
def play_poll(page: Page):
|
||||
info("Playing poll.")
|
||||
answer_elem = page.locator(f"#btoption{choice([0, 1])}")
|
||||
answer_elem.click()
|
||||
info("Poll successful.")
|
23
V7/actions/websearch.py
Normal file
23
V7/actions/websearch.py
Normal file
@ -0,0 +1,23 @@
|
||||
from random import choice
|
||||
|
||||
from playwright.sync_api import sync_playwright, expect, Page
|
||||
from playwright_stealth import stealth_sync
|
||||
|
||||
h = open("../user_data/french", "r", encoding="utf-8")
|
||||
lines = h.readlines()
|
||||
if len(lines) < 3:
|
||||
Liste_de_mot = list(lines[0].split(","))
|
||||
else:
|
||||
Liste_de_mot = [x.replace('\n', "") for x in lines]
|
||||
h.close()
|
||||
|
||||
|
||||
def pc_search(page: Page) -> None:
|
||||
mot = choice(Liste_de_mot).replace(" ", "+")
|
||||
page.goto(f"https://www.bing.com/search?q={mot}")
|
||||
|
||||
for _ in range(35): # todo de-hardcode this variable
|
||||
word = choice(Liste_de_mot)
|
||||
page.get_by_label("Enter your search here -").click()
|
||||
page.get_by_label("Enter your search here -").fill(word)
|
||||
page.get_by_label("Enter your search here -").press("Enter")
|
27
V7/logger.py
Normal file
27
V7/logger.py
Normal file
@ -0,0 +1,27 @@
|
||||
from playwright.sync_api import Page
|
||||
from discord import Colour, Embed, File, RequestsWebhookAdapter, Webhook
|
||||
|
||||
|
||||
class Logger:
|
||||
def __init__(self, link):
|
||||
self.wh = Webhook.from_url(link, adapter=RequestsWebhookAdapter())
|
||||
|
||||
def error(self, page: Page, error: str):
|
||||
with open("page.html", "w") as f:
|
||||
try:
|
||||
f.write(page.content())
|
||||
except Exception as e:
|
||||
f.write(f"the driver has closed or crashed. Can't access page content\n{e}")
|
||||
embed = Embed(
|
||||
title="An Error has occurred",
|
||||
description=str(error),
|
||||
colour=Colour.red(),
|
||||
)
|
||||
try:
|
||||
page.screenshot(path="screenshot.png")
|
||||
except Exception as e:
|
||||
with open("screenshot.png", "w") as f:
|
||||
f.write(f"Can't take screenshot\n{e}")
|
||||
file = File("screenshot.png")
|
||||
embed.set_image(url="attachment://screenshot.png")
|
||||
self.wh.send(embed=embed, username="error", file=file)
|
Reference in New Issue
Block a user