mirror of
				https://gitea.augustin64.fr/piair/MsRewards-Reborn.git
				synced 2025-10-31 14:23:53 +01:00 
			
		
		
		
	parsing input file
This commit is contained in:
		
							
								
								
									
										17
									
								
								V7/V7.py
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								V7/V7.py
									
									
									
									
									
								
							| @@ -5,8 +5,11 @@ 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.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 * | ||||
| import sys | ||||
| import json | ||||
|  | ||||
|  | ||||
| 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() | ||||
|  | ||||
|  | ||||
| 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 : | ||||
| Fidelity management. | ||||
| Daily search mobile | ||||
| custom start | ||||
| start -> with json config | ||||
|     -> allow claiming | ||||
|     -> default mode  | ||||
| --vnc-- Should work, but not tested with WSL. | ||||
| remove unused imports  | ||||
| """ | ||||
|   | ||||
							
								
								
									
										14
									
								
								V7/config.example.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								V7/config.example.json
									
									
									
									
									
										Normal 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" | ||||
|   } | ||||
| } | ||||
							
								
								
									
										18
									
								
								V7/tools/browser_config.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								V7/tools/browser_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 | ||||
| @@ -2,17 +2,46 @@ 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)) | ||||
| from actions.cards import daily_cards, more_cards, all_cards | ||||
| from actions.login import login | ||||
| from actions.websearch import pc_search | ||||
| from tools.browser_config import create_display, start_browser | ||||
| from tools.logger import * | ||||
| import sys | ||||
| import json | ||||
|  | ||||
|  | ||||
| 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 | ||||
| def check_config(data: dict) -> None: | ||||
|     info("Checking config file.") | ||||
|     try: | ||||
|         assert data["accounts"]["nb"] != 0, "No accounts found in the file" | ||||
|         for i in range(data["accounts"]["nb"]): | ||||
|             assert data["accounts"][str(i)]["mail"] != "", f"Account {i} has no mail." | ||||
|             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) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user