الملفات
SolidPoint_Security_Framework/scripts/clear_accounts.py

79 أسطر
2.4 KiB
Python

import sys
import time
from pathlib import Path
from playwright.sync_api import sync_playwright
sys.path.insert(0, str(Path(__file__).parent / "src"))
from client import load_accounts, login_with_credentials
def clear_account_chats(page, email):
print(f"Clearing chats for: {email}")
try:
# Wait for the sidebar list to appear
page.wait_for_selector('.sb-list', timeout=10000)
except:
print(f" Sidebar not found or already empty for {email}.")
return
# Override confirm dialog to always return true
page.evaluate("window.confirm = () => true;")
deleted_count = 0
while True:
# Give UI time to update
page.wait_for_timeout(1000)
buttons = page.locator('.sb-item button.x')
count = buttons.count()
if count == 0:
break
print(f" Found {count} chats. Deleting first one...")
try:
# Force click the first delete button
buttons.nth(0).click(force=True)
deleted_count += 1
# Wait a bit for the backend request and UI removal
page.wait_for_timeout(1000)
except Exception as e:
print(f" Error clicking delete: {e}")
break
print(f" Done clearing {email}. Deleted {deleted_count} chats.")
def main():
accounts = load_accounts()
if not accounts:
print("No accounts found.")
return
print(f"Found {len(accounts)} test accounts to clear.")
with sync_playwright() as pw:
browser = pw.chromium.launch(headless=True)
for account in accounts:
email = account['email']
password = account['password']
context = browser.new_context(viewport={"width": 1280, "height": 800})
page = context.new_page()
print(f"\n--- Logging into {email} ---")
try:
logged_in = login_with_credentials(page, email, password)
if not logged_in:
print(f" Failed to login to {email}")
else:
clear_account_chats(page, email)
except Exception as e:
print(f" Exception handling {email}: {e}")
finally:
context.close()
browser.close()
print("\n[✓] All test accounts have been processed and cleared.")
if __name__ == "__main__":
main()