mirror of
https://gitea.augustin64.fr/piair/MsRewards-Reborn.git
synced 2025-06-24 02:33:56 +02:00
implémentation de la recherche PC + du VNC + requirement.txt + joli logger + séparation en plus de fichiers
This commit is contained in:
18
V7/tools/config.py
Normal file
18
V7/tools/config.py
Normal 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
|
47
V7/tools/logger.py
Normal file
47
V7/tools/logger.py
Normal file
@ -0,0 +1,47 @@
|
||||
import logging
|
||||
|
||||
# ANSI escape codes for colors
|
||||
COLOR_CODES = {
|
||||
'RESET': '\033[0m',
|
||||
'BOLD': '\033[1m',
|
||||
'RED': '\033[31m',
|
||||
'GREEN': '\033[32m',
|
||||
'YELLOW': '\033[33m',
|
||||
'BLUE': '\033[34m',
|
||||
}
|
||||
|
||||
# Define colors for each log level
|
||||
LOG_COLORS = {
|
||||
'DEBUG': COLOR_CODES['BLUE'],
|
||||
'INFO': COLOR_CODES['GREEN'],
|
||||
'WARNING': COLOR_CODES['YELLOW'],
|
||||
'ERROR': COLOR_CODES['RED'],
|
||||
'CRITICAL': COLOR_CODES['BOLD'] + COLOR_CODES['RED'],
|
||||
}
|
||||
|
||||
|
||||
# Create a formatter with colors
|
||||
class ColoredFormatter(logging.Formatter):
|
||||
def format(self, record):
|
||||
log_level = record.levelname
|
||||
record.levelname = f"{LOG_COLORS.get(log_level, '')}{record.levelname}{COLOR_CODES['RESET']}"
|
||||
return super().format(record)
|
||||
|
||||
|
||||
# Set up the root logger
|
||||
root_logger = logging.getLogger()
|
||||
root_logger.setLevel(logging.INFO)
|
||||
|
||||
# Create a console handler and set the formatter
|
||||
ch = logging.StreamHandler()
|
||||
ch.setFormatter(ColoredFormatter('%(levelname)s: %(message)s'))
|
||||
|
||||
# Add the console handler to the root logger
|
||||
root_logger.addHandler(ch)
|
||||
|
||||
# Define log level functions
|
||||
debug = root_logger.debug
|
||||
info = root_logger.info
|
||||
warning = root_logger.warning
|
||||
error = root_logger.error
|
||||
critical = root_logger.critical
|
Reference in New Issue
Block a user