239 Zeilen
7.9 KiB
Python
239 Zeilen
7.9 KiB
Python
# social_networks/facebook/facebook_workflow.py
|
|
|
|
"""
|
|
Facebook Workflow - Definiert die Arbeitsabläufe für Facebook-Automatisierung
|
|
"""
|
|
|
|
import logging
|
|
from typing import Dict, List, Any
|
|
from utils.logger import setup_logger
|
|
|
|
logger = setup_logger("facebook_workflow")
|
|
|
|
class FacebookWorkflow:
|
|
"""
|
|
Klasse zur Definition von Facebook-Workflows.
|
|
Enthält die Schritte für verschiedene Prozesse.
|
|
"""
|
|
|
|
@staticmethod
|
|
def get_registration_workflow() -> Dict[str, Any]:
|
|
"""
|
|
Gibt den Workflow für die Registrierung zurück.
|
|
|
|
Returns:
|
|
Dict mit Workflow-Schritten
|
|
"""
|
|
return {
|
|
"name": "Facebook Registration",
|
|
"steps": [
|
|
{
|
|
"id": "navigate",
|
|
"name": "Navigate to Facebook",
|
|
"description": "Öffne Facebook-Webseite",
|
|
"required": True,
|
|
"retry": 3
|
|
},
|
|
{
|
|
"id": "cookie_consent",
|
|
"name": "Handle Cookie Consent",
|
|
"description": "Lehne optionale Cookies ab",
|
|
"required": False,
|
|
"retry": 2
|
|
},
|
|
{
|
|
"id": "open_registration",
|
|
"name": "Open Registration Form",
|
|
"description": "Klicke auf 'Neues Konto erstellen'",
|
|
"required": True,
|
|
"retry": 3
|
|
},
|
|
{
|
|
"id": "fill_form",
|
|
"name": "Fill Registration Form",
|
|
"description": "Fülle Registrierungsformular aus",
|
|
"required": True,
|
|
"retry": 1,
|
|
"fields": [
|
|
"first_name",
|
|
"last_name",
|
|
"birth_date",
|
|
"gender",
|
|
"email_or_phone",
|
|
"password"
|
|
]
|
|
},
|
|
{
|
|
"id": "submit",
|
|
"name": "Submit Registration",
|
|
"description": "Klicke auf 'Registrieren'",
|
|
"required": True,
|
|
"retry": 2
|
|
},
|
|
{
|
|
"id": "email_verification",
|
|
"name": "Email Verification",
|
|
"description": "Verifiziere E-Mail-Adresse",
|
|
"required": False,
|
|
"retry": 3,
|
|
"timeout": 120
|
|
},
|
|
{
|
|
"id": "complete",
|
|
"name": "Complete Registration",
|
|
"description": "Schließe Registrierung ab",
|
|
"required": True,
|
|
"retry": 1
|
|
}
|
|
],
|
|
"error_handlers": {
|
|
"captcha": "handle_captcha",
|
|
"checkpoint": "handle_checkpoint",
|
|
"suspicious_activity": "handle_suspicious_activity"
|
|
}
|
|
}
|
|
|
|
@staticmethod
|
|
def get_login_workflow() -> Dict[str, Any]:
|
|
"""
|
|
Gibt den Workflow für den Login zurück.
|
|
|
|
Returns:
|
|
Dict mit Workflow-Schritten
|
|
"""
|
|
return {
|
|
"name": "Facebook Login",
|
|
"steps": [
|
|
{
|
|
"id": "navigate",
|
|
"name": "Navigate to Facebook",
|
|
"description": "Öffne Facebook-Webseite",
|
|
"required": True,
|
|
"retry": 3
|
|
},
|
|
{
|
|
"id": "cookie_consent",
|
|
"name": "Handle Cookie Consent",
|
|
"description": "Behandle Cookie-Banner",
|
|
"required": False,
|
|
"retry": 2
|
|
},
|
|
{
|
|
"id": "fill_credentials",
|
|
"name": "Fill Login Credentials",
|
|
"description": "Gebe E-Mail und Passwort ein",
|
|
"required": True,
|
|
"retry": 1
|
|
},
|
|
{
|
|
"id": "submit_login",
|
|
"name": "Submit Login",
|
|
"description": "Klicke auf 'Anmelden'",
|
|
"required": True,
|
|
"retry": 2
|
|
},
|
|
{
|
|
"id": "handle_2fa",
|
|
"name": "Handle 2FA",
|
|
"description": "Behandle Zwei-Faktor-Authentifizierung",
|
|
"required": False,
|
|
"retry": 3
|
|
},
|
|
{
|
|
"id": "handle_dialogs",
|
|
"name": "Handle Post-Login Dialogs",
|
|
"description": "Behandle Dialoge nach Login",
|
|
"required": False,
|
|
"retry": 1
|
|
},
|
|
{
|
|
"id": "verify_login",
|
|
"name": "Verify Login Success",
|
|
"description": "Überprüfe erfolgreichen Login",
|
|
"required": True,
|
|
"retry": 1
|
|
}
|
|
],
|
|
"error_handlers": {
|
|
"wrong_password": "handle_wrong_password",
|
|
"account_locked": "handle_account_locked",
|
|
"checkpoint": "handle_checkpoint"
|
|
}
|
|
}
|
|
|
|
@staticmethod
|
|
def get_profile_setup_workflow() -> Dict[str, Any]:
|
|
"""
|
|
Gibt den Workflow für die Profil-Einrichtung zurück.
|
|
|
|
Returns:
|
|
Dict mit Workflow-Schritten
|
|
"""
|
|
return {
|
|
"name": "Facebook Profile Setup",
|
|
"steps": [
|
|
{
|
|
"id": "skip_suggestions",
|
|
"name": "Skip Friend Suggestions",
|
|
"description": "Überspringe Freundschaftsvorschläge",
|
|
"required": False,
|
|
"retry": 1
|
|
},
|
|
{
|
|
"id": "skip_photo",
|
|
"name": "Skip Profile Photo",
|
|
"description": "Überspringe Profilbild-Upload",
|
|
"required": False,
|
|
"retry": 1
|
|
},
|
|
{
|
|
"id": "skip_interests",
|
|
"name": "Skip Interests",
|
|
"description": "Überspringe Interessen-Auswahl",
|
|
"required": False,
|
|
"retry": 1
|
|
},
|
|
{
|
|
"id": "privacy_settings",
|
|
"name": "Configure Privacy",
|
|
"description": "Konfiguriere Privatsphäre-Einstellungen",
|
|
"required": False,
|
|
"retry": 1
|
|
}
|
|
]
|
|
}
|
|
|
|
@staticmethod
|
|
def validate_workflow_step(step: Dict[str, Any], result: bool) -> bool:
|
|
"""
|
|
Validiert einen Workflow-Schritt.
|
|
|
|
Args:
|
|
step: Workflow-Schritt
|
|
result: Ergebnis des Schritts
|
|
|
|
Returns:
|
|
bool: True wenn Schritt erfolgreich oder optional
|
|
"""
|
|
if result:
|
|
logger.info(f"Schritt '{step['name']}' erfolgreich")
|
|
return True
|
|
elif not step.get("required", True):
|
|
logger.warning(f"Optionaler Schritt '{step['name']}' fehlgeschlagen, fahre fort")
|
|
return True
|
|
else:
|
|
logger.error(f"Erforderlicher Schritt '{step['name']}' fehlgeschlagen")
|
|
return False
|
|
|
|
@staticmethod
|
|
def get_step_timeout(step: Dict[str, Any]) -> int:
|
|
"""
|
|
Gibt das Timeout für einen Schritt zurück.
|
|
|
|
Args:
|
|
step: Workflow-Schritt
|
|
|
|
Returns:
|
|
int: Timeout in Sekunden
|
|
"""
|
|
return step.get("timeout", 30) |