deleted old V7
This commit is contained in:
parent
fc8e666927
commit
f0acd9e2f2
43
V7/V7.py
43
V7/V7.py
|
@ -1,43 +0,0 @@
|
|||
from playwright.sync_api import sync_playwright, expect, Page, BrowserContext
|
||||
from playwright_stealth import stealth_sync
|
||||
from pyvirtualdisplay.smartdisplay import SmartDisplay
|
||||
|
||||
from actions.cards import daily_cards, more_cards, all_cards
|
||||
from actions.login import login
|
||||
from actions.websearch import pc_search
|
||||
from tools.browser_setup import create_display, start_browser
|
||||
from tools.config import load_parameters, check_config
|
||||
from tools.logger import *
|
||||
import sys
|
||||
import json
|
||||
|
||||
|
||||
def routine(mail: str, pwd: str, vnc: bool = False) -> None:
|
||||
name = mail.split("@")[0]
|
||||
# display = create_display(vnc)
|
||||
# display.start()
|
||||
page, browser = start_browser(name)
|
||||
login(page, mail, pwd)
|
||||
all_cards(page)
|
||||
pc_search(page)
|
||||
# display.stop()
|
||||
browser.close()
|
||||
|
||||
|
||||
def main():
|
||||
data = load_parameters()
|
||||
check_config(data)
|
||||
|
||||
|
||||
# routine("EMAIL", "PWD", True)
|
||||
# parse_file({"accounts": {"nb": 1, 0: {"mail": "piair338@gmail.com", "pwd": "<PASSWORD>"}}})
|
||||
"""
|
||||
TODO :
|
||||
Fidelity management.
|
||||
Daily search mobile
|
||||
start -> with json config
|
||||
-> allow claiming
|
||||
-> default mode
|
||||
--vnc-- Should work, but not tested with WSL.
|
||||
remove unused imports
|
||||
"""
|
|
@ -1,61 +0,0 @@
|
|||
from playwright.sync_api import sync_playwright, expect, Page, BrowserContext
|
||||
from playwright_stealth import stealth_sync
|
||||
|
||||
from actions.quiz import play
|
||||
from tools.logger import *
|
||||
from tools.logger import *
|
||||
|
||||
|
||||
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 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')
|
||||
if "mee-icon-AddMedium" not in card.inner_html():
|
||||
info(f'Daily Card {i} : {"Validated" if "mee-icon-AddMedium" not in card.inner_html() else "Failure"}')
|
||||
continue
|
||||
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'Daily Card {i} : {"Validated" if "mee-icon-AddMedium" not in card.inner_html() else "Failure"}')
|
||||
|
||||
|
||||
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:
|
||||
expect(card).to_be_visible(timeout=10_000)
|
||||
except Exception as e: # The card probably does not exist
|
||||
debug(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'More Card {c} : {"Validated" if "mee-icon-AddMedium" not in card.inner_html() else "Failure"}')
|
||||
c += 1
|
|
@ -1,10 +0,0 @@
|
|||
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.')
|
|
@ -1,30 +0,0 @@
|
|||
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.")
|
|
@ -1,120 +0,0 @@
|
|||
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
|
||||
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:
|
||||
|
||||
if "rqQuestionState" in page.content():
|
||||
# The quiz is already started
|
||||
warning("Detected via recovery mode.")
|
||||
return page.content().count("rqAnswerOption") - 1
|
||||
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
|
||||
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.")
|
||||
page.wait_for_timeout(3000) # todo check if there is a better method than hardcoded timout
|
||||
|
||||
|
||||
def play_poll(page: Page):
|
||||
info("Playing poll.")
|
||||
answer_elem = page.locator(f"#btoption{choice([0, 1])}")
|
||||
answer_elem.click()
|
||||
info("Poll successful.")
|
||||
page.wait_for_timeout(3000) # todo check if there is a better method than hardcoded timout
|
|
@ -1,14 +0,0 @@
|
|||
{
|
||||
"accounts": {
|
||||
"nb": 1,
|
||||
"0": {
|
||||
"mail": "piair338@gmail.com",
|
||||
"pwd": "uéuéué"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"vnc_enabled": "False",
|
||||
"vnc_port": 2345,
|
||||
"claim": "False"
|
||||
}
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
playwright
|
||||
pyvirtualdisplay
|
||||
playwright_stealth
|
||||
pillow
|
|
@ -1,18 +0,0 @@
|
|||
from playwright.sync_api import sync_playwright, expect, Page, BrowserContext
|
||||
from playwright_stealth import stealth_sync
|
||||
from pyvirtualdisplay.smartdisplay import SmartDisplay
|
||||
|
||||
|
||||
def create_display(vnc=False) -> SmartDisplay:
|
||||
if vnc:
|
||||
return SmartDisplay(backend="xvnc", size=(1920, 1080), rfbport=2345, color_depth=24)
|
||||
return SmartDisplay(size=(1920, 1080))
|
||||
|
||||
|
||||
def start_browser(name: str) -> (Page, BrowserContext):
|
||||
p = sync_playwright().start()
|
||||
browser = p.firefox.launch_persistent_context(f"./data/{name}/", headless=False, args=["--start-maximised"],
|
||||
no_viewport=True)
|
||||
page = browser.new_page()
|
||||
stealth_sync(page)
|
||||
return page, browser
|
Loading…
Reference in New Issue