Untitled

 avatar
unknown
plain_text
a year ago
3.0 kB
4
Indexable
import sys
import os

# Add the parent directory to the Python path
current_dir = os.path.dirname(os.path.abspath(__file__))
parent_dir = os.path.dirname(current_dir)
sys.path.append(parent_dir)

from utils.config_manager import ConfigManager
from utils.window_utils import WindowUtils
from dolphin_anty.anty_profile_manager import AntyProfileManager
from tasks.task_context import TaskContext
from tasks.gmail.creation import GmailCreatorMultion
from utils.logger_config import logger
import time

def setup_environment():
    config_manager = ConfigManager("config/config.json")
    window_utils = WindowUtils(config_manager)
    profile_manager = AntyProfileManager(config_manager)
    task_context = TaskContext(config_manager, window_utils, profile_manager)
    return config_manager, window_utils, profile_manager, task_context

def prepare_anty_profiles(profile_manager):
    profile_manager.clean_anty_processes()
    time.sleep(20)
    profiles = profile_manager.config_manager.get_profiles()
    if profiles:
        profile_ids = [profile['id'] for profile in profiles if profile['id'] is not None]
        profile_manager.ini_dolphin_utils.delete_saved_handles(profile_ids)
    else:
        logger.warning("No profiles found. Skipping handle deletion.")

def process_profile(driver, profile_manager, window_utils, config_manager, profile_id):
    if not driver:
        logger.error(f"Driver for profile {profile_id} is not initialized. Cannot create Gmail account.")
        return

    try:
        gmail_creator = GmailCreatorMultion(driver, profile_manager.dolphin_utils, profile_manager.ini_dolphin_utils, window_utils, config_manager, profile_id)
        result, user_id = gmail_creator.execute(random_user=True)
        logger.info(f"Gmail creation for profile {profile_id} result: {result}, user ID: {user_id}")
    except Exception as e:
        logger.error(f"Error executing Gmail creation for profile {profile_id}: {str(e)}")

def main():
    config_manager, window_utils, profile_manager, task_context = setup_environment()

    try:
        prepare_anty_profiles(profile_manager)
        task_context.initialize()

        if not profile_manager.profiles:
            logger.error("No profiles found. Cannot proceed with tasks.")
            return

        for profile in profile_manager.profiles:
            profile_id = profile['id']
            if profile_id is None:
                logger.warning(f"Skipping profile with null ID")
                continue
            
            driver = task_context.get_driver(profile_id)
            if driver:
                process_profile(driver, profile_manager, window_utils, config_manager, profile_id)
            else:
                logger.error(f"No driver found for profile {profile_id}")

    except Exception as e:
        logger.error(f"An error occurred during task execution: {str(e)}")
        logger.exception("Exception details:")
    finally:
        task_context.cleanup()

if __name__ == "__main__":
    main()
Editor is loading...
Leave a Comment