parsing input file

This commit is contained in:
piair 2024-01-18 20:15:58 +01:00
parent cf1dcec704
commit 59f7f03584
4 changed files with 87 additions and 15 deletions

View File

@ -5,8 +5,11 @@ from pyvirtualdisplay.smartdisplay import SmartDisplay
from actions.cards import daily_cards, more_cards, all_cards from actions.cards import daily_cards, more_cards, all_cards
from actions.login import login from actions.login import login
from actions.websearch import pc_search from actions.websearch import pc_search
from tools.config import create_display, start_browser from tools.browser_config import create_display, start_browser
from tools.config import load_parameters, check_config
from tools.logger import * from tools.logger import *
import sys
import json
def routine(mail: str, pwd: str, vnc: bool = False) -> None: def routine(mail: str, pwd: str, vnc: bool = False) -> None:
@ -21,12 +24,20 @@ def routine(mail: str, pwd: str, vnc: bool = False) -> None:
browser.close() browser.close()
routine("EMAIL", "PWD", True) 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 : TODO :
Fidelity management. Fidelity management.
Daily search mobile Daily search mobile
custom start start -> with json config
-> allow claiming
-> default mode
--vnc-- Should work, but not tested with WSL. --vnc-- Should work, but not tested with WSL.
remove unused imports
""" """

14
V7/config.example.json Normal file
View File

@ -0,0 +1,14 @@
{
"accounts": {
"nb": 1,
"0": {
"mail": "piair338@gmail.com",
"pwd": "uéuéué"
}
},
"config": {
"vnc_enabled": "False",
"vnc_port": 2345,
"claim": "False"
}
}

View File

@ -0,0 +1,18 @@
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

View File

@ -2,17 +2,46 @@ from playwright.sync_api import sync_playwright, expect, Page, BrowserContext
from playwright_stealth import stealth_sync from playwright_stealth import stealth_sync
from pyvirtualdisplay.smartdisplay import SmartDisplay from pyvirtualdisplay.smartdisplay import SmartDisplay
from actions.cards import daily_cards, more_cards, all_cards
def create_display(vnc=False) -> SmartDisplay: from actions.login import login
if vnc: from actions.websearch import pc_search
return SmartDisplay(backend="xvnc", size=(1920, 1080), rfbport=2345, color_depth=24) from tools.browser_config import create_display, start_browser
return SmartDisplay(size=(1920, 1080)) from tools.logger import *
import sys
import json
def start_browser(name: str) -> (Page, BrowserContext): def check_config(data: dict) -> None:
p = sync_playwright().start() info("Checking config file.")
browser = p.firefox.launch_persistent_context(f"./data/{name}/", headless=False, args=["--start-maximised"], try:
no_viewport=True) assert data["accounts"]["nb"] != 0, "No accounts found in the file"
page = browser.new_page() for i in range(data["accounts"]["nb"]):
stealth_sync(page) assert data["accounts"][str(i)]["mail"] != "", f"Account {i} has no mail."
return page, browser assert data["accounts"][str(i)]["pwd"] != "", f"Account {i} has no password."
assert data["config"]["vnc_enabled"] in ["True", "False"], f"vnc_enable should be either True or False."
assert data["config"]["claim"] in ["True", "False"], f"claim should be either True or False."
assert 1024 < data["config"]["vnc_port"] < 65535, f"vnc_port should be a valid port."
assert data["config"]["vnc_port"] not in [1234], f"vnc_port should be different than the webserver's ports."
except AssertionError as e:
critical(e)
exit(1)
except KeyError as e:
critical(f"Malformed config file. Missing {e}. Refer to the example config file.")
exit(1)
info("Successfully Checked config.")
def load_parameters() -> dict:
parameters = sys.argv
if len(parameters) == 1:
critical("Started with no parameters. Please provide at least a config file.")
exit(1)
if len(parameters) > 2:
warning("Started with multiple parameters. Some will be ignored")
try:
with open(parameters[1], "r") as f:
data = json.load(f)
return data
except FileNotFoundError:
critical("Could not open the config file.")
exit(1)