#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Extract verified working credentials
Gets credentials from work.txt that are NOT in failed_verify.txt
"""

WORK_FILE = "work.txt"
FAILED_FILE = "failed_verify.txt"
VERIFIED_FILE = "verified.txt"

print("=" * 70)
print("EXTRACTING VERIFIED CREDENTIALS")
print("=" * 70)

# Read work.txt
try:
    with open(WORK_FILE, 'r', encoding='utf-8', errors='ignore') as f:
        work_creds = set(line.strip() for line in f if line.strip())
    print(f"[+] Read {len(work_creds)} credentials from {WORK_FILE}")
except FileNotFoundError:
    print(f"[!] Error: {WORK_FILE} not found!")
    exit(1)

# Read failed_verify.txt
failed_creds = set()
try:
    with open(FAILED_FILE, 'r', encoding='utf-8', errors='ignore') as f:
        failed_creds = set(line.strip() for line in f if line.strip())
    print(f"[+] Read {len(failed_creds)} failed credentials from {FAILED_FILE}")
except FileNotFoundError:
    print(f"[!] Warning: {FAILED_FILE} not found (assuming empty)")

# Get verified (in work but not in failed)
verified_creds = work_creds - failed_creds

print(f"\n[*] Calculating verified credentials...")
print(f"    Total in work.txt: {len(work_creds)}")
print(f"    Failed verification: {len(failed_creds)}")
print(f"    Verified (still working): {len(verified_creds)}")

# Save verified credentials
if verified_creds:
    with open(VERIFIED_FILE, 'w', encoding='utf-8') as f:
        for cred in sorted(verified_creds):
            f.write(f"{cred}\n")
    print(f"\n[+] Saved {len(verified_creds)} verified credentials to {VERIFIED_FILE}")
else:
    print(f"\n[!] No verified credentials found!")

print("=" * 70)
print("SUMMARY:")
print(f"  ✓ Verified (still working): {len(verified_creds)} → {VERIFIED_FILE}")
print(f"  ✗ Failed verification: {len(failed_creds)} → {FAILED_FILE}")
print("=" * 70)

